Skip to content

Use Markdown::Perl for GitHub-style fenced code blocks (#57)#71

Merged
jmacdotorg merged 1 commit into
masterfrom
fix/57-fenced-code-blocks
Jun 23, 2026
Merged

Use Markdown::Perl for GitHub-style fenced code blocks (#57)#71
jmacdotorg merged 1 commit into
masterfrom
fix/57-fenced-code-blocks

Conversation

@jmacdotorg

@jmacdotorg jmacdotorg commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Closes #57.

Diagnosis

Text::MultiMarkdown only understands indented (4-space) code blocks — it has no support for GitHub-style fences. A triple-backtick block was parsed as a single inline <code> span, so every line collapsed together (the reporter's "wrapped block of code rather than each line on a new line"), and ~~~ fences were ignored entirely.

Approach

Rather than pre-processing fences by hand, swap the Markdown engine to Markdown::Perl in GitHub mode. It's a maintained, pure-Perl CommonMark + GFM implementation that handles fenced code blocks (with language-foo info-string classes), tables, and the rest of GFM natively. The hand-rolled fence preprocessor is gone.

SmartyPants interaction

Markdown::Perl follows CommonMark and HTML-escapes "&quot; during conversion, which would stop Plerd::SmartyPants from curling literal double quotes into typographic ones. We drop " from html_escaped_characters so quotes survive for SmartyPants; quotes inside code spans/blocks are still escaped via the separate html_escaped_code_characters option. SmartyPants is still required (and kept) for curly quotes, en/em dashes, and ellipses — Markdown::Perl does no typographic substitution of its own.

Notes

  • Perl floor raised to 5.26 (declared in cpanfile): Markdown::Perl requires it. Makefile.PL is regenerated by Minilla at release, per the existing house pattern for dependency changes.
  • Dependency swap in cpanfile: drop Text::MultiMarkdown, add Markdown::Perl (pure Perl, no compiler/C library).
  • CLAUDE.md updated to describe the new engine.

Tests

t/code_blocks.t covers backtick and tilde fences, language classes, line preservation, escaping, and untouched inline code. Full suite (84 tests) passes, including the existing MultiMarkdown table test.

@jmacdotorg jmacdotorg force-pushed the fix/57-fenced-code-blocks branch from af35341 to ffed416 Compare June 23, 2026 22:12
@jmacdotorg jmacdotorg changed the title Support GitHub-style fenced code blocks (#57) Use Markdown::Perl for GitHub-style fenced code blocks (#57) Jun 23, 2026
#57)

Text::MultiMarkdown has no support for GitHub-style fenced code blocks: a
backtick fence was parsed as a single inline <code> span (collapsing the
whole block onto one line) and ~~~ fences were ignored entirely.

Switch the Markdown engine to Markdown::Perl in GitHub mode, which handles
fenced code blocks (with language-foo info-string classes), tables, and the
rest of GFM natively. This replaces an earlier hand-rolled fence
preprocessor with a maintained CommonMark/GFM implementation.

Markdown::Perl follows CommonMark and HTML-escapes " to &quot; during
conversion, which would stop Plerd::SmartyPants from curling literal double
quotes; drop '"' from html_escaped_characters so quotes survive for
SmartyPants (quotes inside code are still escaped via the separate
html_escaped_code_characters option). SmartyPants is still required for
curly quotes, dashes, and ellipses.

Markdown::Perl requires Perl 5.26, so raise the floor in cpanfile.

Also declare Capture::Tiny, a long-standing undeclared test dependency of
t/init.t: it had been satisfied transitively through the Text::Markdown
stack, so removing that stack exposed it.

t/code_blocks.t covers backtick and tilde fences, language classes, line
preservation, escaping, and untouched inline code.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jmacdotorg jmacdotorg force-pushed the fix/57-fenced-code-blocks branch from ffed416 to fc62437 Compare June 23, 2026 23:49
@jmacdotorg jmacdotorg merged commit f1a450b into master Jun 23, 2026
3 checks passed
@jmacdotorg jmacdotorg deleted the fix/57-fenced-code-blocks branch June 23, 2026 23:53
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.

Code blocks?

1 participant