mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Fix headings that are separated by only one newline 🚧
Previously the following lead to only one line with both heading and body: ``` # Heading Body ```
This commit is contained in:
parent
475ca7a62e
commit
98f77e4d80
@ -357,6 +357,7 @@ impl Eval for NodeHeading {
|
|||||||
ctx.state.font.strong = true;
|
ctx.state.font.strong = true;
|
||||||
|
|
||||||
self.contents.eval(ctx);
|
self.contents.eval(ctx);
|
||||||
|
SynNode::Parbreak.eval(ctx);
|
||||||
|
|
||||||
ctx.state = prev;
|
ctx.state = prev;
|
||||||
}
|
}
|
||||||
|
@ -100,11 +100,10 @@ fn heading(p: &mut Parser, start: Pos) -> NodeHeading {
|
|||||||
let span = Span::new(start, p.pos());
|
let span = Span::new(start, p.pos());
|
||||||
let level = (count.min(5) as u8).span_with(span);
|
let level = (count.min(5) as u8).span_with(span);
|
||||||
if count > 5 {
|
if count > 5 {
|
||||||
p.diag(warning!(span, "section depth larger than 6 has no effect"));
|
p.diag(warning!(span, "section depth should be at most 6"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the heading contents.
|
// Parse the heading contents.
|
||||||
p.skip_white();
|
|
||||||
let mut contents = vec![];
|
let mut contents = vec![];
|
||||||
while p.check(|t| !matches!(t, Token::Space(n) if n >= 1)) {
|
while p.check(|t| !matches!(t, Token::Space(n) if n >= 1)) {
|
||||||
if let Some(node) = node(p, false) {
|
if let Some(node) = node(p, false) {
|
||||||
|
@ -295,31 +295,33 @@ fn test_parse_comments() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_headings() {
|
fn test_parse_headings() {
|
||||||
t!("## Hello world!" => H![1, T("Hello"), S, T("world!")]);
|
t!("## Hello world!" => H![1, S, T("Hello"), S, T("world!")]);
|
||||||
|
|
||||||
// Handle various whitespace usages.
|
// Handle various whitespace usages.
|
||||||
t!("####Simple" => H![3, T("Simple")]);
|
t!("####Simple" => H![3, T("Simple")]);
|
||||||
t!(" # Whitespace!" => S, H![0, T("Whitespace!")]);
|
t!(" # Whitespace!" => S, H![0, S, T("Whitespace!")]);
|
||||||
t!(" /* TODO: Improve */ ## Analysis" => S, S, H!(1, T("Analysis")));
|
t!(" /* TODO: Improve */ ## Analysis" => S, S, H!(1, S, T("Analysis")));
|
||||||
|
t!("# Heading \n ends" => H![0, S, T("Heading")], S, T("ends"));
|
||||||
|
|
||||||
// Complex heading contents.
|
// Complex heading contents.
|
||||||
t!("Some text [box][### Valuable facts]" => T("Some"), S, T("text"), S,
|
t!("Some text [box][### Valuable facts]" => T("Some"), S, T("text"), S,
|
||||||
F!("box"; Tree![H!(2, T("Valuable"), S, T("facts"))])
|
F!("box"; Tree![H!(2, S, T("Valuable"), S, T("facts"))])
|
||||||
);
|
);
|
||||||
t!("### Grandiose stuff [box][Get it \n\n straight]" => H![2,
|
t!("### Grandiose stuff [box][Get it \n\n straight]" => H![
|
||||||
T("Grandiose"), S, T("stuff"), S,
|
2,
|
||||||
|
S, T("Grandiose"), S, T("stuff"), S,
|
||||||
F!("box"; Tree![T("Get"), S, T("it"), P, T("straight")])
|
F!("box"; Tree![T("Get"), S, T("it"), P, T("straight")])
|
||||||
]);
|
]);
|
||||||
t!("###### Multiline \\ headings" => H![5, T("Multiline"), S, L, S, T("headings")]);
|
t!("###### Multiline \\ headings" => H![5, S, T("Multiline"), S, L, S, T("headings")]);
|
||||||
|
|
||||||
// Things that should not become headings.
|
// Things that should not become headings.
|
||||||
t!("\\## Text" => T("#"), T("#"), S, T("Text"));
|
t!("\\## Text" => T("#"), T("#"), S, T("Text"));
|
||||||
t!(" ###### # Text" => S, H!(5, T("#"), S, T("Text")));
|
t!(" ###### # Text" => S, H![5, S, T("#"), S, T("Text")]);
|
||||||
t!("I am #1" => T("I"), S, T("am"), S, T("#"), T("1"));
|
t!("I am #1" => T("I"), S, T("am"), S, T("#"), T("1"));
|
||||||
t!("[box][\n] # hi" => F!("box"; Tree![S]), S, T("#"), S, T("hi"));
|
t!("[box][\n] # hi" => F!("box"; Tree![S]), S, T("#"), S, T("hi"));
|
||||||
|
|
||||||
// Depth warnings.
|
// Depth warnings.
|
||||||
e!("########" => s(0, 8, "section depth larger than 6 has no effect"));
|
e!("########" => s(0, 8, "section depth should be at most 6"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user