{"id":18083454,"url":"https://github.com/leizongmin/leizm-html-parser","last_synced_at":"2025-04-05T23:15:53.363Z","repository":{"id":55668010,"uuid":"114511542","full_name":"leizongmin/leizm-html-parser","owner":"leizongmin","description":"Fast HTML parser written in pure JavaScript","archived":false,"fork":false,"pushed_at":"2021-09-15T12:13:44.000Z","size":1023,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-12T05:43:32.803Z","etag":null,"topics":["dom","html","html5","parser"],"latest_commit_sha":null,"homepage":"http://leizm.com","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leizongmin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-17T05:20:05.000Z","updated_at":"2024-04-26T12:04:53.000Z","dependencies_parsed_at":"2022-08-15T06:00:52.673Z","dependency_job_id":null,"html_url":"https://github.com/leizongmin/leizm-html-parser","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leizongmin%2Fleizm-html-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leizongmin%2Fleizm-html-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leizongmin%2Fleizm-html-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leizongmin%2Fleizm-html-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leizongmin","download_url":"https://codeload.github.com/leizongmin/leizm-html-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247411241,"owners_count":20934654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dom","html","html5","parser"],"created_at":"2024-10-31T14:08:01.748Z","updated_at":"2025-04-05T23:15:53.345Z","avatar_url":"https://github.com/leizongmin.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Node.js CI](https://github.com/leizongmin/leizm-html-parser/workflows/Node.js%20CI/badge.svg)\n[![DeepScan grade](https://deepscan.io/api/teams/2068/projects/2782/branches/20098/badge/grade.svg)](https://deepscan.io/dashboard#view=project\u0026tid=2068\u0026pid=2782\u0026bid=20098)\n[![NPM version][npm-image]][npm-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![David deps][david-image]][david-url]\n[![node version][node-image]][node-url]\n[![npm download][download-image]][download-url]\n[![npm license][license-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/@leizm/html-parser.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@leizm/html-parser\n[coveralls-image]: https://img.shields.io/coveralls/leizongmin/leizm-html-parser.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/leizongmin/leizm-html-parser?branch=master\n[david-image]: https://img.shields.io/david/leizongmin/leizm-html-parser.svg?style=flat-square\n[david-url]: https://david-dm.org/leizongmin/leizm-html-parser\n[node-image]: https://img.shields.io/badge/node.js-%3E=_6.0-green.svg?style=flat-square\n[node-url]: http://nodejs.org/download/\n[download-image]: https://img.shields.io/npm/dm/@leizm/html-parser.svg?style=flat-square\n[download-url]: https://npmjs.org/package/@leizm/html-parser\n[license-image]: https://img.shields.io/npm/l/@leizm/html-parser.svg\n\n# @leizm/html-parser\n\nFast HTML parser written in pure JavaScript\n\n## Installation\n\n```bash\nnpm install @leizm/html-parser --save\n```\n\n## Usage\n\n### Node.js or Webpack\n\n```typescript\nimport * as html from \"@leizm/html-parser\";\n\nconst { errors, nodes } = html.parse(`\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n  \u003cmeta charset=\"UTF-8\"\u003e\n  \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n  \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\"\u003e\n  \u003ctitle\u003eDocument\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003ch1\u003eHello, world! \u003csmall\u003eby @leizm/html-parser\u003c/small\u003e\u003c/h1\u003e\n  \u003cp\u003eFast HTML parser written in pure JavaScript\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e`);\n\nconsole.log({ errors, nodes });\nconsole.log(html.toString(nodes));\n```\n\nThe result of `html.parse()` should be:\n\n\u003cdetails\u003e\u003csummary\u003eView details\u003c/summary\u003e\n\n```json\n{\n  \"errors\": [],\n  \"nodes\": [\n    {\n      \"start\": 0,\n      \"end\": 15,\n      \"type\": \"tag\",\n      \"name\": \"!DOCTYPE\",\n      \"properties\": { \"html\": true }\n    },\n    { \"start\": 15, \"end\": 16, \"type\": \"text\", \"text\": \"\\n\" },\n    {\n      \"start\": 16,\n      \"end\": 365,\n      \"type\": \"tag\",\n      \"name\": \"html\",\n      \"properties\": { \"lang\": \"en\" },\n      \"children\": [\n        { \"start\": 32, \"end\": 33, \"type\": \"text\", \"text\": \"\\n\" },\n        {\n          \"start\": 33,\n          \"end\": 227,\n          \"type\": \"tag\",\n          \"name\": \"head\",\n          \"children\": [\n            { \"start\": 39, \"end\": 42, \"type\": \"text\", \"text\": \"\\n  \" },\n            {\n              \"start\": 42,\n              \"end\": 64,\n              \"type\": \"tag\",\n              \"name\": \"meta\",\n              \"properties\": { \"charset\": \"UTF-8\" }\n            },\n            { \"start\": 64, \"end\": 67, \"type\": \"text\", \"text\": \"\\n  \" },\n            {\n              \"start\": 67,\n              \"end\": 137,\n              \"type\": \"tag\",\n              \"name\": \"meta\",\n              \"properties\": {\n                \"name\": \"viewport\",\n                \"content\": \"width=device-width, initial-scale=1.0\"\n              }\n            },\n            { \"start\": 137, \"end\": 140, \"type\": \"text\", \"text\": \"\\n  \" },\n            {\n              \"start\": 140,\n              \"end\": 193,\n              \"type\": \"tag\",\n              \"name\": \"meta\",\n              \"properties\": {\n                \"http-equiv\": \"X-UA-Compatible\",\n                \"content\": \"ie=edge\"\n              }\n            },\n            { \"start\": 193, \"end\": 196, \"type\": \"text\", \"text\": \"\\n  \" },\n            {\n              \"start\": 196,\n              \"end\": 219,\n              \"type\": \"tag\",\n              \"name\": \"title\",\n              \"children\": [\n                { \"start\": 203, \"end\": 211, \"type\": \"text\", \"text\": \"Document\" }\n              ]\n            },\n            { \"start\": 219, \"end\": 220, \"type\": \"text\", \"text\": \"\\n\" }\n          ]\n        },\n        { \"start\": 227, \"end\": 228, \"type\": \"text\", \"text\": \"\\n\" },\n        {\n          \"start\": 228,\n          \"end\": 357,\n          \"type\": \"tag\",\n          \"name\": \"body\",\n          \"children\": [\n            { \"start\": 234, \"end\": 237, \"type\": \"text\", \"text\": \"\\n  \" },\n            {\n              \"start\": 237,\n              \"end\": 296,\n              \"type\": \"tag\",\n              \"name\": \"h1\",\n              \"children\": [\n                {\n                  \"start\": 241,\n                  \"end\": 255,\n                  \"type\": \"text\",\n                  \"text\": \"Hello, world! \"\n                },\n                {\n                  \"start\": 255,\n                  \"end\": 291,\n                  \"type\": \"tag\",\n                  \"name\": \"small\",\n                  \"children\": [\n                    {\n                      \"start\": 262,\n                      \"end\": 283,\n                      \"type\": \"text\",\n                      \"text\": \"by @leizm/html-parser\"\n                    }\n                  ]\n                }\n              ]\n            },\n            { \"start\": 296, \"end\": 299, \"type\": \"text\", \"text\": \"\\n  \" },\n            {\n              \"start\": 299,\n              \"end\": 349,\n              \"type\": \"tag\",\n              \"name\": \"p\",\n              \"children\": [\n                {\n                  \"start\": 302,\n                  \"end\": 345,\n                  \"type\": \"text\",\n                  \"text\": \"Fast HTML parser written in pure JavaScript\"\n                }\n              ]\n            },\n            { \"start\": 349, \"end\": 350, \"type\": \"text\", \"text\": \"\\n\" }\n          ]\n        },\n        { \"start\": 357, \"end\": 358, \"type\": \"text\", \"text\": \"\\n\" }\n      ]\n    }\n  ]\n}\n```\n\n\u003c/details\u003e\n\nThe result of `html.toString()` should be:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n  \u003cmeta charset=\"UTF-8\" /\u003e\n  \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n  \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\" /\u003e\n  \u003ctitle\u003eDocument\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003ch1\u003eHello, world! \u003csmall\u003eby @leizm/html-parser\u003c/small\u003e\u003c/h1\u003e\n  \u003cp\u003eFast HTML parser written in pure JavaScript\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Browser-side\n\n`parser.min.js` is pack by [Browserify](http://browserify.org/), it provided an `require()` function to load the module:\n\n```html\n\u003cscript src=\"https://unpkg.com/@leizm/html-parser/dist/parser.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  const html = require(\"@leizm/html-parser\");\n  const { errors, nodes } = html.parse(`\u003cstrong\u003ehello\u003c/strong\u003e`);\n  // ...\n\u003c/script\u003e\n```\n\n## Benchmark\n\nEnvironment:\n- Node v15.4.0\n- Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz\n\nResult:\n- file1 size: 0.12M, parse: 18.4M/s, toString: 49.2M/s\n- file2 size: 5.04M, parse: 15.4M/s, toString: 9.2M/s\n\n## License\n\n```text\nMIT License\n\nCopyright (c) 2017-2021 Zongmin Lei \u003cleizongmin@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleizongmin%2Fleizm-html-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleizongmin%2Fleizm-html-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleizongmin%2Fleizm-html-parser/lists"}