Skip to content

fix: don't parse list/quote markers inside headings as blocks (fixes #115) - #119

Open
Ultroncn wants to merge 1 commit into
developit:mainfrom
Ultroncn:fix/numbers-in-headings-parsed-as-lists
Open

Ultroncn wants to merge 1 commit into
developit:mainfrom
Ultroncn:fix/numbers-in-headings-parsed-as-lists

Conversation

@Ultroncn

Copy link
Copy Markdown

Problem

### 1. Agreement rendered as <h3><ol><li>Agreement</li></ol></h3> instead of <h3>1. Agreement</h3>.

Reproduced locally before the fix:

  • ### 1. Agreement → <h3><ol><li>Agreement</li></ol></h3>
  • ### 2. Rights → <h3><ol><li>Rights</li></ol></h3>

Root cause

The heading branch re-parsed its contents with the full block parser, which treats a leading 1. as an ordered list (same for - , > etc.).

Fix

Headings can't contain blocks, so heading contents are now parsed inline-only (new internal inline flag on parse(); the public two-argument call signature is unchanged). A leading list/quote marker inside a heading is kept as literal text and only the rest is parsed for inline formatting, so ### 1. **Agreement** still bolds correctly.

Tests

  • npm test (eslint + mocha): 35 passing, including 2 new regression tests in test/index.js under 'titles'.
  • Real ordered/unordered lists, blockquotes, and lists inside blockquotes all still pass unchanged.

…evelopit#115)

'### 1. Agreement' rendered as '<h3><ol><li>Agreement</li></ol></h3>'
because the heading branch re-parsed its contents with the full block
parser, which treats a leading '1. ' as an ordered list. Headings can't
contain blocks, so parse heading contents inline-only: a leading
list/quote marker is kept as literal text and only the rest is parsed
for inline formatting.

Adds an internal 'inline' flag to parse(); the public two-argument
call signature is unchanged.
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