From 3ce99094bc351f0deddf2a816b72abc7ada2ca6a Mon Sep 17 00:00:00 2001 From: Maxim Reznik Date: Wed, 19 Nov 2025 11:41:31 +0200 Subject: [PATCH] Skip leading spaces in ATX headers --- .../implementation/markdown-implementation-atx_headings.adb | 6 ++++-- testsuite/commonmark/xfails.txt | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/source/parser/implementation/markdown-implementation-atx_headings.adb b/source/parser/implementation/markdown-implementation-atx_headings.adb index 19cab22..248bf3a 100644 --- a/source/parser/implementation/markdown-implementation-atx_headings.adb +++ b/source/parser/implementation/markdown-implementation-atx_headings.adb @@ -9,7 +9,7 @@ with VSS.Regular_Expressions; package body Markdown.Implementation.ATX_Headings is Prefix_Pattern : constant Wide_Wide_String := - "^(?: | | |)(######|#####|####|###|##|#)(?: |$)"; + "^(?: | | |)(######|#####|####|###|##|#)(?: +|$)"; Suffix_Pattern : constant Wide_Wide_String := " +#* *$"; @@ -37,6 +37,8 @@ package body Markdown.Implementation.ATX_Headings is overriding function Create (Input : not null access Input_Position) return ATX_Heading is + Ignore : Boolean; + Prefix_Match : constant VSS.Regular_Expressions.Regular_Expression_Match := Prefix.Match (Input.Line.Expanded, Input.First); @@ -50,11 +52,11 @@ package body Markdown.Implementation.ATX_Headings is Result.Level := Positive (Prefix_Match.Marker (1).Character_Length); Input.First.Set_At (Prefix_Match.Last_Marker); + Ignore := Input.First.Forward; -- Move to char after space if Suffix_Match.Has_Match then declare Last : VSS.Strings.Character_Iterators.Character_Iterator; - Ignore : Boolean; begin Last.Set_At (Suffix_Match.First_Marker); Ignore := Last.Backward; diff --git a/testsuite/commonmark/xfails.txt b/testsuite/commonmark/xfails.txt index 6c56a29..f1dc623 100644 --- a/testsuite/commonmark/xfails.txt +++ b/testsuite/commonmark/xfails.txt @@ -29,7 +29,6 @@ Example 59 (lines 1053-1060) Thematic breaks Example 65 (lines 1158-1162) ATX headings Example 66 (lines 1167-1171) ATX headings Example 76 (lines 1269-1277) ATX headings -Example 79 (lines 1307-1315) ATX headings Example 80 (lines 1347-1356) Setext headings Example 81 (lines 1361-1368) Setext headings Example 82 (lines 1375-1382) Setext headings @@ -198,4 +197,4 @@ Example 631 (lines 9191-9195) Raw HTML Example 632 (lines 9198-9202) Raw HTML Example 642 (lines 9305-9311) Hard line breaks Example 643 (lines 9314-9320) Hard line breaks -452 passed, 200 failed, 0 errored, 0 skipped +453 passed, 199 failed, 0 errored, 0 skipped