From faae051821f7a3fc076d2f9cc0f3121033ee8779 Mon Sep 17 00:00:00 2001 From: Noah Hellman Date: Mon, 10 Jul 2023 22:26:26 +0200 Subject: [PATCH] block: let footnote definition continue unindented match reference implementation, let footnote paragraph continue on same line, but not start other blocks e.g. [^footnote]: first second --- src/block.rs | 18 ++++++++++++++++-- src/lib.rs | 30 +++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/block.rs b/src/block.rs index 5268ddd..6004901 100644 --- a/src/block.rs +++ b/src/block.rs @@ -816,6 +816,7 @@ enum Kind<'s> { indent: usize, footnote: bool, label: &'s str, + last_blankline: bool, }, Blockquote, ListItem { @@ -888,6 +889,7 @@ impl<'s> IdentifiedBlock<'s> { indent, footnote, label: &label[usize::from(footnote)..], + last_blankline: false, }, 0..(indent + 3 + l), ) @@ -1104,12 +1106,17 @@ impl<'s> Kind<'s> { *last_blankline || whitespace > *indent || para } Self::Definition { - indent, footnote, .. + indent, + footnote, + last_blankline, + .. } => { if *footnote { let line_t = line.trim_start_matches(|c: char| c.is_ascii_whitespace()); let whitespace = line.len() - line_t.len(); - matches!(next, Self::Atom(Blankline)) || whitespace > *indent + let cont_para = !*last_blankline && matches!(next, Self::Paragraph); + *last_blankline = matches!(next, Self::Atom(Blankline)); + whitespace > *indent || *last_blankline || cont_para } else { line.starts_with(' ') && !matches!(next, Self::Atom(Blankline)) } @@ -2898,6 +2905,7 @@ mod test { indent: 0, footnote: false, label: "tag", + last_blankline: false, }, "[tag]:", 1 @@ -2915,6 +2923,7 @@ mod test { indent: 0, footnote: false, label: "tag", + last_blankline: false, }, "[tag]:", 2, @@ -2928,6 +2937,7 @@ mod test { indent: 0, footnote: false, label: "tag", + last_blankline: false, }, "[tag]:", 1, @@ -2942,6 +2952,7 @@ mod test { indent: 0, footnote: true, label: "tag", + last_blankline: false, }, "[^tag]:", 1 @@ -2956,6 +2967,7 @@ mod test { indent: 0, footnote: true, label: "tag", + last_blankline: false, }, "[^tag]:", 1 @@ -2973,6 +2985,7 @@ mod test { indent: 0, footnote: true, label: "tag", + last_blankline: false, }, "[^tag]:", 2, @@ -2992,6 +3005,7 @@ mod test { indent: 0, footnote: true, label: "tag", + last_blankline: false, }, "[^tag]:", 3, diff --git a/src/lib.rs b/src/lib.rs index 3cd324a..97c8247 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1867,6 +1867,8 @@ mod test { "[^a]\n", "\n", "[^a]: note\n", + "cont\n", + "\n", "para\n", // ), Start(Paragraph, Attributes::new()), @@ -1876,11 +1878,33 @@ mod test { Start(Footnote { label: "a" }, Attributes::new()), Start(Paragraph, Attributes::new()), Str("note".into()), + Softbreak, + Str("cont".into()), + End(Paragraph), + Blankline, + End(Footnote { label: "a" }), + Start(Paragraph, Attributes::new()), + Str("para".into()), + End(Paragraph), + ); + test_parse!( + concat!( + "[^a]\n", // + "\n", // + "[^a]: note\n", // + ":::\n", // + ), + Start(Paragraph, Attributes::new()), + FootnoteReference("a"), + End(Paragraph), + Blankline, + Start(Footnote { label: "a" }, Attributes::new()), + Start(Paragraph, Attributes::new()), + Str("note".into()), End(Paragraph), End(Footnote { label: "a" }), - Start(Paragraph, Attributes::new()), - Str("para".into()), - End(Paragraph), + Start(Div { class: "" }, Attributes::new()), + End(Div { class: "" }), ); }