Skip to content

Finish the move to cmark-gfm: remove hoedown and PEG Markdown Highlight - #8

Merged
levous merged 8 commits into
mainfrom
feature/update-deps
Oct 22, 2026
Merged

levous merged 8 commits into
mainfrom
feature/update-deps

Conversation

@levous

@levous levous commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Removes the original's two C Markdown libraries, hoedown and PEG Markdown Highlight, so cmark-gfm (swift-cmark) is the only engine and the package has no C code left. Also updates licenses and credits, adds LeVous (Rusty Zarse) to contributors, and cleaned change spec references from code comments.

Stacked on #7 (feature/paste-formatted), so this diff shows only this work. Retarget to main once #7 merges.

What's removed

  • Sources/CHoedown and Sources/CPegMarkdown, with their package targets.
  • The hidden markdownEngine setting and MarkdownParser, the hoedown wrapper. ParseSettings now has named options instead of hoedown's flag bits.
  • The editor highlighter's own PEG parse. Highlighting always comes from the document model, and a Swift HighlightElement enum, in PEG's element order, replaces the C constants.
  • Scroll sync's hoedown fallback (ScrollAnchors.scan and the preview script that mirrored it). Anchors are now only source lines.
  • The two harnesses that compared hoedown and cmark-gfm. Their reviewed findings stay summarized in docs/MACDOWN-PORT.md.

Keeping the guarantees

Before deleting the C code, its outputs were recorded in Tests/MacDownKitTests/Resources/engine-snapshots.json:

  • hoedown's HTML for the renderer's byte-for-byte cases;
  • hoedown's escaping;
  • the C style parser's results for all 15 themes and a malformed stylesheet.

The renderer and theme tests now compare against those recordings. The highlighting benchmark compares against PEG's recorded time.

One fix came out of this. With PEG gone, turning the highlighter off and on again for a settings change would have left the editor unhighlighted until the next edit. It now keeps its highlight data and restyles straight away, and a test covers it.

Licenses and credits

  • hoedown.txt and hoextdown.txt are removed.
  • peg-markdown-highlight.txt stays, with a note at the top: the library isn't used, but MarkdownHighlighter and ThemeStyle are Swift ports of its code, kept so .style themes keep working. Both files point to the license.
  • New Licenses/README.md says what each license covers.
  • swift-cmark is covered by cmark-gfm.txt, which matches its license file exactly. There's no swift-markdown dependency.
  • About panel credits, in all 14 languages: LeVous (Rusty Zarse) is listed as a contributor, Hoedown and Hoextdown are replaced with cmark-gfm, and the PEG ports are noted. Tools/import_localizations.py applies these to the original's credits, so re-running it keeps them.

Also

  • Cleaned change spec references from code comments.
  • Updated CLAUDE.md, docs/ARCHITECTURE.md and docs/MACDOWN-PORT.md. The migration intent records the removal (Decision 11) and is marked done.

Testing

  • swift test: 373 passed (run twice where scroll sync and the live tests changed).
  • The app builds.
  • A Debug build launched with the old -markdownEngine hoedown setting ignores it, and the editor highlights and the preview renders as before.

🤖 Generated with Claude Code

levous and others added 7 commits October 22, 2026 11:17
Before the C libraries go, their outputs that the port must match are
recorded in engine-snapshots.json: hoedown's HTML for the renderer's
byte-for-byte cases, front matter, TOC, hard wrap, math, autolink, smart
punctuation, highlight/superscript and Prism languages; its escaping;
and pmh_styleparser.c's parse of every bundled theme and a malformed
stylesheet. HTMLRendererTests, HTMLEscapingTests, PrismLanguageTests
and ThemeStyleParserTests now compare with these instead of calling the
C code. swift test 386 passed; app build succeeded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The HTML and highlight harnesses compared the two engines over the
corpus; with hoedown going, their reviewed differences stay as the
summary in docs/MACDOWN-PORT.md. The HTML normalizer and hunk splitting,
which the paste round trip and renderer tests use, move to HTMLDiff.swift
with their tests. swift test 380 passed (the 6 harness tests are gone);
app build succeeded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cmark-gfm is the only Markdown engine:
- the hidden markdownEngine setting, MarkdownParser (the hoedown bridge)
  and the renderer's hoedown branch are gone; ParseSettings holds named
  options (autolink, math, smart punctuation, …) instead of hoedown flags
