Skip to content

Trim tabs around the fenced code info string - #468

Open
lprnmns wants to merge 1 commit into
mity:masterfrom
lprnmns:fence-info-tabs
Open

lprnmns wants to merge 1 commit into
mity:masterfrom
lprnmns:fence-info-tabs

Conversation

@lprnmns

@lprnmns lprnmns commented Oct 22, 2026

Copy link
Copy Markdown

When a tab separates the opening code fence from its info string, the info string keeps the tab and the language is lost:

$ printf '```\truby\ndef foo(x)\n```\n' | md2html
<pre><code>def foo(x)
</code></pre>

The spec says the text after the fence "is trimmed of leading and trailing spaces or tabs and called the info string" (4.5), so commonmark.js gives <pre><code class="language-ruby">. md_setup_fenced_code_detail() only skipped spaces, so det->info started with the tab, and the det->lang scan stopped right away at that whitespace, which left an empty language. A trailing tab ended up in det->info the same way.

The fix trims with ISBLANK() (space or tab) on both ends. md_is_opening_code_fence() doesn't need a change since it only looks for the end of the line and for backticks.

I added a "Tabs around the fenced code info string" section to test/regressions.txt, with a tab before the info string and a mix of spaces and tabs on both sides. Both examples fail without the change. spec.txt, coverage.txt, regressions.txt and the spec-*.txt suites all pass with md2html built from this branch.

@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.33%. Comparing base (f9e5eb2) to head (656e4df).

Files with missing lines Patch % Lines
src/md4c.c 0.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #468      +/-   ##
==========================================
+ Coverage   79.30%   79.33%   +0.02%     
==========================================
  Files           5        5              
  Lines        3929     3929              
  Branches     1311     1311              
==========================================
+ Hits         3116     3117       +1     
+ Misses        295      294       -1     
  Partials      518      518              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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