Skip to content

Commit

Permalink
Fix sourcepos for setext headers
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalmoksha committed Apr 25, 2024
1 parent 0d4c448 commit bb7de2a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
} {
Expand Down
47 changes: 47 additions & 0 deletions src/tests/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ fn thematic_breaks() {
);
}

#[test]
fn atx_heading() {
html(
concat!("# h1\n", "foo\n", "## h2\n"),
concat!("<h1>h1</h1>\n", "<p>foo</p>\n", "<h2>h2</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(
Expand All @@ -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!(
Expand Down

0 comments on commit bb7de2a

Please sign in to comment.