- the editor is always highlighted from the document model: the
  highlighter's PEG parse, extensions and usesExternalElements are gone,
  a Swift HighlightElement enum (PEG's element order) replaces the pmh_
  constants, and spans are kept across deactivate/activate so settings
  changes restyle without a parse of its own
- scroll sync anchors are source lines only: ScrollAnchors.scan (hoedown's
  block rules), the header/image kinds and the preview's mirroring script
  are gone
Tests drop their hoedown arguments and hoedown-pinned scroll tests; the
benchmark compares against PEG's recorded time. Checked in a running
Debug build launched with -markdownEngine hoedown: the stale value is
ignored, and the editor and preview render and highlight. swift test 373
passed twice; app build succeeded. The C targets are removed next.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sources/CHoedown (hoedown 3.0.7 with MacDown's patches) and
Sources/CPegMarkdown (PEG Markdown Highlight, with the generated
pmh_parser.c) and their package targets go; nothing uses them since the
previous commit. The package has no C targets left. swift test 373
passed; app build succeeded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hoedown.txt and hoextdown.txt are removed with hoedown. The PEG Markdown
Highlight license stays, with a note that the library isn't used: the
editor highlighter and theme parser are Swift ports of its code, kept so
.style themes work. Licenses/README.md says what each license covers
(cmark-gfm.txt is swift-cmark's COPYING; there's no swift-markdown
dependency to license). In the About panel's credits, every language
lists LeVous (Rusty Zarse) as a contributor, replaces Hoedown and
Hoextdown with cmark-gfm, and notes the PEG ports. The localization
import script applies these to the original's credits, so re-running it
keeps them. swift test 373 passed; app build succeeded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CLAUDE.md, ARCHITECTURE.md and MACDOWN-PORT.md describe cmark-gfm as the
only engine: no C targets or hidden engine setting, source-line scroll
anchors, the highlighter and theme parser as Swift ports of PEG Markdown
Highlight, renderer tests against hoedown's recorded output, and the
retired diff harnesses (their findings stay in MACDOWN-PORT.md). The
parser-regeneration section goes. The migration intent records the
removal as Decision 11 and is marked done. swift test 373 passed; app
build succeeded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Oct 22, 2026

Copy link
Copy Markdown

Claude code review a04bfd4

No issues found. Checked for bugs and CLAUDE.md compliance.

@levous
levous changed the base branch from feature/paste-formatted to main October 22, 2026 15:48
@claude

claude Bot commented Oct 22, 2026

Copy link
Copy Markdown

Claude code review ad66810

This PR removes the two C libraries (hoedown and PEG Markdown Highlight), so cmark-gfm is the only engine. Highlighting now always comes from the document model. The removal looks clean, and the recorded hoedown and PEG outputs keep the renderer and theme guarantees under test.

No blocking or should-fix findings.

What I checked:

  • Leftover references: no code references to markdownEngine, MarkdownParser, CHoedown or CPegMarkdown remain. Package.swift has no C targets left, and the resource list is unchanged.
  • Highlighter: MarkdownHighlighter keeps cachedElements across deactivate() and activate(), which restores highlighting after a settings change. DocumentController.setupEditor also re-feeds the model spans, and only when model.source == editor.string, so stale spans are never applied.
  • Scroll sync: anchors now come only from data-source-line. The JS parsing in PreviewController guards against malformed rows.
  • Package and licenses: the hoedown licenses are removed. The PEG license stays, with a note explaining why.

Not verified: I didn't build the package or run the test suite.

Ready to merge: the removal is coherent, behavior is preserved by recorded snapshots, and I found no correctness or concurrency problems.

@levous
levous merged commit 998a562 into main Oct 22, 2026
1 check passed
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