{"id":15642022,"url":"https://github.com/huozhi/html2any","last_synced_at":"2025-04-30T09:17:25.553Z","repository":{"id":23257753,"uuid":"98556592","full_name":"huozhi/html2any","owner":"huozhi","description":"🌀 parse and convert html string to anything","archived":false,"fork":false,"pushed_at":"2025-03-25T04:40:20.000Z","size":208,"stargazers_count":74,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-30T09:17:20.975Z","etag":null,"topics":["html-parser","rich-text","xml-parser"],"latest_commit_sha":null,"homepage":"https://html2any.vercel.app","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/huozhi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-27T16:08:07.000Z","updated_at":"2025-01-14T14:02:00.000Z","dependencies_parsed_at":"2023-01-14T01:30:23.324Z","dependency_job_id":null,"html_url":"https://github.com/huozhi/html2any","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huozhi%2Fhtml2any","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huozhi%2Fhtml2any/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huozhi%2Fhtml2any/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huozhi%2Fhtml2any/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huozhi","download_url":"https://codeload.github.com/huozhi/html2any/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251674590,"owners_count":21625646,"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","rich-text","xml-parser"],"created_at":"2024-10-03T11:53:36.589Z","updated_at":"2025-04-30T09:17:25.533Z","avatar_url":"https://github.com/huozhi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# html2any\n\n[![npm version](https://badge.fury.io/js/html2any.svg)](https://badge.fury.io/js/html2any)\n\n\u003e A non-dependecy package for coverting html/xml string to your customized format/structures.\n\nWhile building websites, people may met issues for rendering rich text into different formats.\nFor example, I've got an `\u003cvideo\u003e` tag, but I wanna render it with my own React video component.\nBut I also want to render the whole html easily rather than parse it manually.\n\nNow `html2any` help you to render html string. It not only parses your html but also gives you ability to transform it from origin to the dest.\n\n### API\n\nhtml2any provide following APIs\n\n- `AST(Object) parse(String source)`\n- `void transform(AST ast, function rule)`\n- `void html2any(html, function rule)`\n\n- parse\n\u003e Build the AST from source to AST from source html/xml code\n\n- transform\n\u003e Convert the AST to the final form with the specific rule.\n\n- html2any\n\u003e Convert the html/xml to the final form directly.\n\n### Usage\n\n```\nnpm i -S html2any\n```\n\n```js\nimport html2any, { parse, transform } from 'html2any'\n\nconst html = escapeHTMLEntity(`\u003cdiv\u003e123\u003c/div\u003e`)\n\nconst ast = parse(html)[0]\n\nfunction rule(node, children) {\n  if (typeof node === 'string') {\n    return node\n  } else {\n    return \u003cdiv\u003e{node}\u003c/div\u003e\n  }\n}\n\nconst vdom = transform(ast, rule)\n// JSX vdom form of html\n// { type: 'div', props: {...}, children: '...' }\n\n```\n\nOr you can just call html2any directly\n\n```js\nconst vdom = html2any(html, rule)\n```\n\n### How It Works\n\nUse `html2any` to construct an AST of html string, then convert each node recursively with `rule` passed to transform function.\n\nFor example, we translate `\u003cp\u003e` tag into React Native component `\u003cText style={styles.paragraph}\u003e` with the prepared styles. Then decode the p tag' s content to avoid html entities mess up.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuozhi%2Fhtml2any","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuozhi%2Fhtml2any","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuozhi%2Fhtml2any/lists"}