From bb7de2adff689665b4d274ded492f0789bca93f8 Mon Sep 17 00:00:00 2001 From: digitalMoksha Date: Thu, 25 Apr 2024 17:21:49 -0500 Subject: [PATCH] Fix sourcepos for setext headers --- src/parser/mod.rs | 1 - src/tests/core.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 9c9de85e..c5c10f4c 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1827,7 +1827,6 @@ impl<'a, 'o, 'c> Parser<'a, 'o, 'c> { } else if match ast.value { NodeValue::Document => true, NodeValue::CodeBlock(ref ncb) => ncb.fenced, - NodeValue::Heading(ref nh) => nh.setext, NodeValue::MultilineBlockQuote(..) => true, _ => false, } { diff --git a/src/tests/core.rs b/src/tests/core.rs index d9aabb52..81bd231c 100644 --- a/src/tests/core.rs +++ b/src/tests/core.rs @@ -64,6 +64,35 @@ fn thematic_breaks() { ); } +#[test] +fn atx_heading() { + html( + concat!("# h1\n", "foo\n", "## h2\n"), + concat!("

h1

\n", "

foo

\n", "

h2

\n"), + ); +} + +#[test] +fn atx_heading_sourcepos() { + assert_ast_match!( + [], + "# h1\n" + "foo\n" + "## h2\n", + (document (1:1-3:5) [ + (heading (1:1-1:4) [ + (text (1:3-1:4) "h1") + ]) + (paragraph (2:1-2:3) [ + (text (2:1-2:3) "foo") + ]) + (heading (3:1-3:5) [ + (text (3:4-3:5) "h2") + ]) + ]) + ); +} + #[test] fn setext_heading() { html( @@ -72,6 +101,24 @@ fn setext_heading() { ); } +#[test] +fn setext_heading_sourcepos() { + assert_ast_match!( + [], + "Header\n" + "---\n" + "this", + (document (1:1-3:4) [ + (heading (1:1-2:3) [ + (text (1:1-1:6) "Header") + ]) + (paragraph (3:1-3:4) [ + (text (3:1-3:4) "this") + ]) + ]) + ); +} + #[test] fn html_block_1() { html_opts!(