{"id":17464970,"url":"https://github.com/brucificus/html-antlr4-typescript","last_synced_at":"2026-05-02T09:32:18.845Z","repository":{"id":38175289,"uuid":"247577070","full_name":"brucificus/html-antlr4-typescript","owner":"brucificus","description":"HTML lexer \u0026 parser written in TypeScript using ANTLR 4 \u0026 ANTLR4TS","archived":false,"fork":false,"pushed_at":"2024-04-11T10:56:32.000Z","size":1375,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-11T11:48:36.585Z","etag":null,"topics":["antlr4","html-parser","npm-package","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/html-antlr4","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brucificus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2020-03-16T00:36:27.000Z","updated_at":"2024-04-15T11:29:54.513Z","dependencies_parsed_at":"2023-12-25T11:25:42.752Z","dependency_job_id":"669e9c62-d1d8-4416-9f43-31bf17fdd08f","html_url":"https://github.com/brucificus/html-antlr4-typescript","commit_stats":{"total_commits":217,"total_committers":4,"mean_commits":54.25,"dds":0.6175115207373272,"last_synced_commit":"f5283646182414cb1aa63157f954c5d70e4a3da7"},"previous_names":[],"tags_count":88,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brucificus%2Fhtml-antlr4-typescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brucificus%2Fhtml-antlr4-typescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brucificus%2Fhtml-antlr4-typescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brucificus%2Fhtml-antlr4-typescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brucificus","download_url":"https://codeload.github.com/brucificus/html-antlr4-typescript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245966913,"owners_count":20701758,"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":["antlr4","html-parser","npm-package","typescript"],"created_at":"2024-10-18T11:07:44.917Z","updated_at":"2026-05-02T09:32:18.811Z","avatar_url":"https://github.com/brucificus.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# html-antlr4\n\n[![Dependabot Status](https://api.dependabot.com/badges/status?host=github\u0026repo=foxguardsolutions/Foundation)](https://dependabot.com)\n![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/html-antlr4)\n![npm latest release](https://img.shields.io/npm/v/html-antlr4/latest)\n[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](./LICENSE.txt)\n![Release](https://github.com/brucificus/html-antlr4-typescript/workflows/Release/badge.svg)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Gitmoji](https://img.shields.io/badge/gitmoji-%20😜%20😍-FFDD67.svg?style=flat-square)](https://gitmoji.carloscuesta.me/)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![Awesome Badges](https://img.shields.io/badge/badges-awesome-green.svg)](https://github.com/Naereen/badges)\n\nAn HTML lexer \u0026 parser that provides both visitor and listener patterns to traverse the parse tree.\n\n## Overview\n\nThis is a continuous-delivery focused synthesis of the [ANTLR4 HTML grammar](https://github.com/antlr/grammars-v4/tree/master/html) and the Optimized ANLTR TypeScript target provided by [antlr4ts](https://github.com/tunnelvisionlabs/antlr4ts).\n\n- **Releases:** See the [GitHub Releases](https://github.com/brucificus/html-antlr4-typescript/releases) page for release notes and\n  links to the distribution.\n- **Feedback:**\n  Got a feature request to make, or a bug to complain about? Depending on the nature of your feedback, it probably needs to go to one of three places:\n  - 📐 For the _grammar_ (which includes the API \"shape\" of the generated lexer/parser), provide feedback at [the ANTLR4 grammar's GitHub Issues](https://github.com/antlr/grammars-v4/issues).\n  - 🔢 For the _code generated_ based on the grammar (or the runtime it depends on), provide feedback at [antlr4ts's GitHub Issues](https://github.com/tunnelvisionlabs/antlr4ts/issues).\n  - 🚀 For the _deployment process_ (versioning, update cadence, documentation), provide feedback at our own [GitHub Issues](https://github.com/brucificus/html-antlr4-typescript).\n\n  If in doubt, talk to us first so we can try to point you in the right direction.\n\n## Getting started\n\n1. Install `html-antlr4` and `antlr4ts` as dependencies using your preferred package manager.\n\n```bash\nnpm install html-antlr4 antlr4ts --save\n```\n\n```bash\nyarn add html-antlr4 antlr4ts\n```\n\n2. Use your grammar in TypeScript (or JavaScript)\n\n```typescript\nimport { HTMLLexer, HTMLParser } from \"html-antlr4\";\nimport { ANTLRInputStream, CommonTokenStream } from \"antlr4ts\";\n\nlet inputStream = new ANTLRInputStream(\"\u003cstrong\u003eHello there, \u003ci\u003eworld\u003c/i\u003e!\u003c/strong\u003e\");\n\nlet lexer = new HTMLLexer(inputStream);\nlet tokenStream = new CommonTokenStream(lexer);\nlet parser = new HTMLParser(tokenStream);\n\nlet tree = parser.htmlDocument();\n```\n\nThe two main ways to inspect the tree are by using a listener or a visitor, you can read about the differences between the two [here](https://github.com/antlr/antlr4/blob/master/doc/listeners.md).\n\n###### Listener Approach\n\n```typescript\n// ...\nimport { HTMLParserListener, HtmlElementContext } from \"html-antlr4\";\nimport { ParseTreeWalker } from \"antlr4ts/tree\";\n\nclass EnterHtmlElementListener implements HTMLParserListener {\n  enterHtmlElement(context: HtmlElementContext) {\n    console.log(`Element start line number ${context._start.line}`);\n    // ...\n  }\n\n  // other enterX functions...\n}\n\n// Create the listener\nconst listener: HTMLParserListener = new EnterHtmlElementListener();\n// Use the entry point for listeners\nParseTreeWalker.DEFAULT.walk(listener, tree);\n```\n\n###### Visitor Approach\n\n```typescript\n// ...\nimport { HTMLParserVisitor, HtmlElementContext } from \"html-antlr4\";\nimport { AbstractParseTreeVisitor } from \"antlr4ts/tree\";\n\n// Extend the AbstractParseTreeVisitor to get default visitor behaviour\nclass CountElementsVisitor\n  extends AbstractParseTreeVisitor\u003cnumber\u003e\n  implements HTMLParserVisitor\u003cnumber\u003e {\n\n  defaultResult() {\n    return 0;\n  }\n\n  aggregateResult(aggregate: number, nextResult: number) {\n    return aggregate + nextResult;\n  }\n\n  visitHtmlElement(context: HtmlElementContext): number {\n    return 1 + super.visitChildren(context);\n  }\n}\n\n// Create the visitor\nconst countElementsVisitor = new CountElementsVisitor();\n// Use the visitor entry point\nconst count = countElementsVisitor.visit(tree);\nconsole.log(`There are ${count} elements`);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrucificus%2Fhtml-antlr4-typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrucificus%2Fhtml-antlr4-typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrucificus%2Fhtml-antlr4-typescript/lists"}