feat: HTML parser#57
Conversation
There was a problem hiding this comment.
Pull request overview
Introduces a new streaming HTML parser (HTMLStreamParser) that converts Telegram HTML-style text into FormattedString instances, along with initial tests and a specification document.
Changes:
- Added
HTMLStreamParserstate-machine implementation for supported tags/entities and Telegram entity mapping. - Added test coverage for several core tag mappings and chunk-boundary streaming behavior.
- Exported the new parser from the library entrypoint and added a spec document describing intended completion criteria.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
src/stream-html-to-format.ts |
New streaming HTML parser implementation and entity mapping logic. |
test/stream-html-to-format.test.ts |
New tests validating core tag/entity mappings and streamed chunk handling. |
src/mod.ts |
Re-exports the new parser module. |
specs.md |
Adds a detailed refactor/specification document for the parser behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
What's the deal here? Wanna instruct LLMs to output HTML and then use this to stream formatted drafts? |
Don't really have LLMs as an intended audience for this, though it might coincidentally work (i.e. this parser is somewhat lenient on incomplete HTML strings). The main (and original) audience would be i18n users. Instead of wrangling with HTML parse_mode, we want to locally convert HTML strings (which i18n users are forced to use as they can't do template literals in |
|
Only works coincidentally because of the chosen architecture of the parser |
|
That's pretty cool! |
This comment was marked as spam.
This comment was marked as spam.
|
Merged as unstable/experimental, but good enough for RFC from real world use |
Note: Tests and select utility methods written by LLM
Note: Parsing methods are handwritten and deliberately rolled out (i.e. not refactored for DRY) at this moment - i.e. putting all the state transitions on paper first