Skip to content

[markdown] Fix setext heading precedence over lists in gitHubFlavored - #2510

Merged
srawlins merged 1 commit into
dart-lang:mainfrom
hkarmoush:fix-gfm-setext-header-list-precedence
Aug 13, 2026
Merged

srawlins merged 1 commit into
dart-lang:mainfrom
hkarmoush:fix-gfm-setext-header-list-precedence

Conversation

@hkarmoush

Copy link
Copy Markdown
Contributor

Summary

ExtensionSet.gitHubFlavored's block syntax list checked UnorderedListWithCheckboxSyntax before SetextHeaderSyntax. Since custom document.blockSyntaxes are always tried before the standard ones in BlockParser.parseLines, a lone -/= line continuing a paragraph was parsed as an empty list item instead of a setext heading underline — unlike the default parser (which orders SetextHeaderSyntax first) and ExtensionSet.gitHubWeb (which already puts SetextHeaderWithIdSyntax before its list syntaxes).

import 'package:markdown/markdown.dart' as md;

void main() {
  final doc = md.Document(blockSyntaxes: [const md.UnorderedListSyntax()]);
  print((doc.parseLines('I am paragraph\n-')[0] as md.Element).tag);
  // actual: ul   expected: h2
}

This matches CommonMark / GitHub's own rendering (confirmed in the issue by @lrhn) — see https://spec.commonmark.org/dingus/?text=I%20am%20paragraph%0A-.

Fixes #2108 (duplicate of #1953).

Changes

  • Adds SetextHeaderSyntax to ExtensionSet.gitHubFlavored's block syntax list, ordered before the list syntaxes.
  • Adds a regression test in test/regression_test.dart.
  • Adds a changelog entry under the unreleased 7.4.0 section.

Test plan

  • dart test — full markdown suite passes (2763 passed, 1 pre-existing skip, 0 failures)
  • dart analyze --fatal-infos . — no issues
  • dart format --output=none --set-exit-if-changed on changed files — no changes needed

ExtensionSet.gitHubFlavored checked UnorderedListWithCheckboxSyntax
before SetextHeaderSyntax, so a lone `-`/`=` line continuing a
paragraph was parsed as an empty list item instead of a setext
heading underline (unlike the default parser and gitHubWeb, which
already order this correctly).

Fixes dart-lang#2108.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes an issue in ExtensionSet.gitHubFlavored where a lone - or = line continuing a paragraph was incorrectly parsed as an empty list item instead of a setext heading underline. This is resolved by adding SetextHeaderSyntax before the list syntaxes in the block syntaxes list. A regression test has been added to verify this behavior. There are no review comments, and I have no additional feedback to provide.

@srawlins
srawlins merged commit c2e4de1 into dart-lang:main Aug 13, 2026
24 checks passed
tomyeh added a commit to tomyeh/markd that referenced this pull request Sep 24, 2026
…ake AutolinkExtensionSyntax.emailPattern public

* Fix quadratic parsing time on a long unbroken run of word characters ending a line (dart-lang/tools#2536)
* Fix performance and correctness of the HTML comment parser; processing instructions, declarations and CDATA sections may span lines; tag names accept uppercase letters (dart-lang/tools#2121)
* Fix nested list structure when indented by tabs (dart-lang/tools#2173)
* Escape image description text when assigning it to the alt attribute (dart-lang/tools#2478)
* markdownToHtml respects enableTagfilter when inlineOnly is true; the tag filter covers tags with attributes, spaces, self-closing and closing tags (dart-lang/tools#2471, dart-lang/tools#2472)
* Bound the email regex quantifiers in AutolinkExtensionSyntax (dart-lang/tools#2474)
* ExtensionSet.gitHubFlavored: setext heading underline takes precedence over an empty list item (dart-lang/tools#2510)
* AutolinkExtensionSyntax.emailPattern is public, for reuse by Quire

Co-author: Claude Fable 5.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ExtensionSet.gitHubFlavored leads to incorrect parsing of "a\n-"

2 participants