Skip to content

Rewrite the printer - #9

Merged
otherjoel merged 5 commits into
mainfrom
token-printer
Sep 6, 2026
Merged

otherjoel merged 5 commits into
mainfrom
token-printer

Conversation

@otherjoel

Copy link
Copy Markdown
Owner

Printer rewritten as a token-stream greedy layout. Fixes a bunch of niggling issues with the original printer:

  • Off-by-one fixed: lines may fill the wrap width exactly
  • Breaks allowed wherever the input has whitespace, including " " and "\n" strings
  • Inline closing tags stay glued after trailing whitespace is hoisted
  • Nested flow after text indents as a sibling; text after a closed block is indented
  • Tag name and first attribute glued (<a href=)
  • no trailing spaces on wrapped lines
  • No whitespace-only lines (empty flow elements, trailing <br>, deep nesting)
  • Whitespace containing newlines is collapsed, never written raw
  • Prints </pre> closer at column 1 after content ending in a newline
  • Empty blocks keep their closing tag glued to the opener

The new printer is about 2.3× faster on a 2 MB document.

The algorithm improvements and test additions were LLM-assisted.

@otherjoel
otherjoel merged commit fe7decf into main Sep 6, 2026
2 checks passed
@otherjoel
otherjoel deleted the token-printer branch September 10, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant