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
This commit is contained in:
parent
cee759f751
commit
faae051821
2 changed files with 43 additions and 5 deletions
18
src/block.rs
18
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,
|
||||
|
|
30
src/lib.rs
30
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: "" }),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue