{"id":20688791,"url":"https://github.com/71/parse-html-parts","last_synced_at":"2026-04-24T04:33:49.372Z","repository":{"id":95481144,"uuid":"324860665","full_name":"71/parse-html-parts","owner":"71","description":"Parse HTML parts in order to make literal templates.","archived":false,"fork":false,"pushed_at":"2020-12-27T23:37:54.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-26T16:37:02.548Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/71.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-12-27T22:30:33.000Z","updated_at":"2020-12-27T23:37:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"c5e5990d-9279-4966-be31-3b2af9ea37b1","html_url":"https://github.com/71/parse-html-parts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/71/parse-html-parts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/71%2Fparse-html-parts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/71%2Fparse-html-parts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/71%2Fparse-html-parts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/71%2Fparse-html-parts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/71","download_url":"https://codeload.github.com/71/parse-html-parts/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/71%2Fparse-html-parts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32209893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T03:15:14.334Z","status":"ssl_error","status_checked_at":"2026-04-24T03:15:11.608Z","response_time":64,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-16T23:07:03.075Z","updated_at":"2026-04-24T04:33:49.367Z","avatar_url":"https://github.com/71.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `parse-html-parts`\n\nThis project provides utilities for parsing HTML-like JavaScript\n[template literals](\nhttps://developer.mozilla.org/docs/Web/JavaScript/Reference/Template_literals),\nsimilarly to [htl](https://github.com/observablehq/htl)\nand [lit-html](https://github.com/Polymer/lit-html).\n\nUnlike those libraries, though, the result is not directly usable in the DOM.\nInstead, `LiteralPart`s are returned, which can be inspected to then create\nyour own renderers.\n\n## Example\nFirst, we parse the template literal into `LiteralPart`s. Each resulting\n`LiteralPart` corresponds to a passed expression.\n\n```ts\nconst parts = parseHtmlLiteral`\u003cp style=\"${0}: ${1}\" ${2}\u003ehey ${3}\u003c/p\u003e`;\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eTests\u003c/summary\u003e\n\u003cp\u003e\n\n```ts\nexpect(parts.length).toBe(4);\n\nconst [part0, part1, part2, part3] = parts;\n\nexpect(part0.type).toBe(LiteralPart.Kind.Attribute);\nexpect(part1.type).toBe(LiteralPart.Kind.Attribute);\nexpect(part2.type).toBe(LiteralPart.Kind.Data);\nexpect(part3.type).toBe(LiteralPart.Kind.Node);\n\nexpect(part0.attributeName).toBe(\"style\");\nexpect(part0.valueParts).toEqual([\"\", \":\", \"\"]);\nexpect(part0.index).toBe(0);\n\nexpect(part1.attributeName).toBe(\"style\");\nexpect(part1.valueParts).toBe(part0.valueParts);\nexpect(part1.index).toBe(1);\n```\n\n\u003c/p\u003e\n\u003c/details\u003e\n\nThen, we can render the parts into a valid HTML string.\n\n```ts\nconst strings = (strings =\u003e strings)`\u003cp style=\"${0}: ${1}\" ${2}\u003ehey ${3}\u003c/p\u003e`,\n      htmlString = renderToHtml(strings, parts),\n      root = document.createRange().createContextualFragment(htmlString);\n```\n\nAnd once it's rendered, we can find its marked nodes:\n\n```ts\nconst finder = new LiteralNodesFinder(parts),\n      nodes = finder.find(root);\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eTests\u003c/summary\u003e\n\u003cp\u003e\n\n```ts\nconst p = root.children[0];\n\nexpect(nodes.length).toBe(4);\n\nexpect(nodes[0].ownerElement).toBe(p);\nexpect(nodes[1].ownerElement).toBe(p);\nexpect(nodes[2].ownerElement).toBe(p);\nexpect(nodes[3]).toBe(p.childNodes[1]);\n```\n\n\u003c/p\u003e\n\u003c/details\u003e\n\nPlease see the [html.test.ts](html.test.ts) file for an example `html` function\nthat renders directly to a `DocumentFragment`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F71%2Fparse-html-parts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F71%2Fparse-html-parts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F71%2Fparse-html-parts/lists"}