Skip to content

fix: recognize lowercase declarations as HTML blocks (CommonMark 4.6) - #1189

Merged
puzrin merged 1 commit into
markdown-it:masterfrom
spokodev:w33/markdown-it-html-block-lowercase-declaration
Jul 3, 2026
Merged

puzrin merged 1 commit into
markdown-it:masterfrom
spokodev:w33/markdown-it-html-block-lowercase-declaration

Conversation

@spokodev

@spokodev spokodev commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

CommonMark start condition 4 for HTML blocks (spec 4.6) says a block begins with
<! followed by an ASCII letter. ASCII letter means both cases, [A-Za-z].

The block rule in lib/rules_block/html_block.mjs matches only [A-Z], so a line
like

foo
<!bar baz>

is not recognized as an HTML block. Instead the declaration is pulled into the
preceding paragraph as inline HTML:

<p>foo
<!bar baz></p>

The spec-correct output, and the output of the reference commonmark.js renderer,
is:

<p>foo</p>
<!bar baz>

because an HTML block of type 4 interrupts a paragraph.

The inline HTML rule already uses the correct range: lib/common/html_re.mjs has
const declaration = '<![A-Za-z][^>]*>'. This change makes the block rule match
the same range, so uppercase and lowercase declarations behave the same.

Change: /^<![A-Z]/ becomes /^<![A-Za-z]/.

Added a fixture in test/fixtures/markdown-it/commonmark_extras.txt covering a
lowercase declaration interrupting a paragraph.

All 652 CommonMark spec examples and the full markdown-it suite pass.

@puzrin

puzrin commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

LGTM. Rebase please, conflicting with your another marged PR (samples landed to the same file)

@spokodev
spokodev force-pushed the w33/markdown-it-html-block-lowercase-declaration branch from b454a5a to 214e458 Compare July 3, 2026 11:40
@spokodev

spokodev commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto master. The samples from #1188 and this PR now sit side by side in commonmark_extras.txt, and the full suite is green.

@puzrin
puzrin merged commit 2d9bbea into markdown-it:master Jul 3, 2026
1 check passed
meta-codesync Bot pushed a commit to meta/memlab that referenced this pull request Sep 30, 2026
Summary:
Bumps [[https://github.com/markdown-it/markdown-it | markdown-it]] from 14.3.0 to 14.3.2 in `website/`.

**Changelog** (from [[https://github.com/markdown-it/markdown-it/blob/14.3.2/CHANGELOG.md | markdown-it's changelog]]):

- **14.3.2** (2026-09-12), Security: backported 15.0.2 fixes.
- **14.3.1** (2026-08-27), Security: backported 15.0.1 fixes.

**Commits:**

- [[markdown-it/markdown-it@efb9993 | efb9993]] 14.3.2 released
- [[markdown-it/markdown-it@daf5a3c | daf5a3c]] Backported 15.0.2 fixes
- [[markdown-it/markdown-it@a855f10 | a855f10]] 14.3.1 released
- [[markdown-it/markdown-it@ad70f6b | ad70f6b]] Backported 15.0.1 fixes
- [[markdown-it/markdown-it@b407f3b | b407f3b]] Ignore generated API docs in lint
- [[markdown-it/markdown-it@bf025ad | bf025ad]] Prepare package.json for v14 backports
- [[markdown-it/markdown-it@2d9bbea | 2d9bbea]] fix: recognize lowercase declarations as HTML blocks (CommonMark 4.6) ([[markdown-it/markdown-it#1189 | #1189]])
- [[markdown-it/markdown-it@a311cfb | a311cfb]] fix: keep literal backslash before space in link destination (CommonMark 6.3)
- Full diff: [[markdown-it/markdown-it@14.3.0...14.3.2 | 14.3.0...14.3.2]]

Only `website/yarn.lock` changes.

Pull Request resolved: #156

Differential Revision: D122444745

Pulled By: JacksonGL

fbshipit-source-id: e5a4d891b3431785279f5101f22490d6346c64be
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.

2 participants