{"id":15989510,"url":"https://github.com/brycerussell/htmlrx","last_synced_at":"2025-06-23T21:34:32.170Z","repository":{"id":183444696,"uuid":"608862985","full_name":"BryceRussell/HTMLRx","owner":"BryceRussell","description":"Select and manipulate elements in a HTML string without an AST","archived":false,"fork":false,"pushed_at":"2023-04-24T17:23:25.000Z","size":160,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-06T15:03:13.621Z","etag":null,"topics":["html","htmlparser","regex","regexp","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/BryceRussell.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-03-02T22:22:00.000Z","updated_at":"2023-04-24T17:17:28.000Z","dependencies_parsed_at":"2023-07-24T14:18:00.084Z","dependency_job_id":"d99f8238-fe08-4686-b8c7-39971f5e5763","html_url":"https://github.com/BryceRussell/HTMLRx","commit_stats":null,"previous_names":["brycerussell/htmlrx"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/BryceRussell/HTMLRx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BryceRussell%2FHTMLRx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BryceRussell%2FHTMLRx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BryceRussell%2FHTMLRx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BryceRussell%2FHTMLRx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BryceRussell","download_url":"https://codeload.github.com/BryceRussell/HTMLRx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BryceRussell%2FHTMLRx/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261559315,"owners_count":23177175,"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","htmlparser","regex","regexp","typescript"],"created_at":"2024-10-08T04:43:03.082Z","updated_at":"2025-06-23T21:34:32.137Z","avatar_url":"https://github.com/BryceRussell.png","language":"TypeScript","readme":"# HTMLRx\n\nSelect and manipulate elements in a HTML string without an AST\n\n\u003e **Note**: This repo is for learning and practice, it is not meant to be a real library and is subject to change\n\n## How to use\n\n```ts\nimport { HTMLRx } from 'htmlrx`;\n\nconst html = `\n  \u003cdetail open class=\"dropdown\"\u003e\n    \u003csummary\u003eOpen\u003csummary\u003e\n    \u003cul\u003e\n      \u003cli\u003e\u003ca href=\"\"\u003eOne\u003c/a\u003e\u003c/li\u003e\n      \u003cli\u003e\u003ca href=\"\"\u003eTwo\u003c/a\u003e\u003c/li\u003e\n      \u003cli\u003e\u003ca href=\"\"\u003eThree\u003c/a\u003e\u003c/li\u003e\n    \u003c/ul\u003e\n  \u003c/details\u003e\n`\n\nconst newHTML = HTMLRx(html)\n  .clean() // Remove HTML comments\n  .select('ul') // Select first 'ul' element\n\n  // Once an element is selected you can:\n  \n  // Change the element's tag and/or attributes\n  .modify('ol', {class: old =\u003e old + 'ordered'})\n  // Remove everything from inside the element\n  .empty()\n  // Remove the element from the HTML\n  .remove()\n\n  // or\n\n  // Return the element's attributes\n  .attrs()\n  // Return the full element as a string\n  .element()\n  // Return element's text\n  .text()\n```\n### Using `.walk()`\n```ts\nimport { HTMLRx } from 'htmlrx`;\n\nconst html = '\n  \u003cdetail open class=\"dropdown\"\u003e\n    \u003csummary\u003eOpen\u003csummary\u003e\n    \u003cul\u003e\n      \u003cli\u003e\u003ca href=\"\"\u003eOne\u003c/a\u003e\u003c/li\u003e\n      \u003cli\u003e\u003ca href=\"\"\u003eTwo\u003c/a\u003e\u003c/li\u003e\n      \u003cli\u003e\u003ca href=\"\"\u003eThree\u003c/a\u003e\u003c/li\u003e\n    \u003c/ul\u003e\n  \u003c/details\u003e\n'\n\nconst newHTML = HTMLRx(html)\n  .walk(({index, name, attrs, select}) =\u003e {\n    // Select every element and log it to the console\n    select()\n    console.log(this.element())\n  })\n  \n```\n\n## Example\n\n```js\nconst html = `\n  \u003cdiv class=\"container\"\u003e\n    \u003ch1\u003eTitle\u003c/h1\u003e\n    \u003cp\u003eParagraph 1\u003c/p\u003e\n    \u003cp\u003eParagraph 2\u003c/p\u003e\n    \u003cimg src=\"image.png\" alt=\"Image\"\u003e\n  \u003c/div\u003e\n`\n\nconst newHTML = HTMLRx(html)\n  .select(null, {class: 'container'})\n  .modify('section', {class: 'new-class'})\n  .select('h1')\n  .modify('h2')\n  .select('p')\n  .empty()\n  .select('img')\n  .modify('figure', {class: 'image-container'})\n  .HTML\n```\n\n```html\n\u003csection class=\"new-class\"\u003e\n  \u003ch2\u003eTitle\u003c/h2\u003e\n  \u003cp\u003e\u003c/p\u003e\n  \u003cp\u003eParagraph 2\u003c/p\u003e\n  \u003cfigure src=\"image.png\" alt=\"Image\" class=\"image-container\"\u003e\n\u003c/section\u003e\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrycerussell%2Fhtmlrx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrycerussell%2Fhtmlrx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrycerussell%2Fhtmlrx/lists"}