{"id":16485827,"url":"https://github.com/creeperyang/html-parser-lite","last_synced_at":"2025-03-23T12:33:15.538Z","repository":{"id":57267494,"uuid":"59560929","full_name":"creeperyang/html-parser-lite","owner":"creeperyang","description":"A light weight html parser and more.","archived":false,"fork":false,"pushed_at":"2023-07-20T13:11:58.000Z","size":110,"stargazers_count":7,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-12T13:27:11.370Z","etag":null,"topics":["html-parser","html-parser-lite","parser"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/creeperyang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-24T09:47:28.000Z","updated_at":"2024-02-18T06:16:02.000Z","dependencies_parsed_at":"2024-06-19T01:34:45.963Z","dependency_job_id":"2b32de54-2ead-4fca-bad3-a4b5045f1af6","html_url":"https://github.com/creeperyang/html-parser-lite","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fhtml-parser-lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fhtml-parser-lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fhtml-parser-lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fhtml-parser-lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creeperyang","download_url":"https://codeload.github.com/creeperyang/html-parser-lite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221850776,"owners_count":16891673,"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":["html-parser","html-parser-lite","parser"],"created_at":"2024-10-11T13:27:24.793Z","updated_at":"2024-10-28T15:49:02.896Z","avatar_url":"https://github.com/creeperyang.png","language":"JavaScript","readme":"## html-parser-lite [![Test CI](https://github.com/creeperyang/html-parser-lite/actions/workflows/node.js.yml/badge.svg)](https://github.com/creeperyang/html-parser-lite/actions/workflows/node.js.yml)\n\n\u003e A light weight html parser and more.\n\n[![NPM](https://nodei.co/npm/html-parser-lite.png?compact=true)](https://nodei.co/npm/html-parser-lite/)\n\n### API\n\n**`parse(html: string, options?: object)=\u003eNode|Node[]`:**\n\n\n|property|type|desc|defaults|\n|--------|---------|-------|-------|\n| `html` | `string` | The string to parse | None |\n| `options.wrapWithDocument` | `boolean` | Whether force to create a document node as root wrapper. | `false` |\n| `options.ignoreWhitespaceText` | `boolean` | Whether create text node when all the chars are white space. | `true` |\n| `options.scanner` | `HtmlScanner` | Inner html scanner. Config it only when you want to implement custom complex logic. | inner `HtmlScanner` instance |\n\nIf `options.ignoreWhitespaceText` set to `true`, it will return a `DocumentNode`(as the root of the whole tree); otherwise, it will return an array of nodes.\n\n#### Important Tips\n\nThe library's goal is not to behave the same as the browser, it just parses html string to node tree.\n\nWhen you use default options (just run `parse(html)`)，it will always return an array of nodes. And the white space between tags will be ignored. Take `\u003cp\u003es t a r t\u003c/p\u003e↵  ↵\u003cp\u003e   \u003c/p\u003e` for example:\n\n- `↵  ↵` between two paragraphs will be ignored, so only return two paragraph nodes.\n- The first paragraph `\u003cp\u003es t a r t\u003c/p\u003e` will keep all white space characters.\n- The second paragraph `\u003cp\u003e   \u003c/p\u003e` will ingore white space, so this `p` node has no text child node.\n\nIf you want to keep white space(which generates corresponding text nodes), set `options.ignoreWhitespaceText=false`.\n\n### Usage\n\n```js\nconst fs = require('fs')\nconst parse = require('html-parser-lite')\nconst html = fs.readFileSync('test/textures/simple.html').toString()\n\n// html-parser will parse html to nodes array (default behavior).\nconst nodes = parse(html)\n// JSON.stringify(nodes):\n// [{\"tagName\":\"doctype\",\"nodeType\":10,\"publicId\":\"\",\"systemId\":\"\",\"name\":\"html\"},{\"tagName\":\"html\",\"nodeType\":1,\"childNodes\":[{\"tagName\":\"head\",\"nodeType\":1,\"childNodes\":[{\"tagName\":\"meta\",\"nodeType\":1,\"childNodes\":[],\"attrs\":{\"charset\":\"utf-8\"}},{\"tagName\":\"title\",\"nodeType\":1,\"childNodes\":[{\"tagName\":\"text\",\"nodeType\":3,\"textContent\":\"hi\"}],\"attrs\":{}}],\"attrs\":{}},{\"tagName\":\"body\",\"nodeType\":1,\"childNodes\":[{\"tagName\":\"h1\",\"nodeType\":1,\"childNodes\":[{\"tagName\":\"text\",\"nodeType\":3,\"textContent\":\"heading title\"}],\"attrs\":{}}],\"attrs\":{}}],\"attrs\":{\"class\":\"html-ok\",\"lang\":\"zh-hans-cn\"},\"className\":\"html-ok\"}]\n```\n\n### License\n\n[MIT](https://opensource.org/licenses/mit-license.php)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreeperyang%2Fhtml-parser-lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreeperyang%2Fhtml-parser-lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreeperyang%2Fhtml-parser-lite/lists"}