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,
|
indent: usize,
|
||||||
footnote: bool,
|
footnote: bool,
|
||||||
label: &'s str,
|
label: &'s str,
|
||||||
|
last_blankline: bool,
|
||||||
},
|
},
|
||||||
Blockquote,
|
Blockquote,
|
||||||
ListItem {
|
ListItem {
|
||||||
|
@ -888,6 +889,7 @@ impl<'s> IdentifiedBlock<'s> {
|
||||||
indent,
|
indent,
|
||||||
footnote,
|
footnote,
|
||||||
label: &label[usize::from(footnote)..],
|
label: &label[usize::from(footnote)..],
|
||||||
|
last_blankline: false,
|
||||||
},
|
},
|
||||||
0..(indent + 3 + l),
|
0..(indent + 3 + l),
|
||||||
)
|
)
|
||||||
|
@ -1104,12 +1106,17 @@ impl<'s> Kind<'s> {
|
||||||
*last_blankline || whitespace > *indent || para
|
*last_blankline || whitespace > *indent || para
|
||||||
}
|
}
|
||||||
Self::Definition {
|
Self::Definition {
|
||||||
indent, footnote, ..
|
indent,
|
||||||
|
footnote,
|
||||||
|
last_blankline,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
if *footnote {
|
if *footnote {
|
||||||
let line_t = line.trim_start_matches(|c: char| c.is_ascii_whitespace());
|
let line_t = line.trim_start_matches(|c: char| c.is_ascii_whitespace());
|
||||||
let whitespace = line.len() - line_t.len();
|
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 {
|
} else {
|
||||||
line.starts_with(' ') && !matches!(next, Self::Atom(Blankline))
|
line.starts_with(' ') && !matches!(next, Self::Atom(Blankline))
|
||||||
}
|
}
|
||||||
|
@ -2898,6 +2905,7 @@ mod test {
|
||||||
indent: 0,
|
indent: 0,
|
||||||
footnote: false,
|
footnote: false,
|
||||||
label: "tag",
|
label: "tag",
|
||||||
|
last_blankline: false,
|
||||||
},
|
},
|
||||||
"[tag]:",
|
"[tag]:",
|
||||||
1
|
1
|
||||||
|
@ -2915,6 +2923,7 @@ mod test {
|
||||||
indent: 0,
|
indent: 0,
|
||||||
footnote: false,
|
footnote: false,
|
||||||
label: "tag",
|
label: "tag",
|
||||||
|
last_blankline: false,
|
||||||
},
|
},
|
||||||
"[tag]:",
|
"[tag]:",
|
||||||
2,
|
2,
|
||||||
|
@ -2928,6 +2937,7 @@ mod test {
|
||||||
indent: 0,
|
indent: 0,
|
||||||
footnote: false,
|
footnote: false,
|
||||||
label: "tag",
|
label: "tag",
|
||||||
|
last_blankline: false,
|
||||||
},
|
},
|
||||||
"[tag]:",
|
"[tag]:",
|
||||||
1,
|
1,
|
||||||
|
@ -2942,6 +2952,7 @@ mod test {
|
||||||
indent: 0,
|
indent: 0,
|
||||||
footnote: true,
|
footnote: true,
|
||||||
label: "tag",
|
label: "tag",
|
||||||
|
last_blankline: false,
|
||||||
},
|
},
|
||||||
"[^tag]:",
|
"[^tag]:",
|
||||||
1
|
1
|
||||||
|
@ -2956,6 +2967,7 @@ mod test {
|
||||||
indent: 0,
|
indent: 0,
|
||||||
footnote: true,
|
footnote: true,
|
||||||
label: "tag",
|
label: "tag",
|
||||||
|
last_blankline: false,
|
||||||
},
|
},
|
||||||
"[^tag]:",
|
"[^tag]:",
|
||||||
1
|
1
|
||||||
|
@ -2973,6 +2985,7 @@ mod test {
|
||||||
indent: 0,
|
indent: 0,
|
||||||
footnote: true,
|
footnote: true,
|
||||||
label: "tag",
|
label: "tag",
|
||||||
|
last_blankline: false,
|
||||||
},
|
},
|
||||||
"[^tag]:",
|
"[^tag]:",
|
||||||
2,
|
2,
|
||||||
|
@ -2992,6 +3005,7 @@ mod test {
|
||||||
indent: 0,
|
indent: 0,
|
||||||
footnote: true,
|
footnote: true,
|
||||||
label: "tag",
|
label: "tag",
|
||||||
|
last_blankline: false,
|
||||||
},
|
},
|
||||||
"[^tag]:",
|
"[^tag]:",
|
||||||
3,
|
3,
|
||||||
|
|
30
src/lib.rs
30
src/lib.rs
|
@ -1867,6 +1867,8 @@ mod test {
|
||||||
"[^a]\n",
|
"[^a]\n",
|
||||||
"\n",
|
"\n",
|
||||||
"[^a]: note\n",
|
"[^a]: note\n",
|
||||||
|
"cont\n",
|
||||||
|
"\n",
|
||||||
"para\n", //
|
"para\n", //
|
||||||
),
|
),
|
||||||
Start(Paragraph, Attributes::new()),
|
Start(Paragraph, Attributes::new()),
|
||||||
|
@ -1876,11 +1878,33 @@ mod test {
|
||||||
Start(Footnote { label: "a" }, Attributes::new()),
|
Start(Footnote { label: "a" }, Attributes::new()),
|
||||||
Start(Paragraph, Attributes::new()),
|
Start(Paragraph, Attributes::new()),
|
||||||
Str("note".into()),
|
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(Paragraph),
|
||||||
End(Footnote { label: "a" }),
|
End(Footnote { label: "a" }),
|
||||||
Start(Paragraph, Attributes::new()),
|
Start(Div { class: "" }, Attributes::new()),
|
||||||
Str("para".into()),
|
End(Div { class: "" }),
|
||||||
End(Paragraph),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue