{"id":15091674,"url":"https://github.com/stevenvachon/handlebars-html-parser","last_synced_at":"2025-04-12T06:30:48.628Z","repository":{"id":24902809,"uuid":"28319370","full_name":"stevenvachon/handlebars-html-parser","owner":"stevenvachon","description":"Parse Handlebars and HTML.","archived":true,"fork":false,"pushed_at":"2024-10-06T05:28:44.000Z","size":121,"stargazers_count":35,"open_issues_count":14,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T01:41:27.456Z","etag":null,"topics":["handlebars","html","html-parser","html5","nodejs","whatwg"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/stevenvachon.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}},"created_at":"2014-12-22T00:55:33.000Z","updated_at":"2025-02-23T16:05:38.000Z","dependencies_parsed_at":"2023-12-01T15:26:54.348Z","dependency_job_id":"cf7b58e3-1260-40d5-9cca-ab860761ddbf","html_url":"https://github.com/stevenvachon/handlebars-html-parser","commit_stats":{"total_commits":27,"total_committers":1,"mean_commits":27.0,"dds":0.0,"last_synced_commit":"d4b0ac86b2771d42ae3b7b5673df78f60a1e02bc"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fhandlebars-html-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fhandlebars-html-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fhandlebars-html-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fhandlebars-html-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevenvachon","download_url":"https://codeload.github.com/stevenvachon/handlebars-html-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248529237,"owners_count":21119467,"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":["handlebars","html","html-parser","html5","nodejs","whatwg"],"created_at":"2024-09-25T10:42:39.187Z","updated_at":"2025-04-12T06:30:48.219Z","avatar_url":"https://github.com/stevenvachon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# handlebars-html-parser [![NPM Version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][david-image]][david-url]\n\n\u003e Parse Handlebars and HTML.\n\nParse this:\n```handlebars\n\u003ctag\u003e value {{{obj.value}~}} \u003c/tag\u003e\n```\ninto this:\n```js\n[\n    { type:\"htmlTagStart\" },\n    { type:\"htmlTagNameStart\" },\n    { type:\"literal\", value:\"tag\" },\n    { type:\"htmlTagNameEnd\" },\n    { type:\"htmlTagEnd\" },\n    \n    { type:\"literal\", value:\" value \" },\n    \n    { type:\"hbsTagStart\", unescaped:true },\n    { type:\"hbsExpressionStart\" },\n    { type:\"hbsPartStart\" },\n    { type:\"hbsPath\", value:[\"obj\",\"value\"] },\n    { type:\"hbsPartEnd\" },\n    { type:\"hbsExpressionEnd\" },\n    { type:\"hbsTagEnd\", unescaped:true, strip:true },\n    \n    // whitespace stripped\n    \n    { type:\"htmlTagStart\", closing:true },\n    { type:\"htmlTagNameStart\" },\n    { type:\"literal\", value:\"tag\" },\n    { type:\"htmlTagNameEnd\" },\n    { type:\"htmlTagEnd\" }\n]\n```\n…for use in compiling to something like a virtual DOM, such that of [handlebars-react](https://github.com/stevenvachon/handlebars-react).\n\nFor more information on the strengths, weaknesses and implementation details of this library, check out the [wiki](https://github.com/stevenvachon/handlebars-html-parser/wiki).\n\n\n## Installation\n[Node.js](http://nodejs.org/) `\u003e= 5` is required; `\u003c 5.0` will need an ES6 compiler. ~~Type this at the command line:~~\n```shell\nnpm install handlebars-html-parser\n```\n\n\n## Methods\n\n### .parse(template)\nParse a template String into a linear program which contains HTML pieces and Handlebars expressions. A `Promise` is returned for use in chaining.\n\n\n## Functions\n\n### .beautifyJS(js)\nFormat a JavaScript String for increased legibility. This is a convenience function that will prevent your project from depending on multiple versions of [uglify-js](https://npmjs.com/uglify-js).\n\n### .each(callback)\nRuns a provided Function once per element in the generated linear program.\n\n`callback` has two arguments:\n\n* `node`, the current node being processed in the linear program\n* `state`, a mutable/reused object containing the current state of `node`\n\n\n## Constants\n\n### .type.*\nA map of node types. See the [full list](https://github.com/stevenvachon/handlebars-html-parser/blob/master/lib/NodeType.js).\n\n\n## Options\n\n### options.convertHbsComments\nType: `Boolean`  \nDefault value: `false`  \nWhen `true`, Handlebars comments will be converted to HTML comments.\n\n### options.ignoreHbsComments\nType: `Boolean`  \nDefault value: `false`  \nWhen `true`, Handlebars comments will be excluded from output. This can result in concatenated Strings, which optimizes compilation.\n\n### options.ignoreHtmlComments\nType: `Boolean`  \nDefault value: `false`  \nWhen `true`, HTML comments will be excluded from output. This can result in concatenated Strings, which optimizes compilation.\n\n### options.normalizeWhitespace\nType: `Boolean`  \nDefault value: `false`  \nWhen `true`, will replace multiple standard whitespace characters (line breaks, tabs, regular spaces) with a single space. This helps improve runtime performance and lower compiled template file size.\n\n* Does not affect \"special\" whitespace chars such as `\u0026nbsp;`, etc.\n* Does not affect text within `\u003cpre\u003e`,`\u003cscript\u003e`,`\u003cstyle\u003e`,`\u003ctextarea\u003e` elements\n* Does not affect text within \"dynamic\" elements (`\u003c{{tag}}\u003e`)\n* Does not affect attribute values (`\u003ctag attr=\"value\"\u003e`)\n* Does not affect HTML's rendered appearance (unless using CSS `white-space:pre`)\n\n### options.processCSS\nType: `Boolean`  \nDefault value: `false`  \nWhen `true`, the contents of CSS tags and attributes will be [auto-prefixed](https://npmjs.com/autoprefixer) and minified. **Note:** if *any* Handlebars expressions are contained within, minification will be skipped.\n\n### options.processJS\nType: `Boolean`  \nDefault value: `false`  \nWhen `true`, the contents of JavaScript tags, attributes and `href=\"javascript:…\"` links will be minified. **Note:** if *any* Handlebars expressions are contained within, minification will be skipped.\n\n\n## Example\n```js\nvar HandlebarsHtmlParser = require(\"handlebars-html-parser\")\n\nvar eachNode = HandlebarsHtmlParser.each\nvar NodeType = HandlebarsHtmlParser.type\nvar parser = new HandlebarsHtmlParser(options)\n\nparser.parse(\"\u003ctag\u003e{{var}}\u003c/tag\u003e\")\n.then( eachNode((node, state) =\u003e {\n\tswitch(node.type) {\n\t\tcase NodeType.HBS_EXPRESSION_START: {\n\t\t\t// is expression start node\n\t\t\tbreak\n\t\t}\n\t\tcase NodeType.HTML_TAG_START: {\n\t\t\t// is html tag start node\n\t\t\tbreak\n\t\t}\n\t}\n}))\n.then(program =\u003e console.log(\"done!\"))\n```\n\n\n## FAQ\n1. **How is this different from [HTMLBars](https://npmjs.com/htmlbars)?**  \nHTMLBars *builds* an *opinionated* DOM whereas this library *enables* you to build a *custom* DOM with any and all reactive binding logic offloaded to a library of your choice.\n\n2. **Why not just extend the Handlebars AST?**  \nLess maintenance. The result of extending it would still require a custom compiler because the AST would be incompatible with the Handlebars compiler. Every breaking change made to Handlebars will require such to this parser, but likely not to its [compiler](https://github.com/stevenvachon/handlebars-html-compiler).\n\n\n## Roadmap Features\n* figure out what `inverseStrip` (in hbs ast) is used for\n* support raw blocks: `{{{{raw-helper}}}} {{path}} {{{{/raw-helper}}}}`\n* support `\u003c{{tag}}\u003e\u003c/{{tag}}\u003e` by aliasing to `\u003chbshtml-start1-end3\u003e\u003c/hbshtml-start1-end3\u003e`?\n* add support for `{{this}}`,`{{.}}`\n* add default whitespace control to \"standalone\" tags: http://handlebarsjs.com/expressions.html#whitespace-control\n* `options.mustacheOnly` that disables helpers, expressions and whitespace control? would have to provide parse errors\n* `options.xmlMode` with [xmldoc](https://npmjs.com/xmldoc) ?\n\n\n## Changelog\n* 0.0.1–0.0.26 pre-releases\n\n\n[npm-image]: https://img.shields.io/npm/v/handlebars-html-parser.svg\n[npm-url]: https://npmjs.org/package/handlebars-html-parser\n[travis-image]: https://img.shields.io/travis/stevenvachon/handlebars-html-parser.svg\n[travis-url]: https://travis-ci.org/stevenvachon/handlebars-html-parser\n[david-image]: https://img.shields.io/david/stevenvachon/handlebars-html-parser.svg\n[david-url]: https://david-dm.org/stevenvachon/handlebars-html-parser\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenvachon%2Fhandlebars-html-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevenvachon%2Fhandlebars-html-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenvachon%2Fhandlebars-html-parser/lists"}