From 2c865f469ab7938612a994ff602ec490d5dc2d29 Mon Sep 17 00:00:00 2001 From: Vincent Peng Date: Thu, 8 Oct 2026 23:07:37 +1100 Subject: [PATCH 1/8] Render supported inline HTML tags instead of dropping them Inline raw-HTML nodes (InlineHTML) were previously dropped during inline conversion because they don't conform to InlineConvertible. This adds an AST-level InlineHTMLRewriter that maps a supported formatting subset onto equivalent Markdown nodes or InlineAttributes carriers before conversion: -
-> line break, -> zero-width space - / -> strong, / -> emphasis - // -> strikethrough - /, , / -> InlineAttributes, now rendered by a new InlineConvertible conformance (underline, highlight, baseline offset) - /// -> inline code - -> link HTML comments are dropped. Unmatched, unsupported, or malformed tags keep their source as literal text so documents degrade gracefully. An open tag with no matching close applies to the rest of the inline container, which keeps mid-stream documents sensible while a tag is still arriving. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- README.md | 3 +- .../Inline/Markdown+InlineConvertible.swift | 45 ++++ .../Parser/MarkdownParserImpl.swift | 9 + .../Parser/Rewriters/InlineHTMLRewriter.swift | 232 ++++++++++++++++++ .../Scanners/MarkupPostParsingRewriter.swift | 12 + Sources/MarkdownText/Utilities/MDFont.swift | 11 + .../InlineHTMLRewriterTests.swift | 146 +++++++++++ 7 files changed, 457 insertions(+), 1 deletion(-) create mode 100644 Sources/MarkdownText/Parser/Rewriters/InlineHTMLRewriter.swift create mode 100644 Tests/MarkdownTextTests/InlineHTMLRewriterTests.swift diff --git a/README.md b/README.md index efae63a8..ab3cb1f2 100644 --- a/README.md +++ b/README.md @@ -113,12 +113,13 @@ The renderer targets the subset of CommonMark + GitHub-flavored Markdown that LL - [x] Inline LaTeX math via `\( … \)` - [x] Display LaTeX math via `$$ … $$` - [x] Inline citation pills +- [x] Inline HTML formatting tags — `
`, ``/``, ``/``, ``/``, ``/``, ``, ``/``, ``/``/``/``, `
`, `` (unmatched or unsupported tags render as literal text) ### Not yet supported - [ ] Footnotes (`[^1]`) - [ ] Highlight (`==text==`), superscript (`^x^`), subscript (`~x~`) -- [ ] Raw HTML (`
`, ``, `