aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-11-25 11:46:02 +0100
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-11-25 11:46:02 +0100
commiteea185ea8509d37a1f87babab75b1f94350db802 (patch)
treef8a120ff2ddabbcb13fab0a04df7d3181fc1f3fd
parent4f776347163a514abadc7ded95e66a459be03bc9 (diff)
downloadmarkdown-rs-eea185ea8509d37a1f87babab75b1f94350db802.tar.gz
markdown-rs-eea185ea8509d37a1f87babab75b1f94350db802.tar.bz2
markdown-rs-eea185ea8509d37a1f87babab75b1f94350db802.zip
Fix double setext heading underlines
Related-to: GH-22.
-rw-r--r--src/construct/document.rs2
-rw-r--r--src/construct/heading_setext.rs5
-rw-r--r--tests/heading_setext.rs6
3 files changed, 9 insertions, 4 deletions
diff --git a/src/construct/document.rs b/src/construct/document.rs
index a81be8a..656525c 100644
--- a/src/construct/document.rs
+++ b/src/construct/document.rs
@@ -423,7 +423,7 @@ pub fn flow_end(tokenizer: &mut Tokenizer) -> State {
if !document_lazy_continuation_current && !child.events.is_empty() {
let before = skip::opt_back(&child.events, child.events.len() - 1, &[Name::LineEnding]);
let name = &child.events[before].name;
- if name == &Name::Content {
+ if name == &Name::Content || name == &Name::HeadingSetextUnderline {
document_lazy_continuation_current = true;
}
}
diff --git a/src/construct/heading_setext.rs b/src/construct/heading_setext.rs
index 6e0ec08..d66f339 100644
--- a/src/construct/heading_setext.rs
+++ b/src/construct/heading_setext.rs
@@ -92,13 +92,12 @@ pub fn start(tokenizer: &mut Tokenizer) -> State {
&& !tokenizer.pierce
// Require a paragraph before.
&& (!tokenizer.events.is_empty()
- && tokenizer.events[skip::opt_back(
+ && matches!(tokenizer.events[skip::opt_back(
&tokenizer.events,
tokenizer.events.len() - 1,
&[Name::LineEnding, Name::SpaceOrTab],
)]
- .name
- == Name::Content)
+ .name, Name::Content | Name::HeadingSetextUnderline))
{
tokenizer.enter(Name::HeadingSetextUnderline);
diff --git a/tests/heading_setext.rs b/tests/heading_setext.rs
index 29e8dd2..3bc1eef 100644
--- a/tests/heading_setext.rs
+++ b/tests/heading_setext.rs
@@ -250,6 +250,12 @@ fn heading_setext() -> Result<(), String> {
);
assert_eq!(
+ to_html("[a]: b\n=\n="),
+ "<h1>=</h1>",
+ "should support a two setext heading underlines after a definition, as a setext heading"
+ );
+
+ assert_eq!(
to_html("> ===\na"),
"<blockquote>\n<p>===\na</p>\n</blockquote>",
"should not support lazyness (1)"