From d6e318b9ce07cfb212764f01e1bdad789bd13c38 Mon Sep 17 00:00:00 2001 From: Ramon Ferreira Date: Tue, 7 Jul 2026 21:19:20 -0300 Subject: [PATCH 1/6] Add footnote rendering via a preprocessing pass swift-markdown attaches no footnote extension and has no footnote node types, so footnote syntax previously survived parsing as literal text. Following the LaTeX preprocessor precedent, a new FootnotePreProcessor collects single-line definitions, numbers references by order of first appearance, replaces them with a marked inline construct rendered as a real superscript by the inline layer, and re-emits definitions as an ordered list after a thematic break at the end of the document. Content inside fenced code blocks and inline code spans is left untouched. Closes #126 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-Authored-By: Claude Fable 5 --- .../Resources/Fixtures/kitchen-sink.md | 4 +- README.md | 2 +- .../Inline/Markdown+InlineConvertible.swift | 15 ++ .../Parser/FootnotePreProcessor.swift | 158 ++++++++++++++++ .../Parser/MarkdownParserImpl.swift | 10 +- Sources/MarkdownText/Utilities/MDFont.swift | 11 ++ .../FootnotePreProcessorTests.swift | 168 ++++++++++++++++++ .../FootnoteRenderingTests.swift | 55 ++++++ .../MarkdownTextSnapshotTests.swift | 16 ++ .../testFootnotes.iPadPro11-light-US-en.png | Bin 0 -> 239667 bytes ...ootnotes.iPadPro11Landscape-dark-US-en.png | Bin 0 -> 233854 bytes .../testFootnotes.iPhone16-dark-US-en.png | Bin 0 -> 131918 bytes .../testFootnotes.iPhone16-light-US-en.png | Bin 0 -> 131928 bytes .../testFootnotes.macOS-standard-dark.png | Bin 0 -> 38856 bytes .../testFootnotes.macOS-standard-light.png | Bin 0 -> 38941 bytes 15 files changed, 434 insertions(+), 5 deletions(-) create mode 100644 Sources/MarkdownText/Parser/FootnotePreProcessor.swift create mode 100644 Tests/MarkdownTextTests/FootnotePreProcessorTests.swift create mode 100644 Tests/MarkdownTextTests/FootnoteRenderingTests.swift create mode 100644 Tests/MarkdownTextTests/__Snapshots__/MarkdownTextSnapshotTests/testFootnotes.iPadPro11-light-US-en.png create mode 100644 Tests/MarkdownTextTests/__Snapshots__/MarkdownTextSnapshotTests/testFootnotes.iPadPro11Landscape-dark-US-en.png create mode 100644 Tests/MarkdownTextTests/__Snapshots__/MarkdownTextSnapshotTests/testFootnotes.iPhone16-dark-US-en.png create mode 100644 Tests/MarkdownTextTests/__Snapshots__/MarkdownTextSnapshotTests/testFootnotes.iPhone16-light-US-en.png create mode 100644 Tests/MarkdownTextTests/__Snapshots__/MarkdownTextSnapshotTests/testFootnotes.macOS-standard-dark.png create mode 100644 Tests/MarkdownTextTests/__Snapshots__/MarkdownTextSnapshotTests/testFootnotes.macOS-standard-light.png diff --git a/Examples/SwiftStreamingMarkdownSample/SwiftStreamingMarkdownSample/Resources/Fixtures/kitchen-sink.md b/Examples/SwiftStreamingMarkdownSample/SwiftStreamingMarkdownSample/Resources/Fixtures/kitchen-sink.md index 93d6c64..b81941f 100644 --- a/Examples/SwiftStreamingMarkdownSample/SwiftStreamingMarkdownSample/Resources/Fixtures/kitchen-sink.md +++ b/Examples/SwiftStreamingMarkdownSample/SwiftStreamingMarkdownSample/Resources/Fixtures/kitchen-sink.md @@ -224,11 +224,11 @@ flowchart TD Supported --> Citations[Citation attachments] ``` -## Footnotes and definitions fallback +## Footnotes and definition-list fallback Here is a footnote reference.[^streaming] -[^streaming]: Footnote syntax is included to check how unsupported block extensions degrade. +[^streaming]: Footnote definitions render in a notes section at the end of the document. Term : Definition list syntax is included as another compatibility check. diff --git a/README.md b/README.md index 89a4dce..9edbe92 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ The renderer targets the subset of CommonMark + GitHub-flavored Markdown that LL - [x] Ordered lists - [x] Unordered lists (with nesting) - [x] Task lists (`- [ ]` / `- [x]`), display-only +- [x] Footnotes (`[^1]`), superscript references with an end-of-document notes section - [x] Thematic breaks (`---`) - [x] Tables with `:---`, `:---:`, `---:` column alignment - [x] Inline LaTeX math via `\( … \)` @@ -108,7 +109,6 @@ The renderer targets the subset of CommonMark + GitHub-flavored Markdown that LL ### Not yet supported - [ ] Images (`![alt](url)`) — alt text only -- [ ] Footnotes (`[^1]`) - [ ] Highlight (`==text==`), superscript (`^x^`), subscript (`~x~`) - [ ] Raw HTML (`
`, ``, `