mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Don't allow headings to span multiple lines
This commit is contained in:
parent
2eacfcfa81
commit
b865accae6
@ -364,7 +364,7 @@ mod tests {
|
|||||||
test("hey #myfriend", 4 .. 4, "\\", 0 .. 14);
|
test("hey #myfriend", 4 .. 4, "\\", 0 .. 14);
|
||||||
test("hey #myfriend", 4 .. 4, "\\", 3 .. 6);
|
test("hey #myfriend", 4 .. 4, "\\", 3 .. 6);
|
||||||
test("= foo\nbar\n - a\n - b", 6 .. 9, "", 0 .. 11);
|
test("= foo\nbar\n - a\n - b", 6 .. 9, "", 0 .. 11);
|
||||||
test("= foo\n bar\n baz", 6 .. 8, "", 0 .. 15);
|
test("= foo\n bar\n baz", 6 .. 8, "", 0 .. 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -161,6 +161,11 @@ fn markup(p: &mut Parser, mut at_start: bool) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parse a single line of markup.
|
||||||
|
fn markup_line(p: &mut Parser) {
|
||||||
|
markup_indented(p, usize::MAX);
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse markup that stays right of the given `column`.
|
/// Parse markup that stays right of the given `column`.
|
||||||
fn markup_indented(p: &mut Parser, column: usize) {
|
fn markup_indented(p: &mut Parser, column: usize) {
|
||||||
p.eat_while(|t| match t {
|
p.eat_while(|t| match t {
|
||||||
@ -272,8 +277,7 @@ fn heading(p: &mut Parser, at_start: bool) {
|
|||||||
while p.eat_if(&NodeKind::Eq) {}
|
while p.eat_if(&NodeKind::Eq) {}
|
||||||
|
|
||||||
if at_start && p.peek().map_or(true, |kind| kind.is_space()) {
|
if at_start && p.peek().map_or(true, |kind| kind.is_space()) {
|
||||||
let column = p.column(p.prev_end());
|
markup_line(p);
|
||||||
markup_indented(p, column);
|
|
||||||
marker.end(p, NodeKind::Heading);
|
marker.end(p, NodeKind::Heading);
|
||||||
} else {
|
} else {
|
||||||
let text = p.get(current_start .. p.prev_end()).into();
|
let text = p.get(current_start .. p.prev_end()).into();
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 23 KiB |
@ -26,20 +26,16 @@ No = heading
|
|||||||
\= No heading
|
\= No heading
|
||||||
|
|
||||||
---
|
---
|
||||||
// While indented at least as much as the start, the heading continues.
|
// Blocks can continue the heading.
|
||||||
|
|
||||||
= This
|
= [This
|
||||||
is
|
is
|
||||||
indented.
|
multiline.
|
||||||
|
]
|
||||||
|
|
||||||
= This
|
= This
|
||||||
is not.
|
is not.
|
||||||
|
|
||||||
// Code blocks continue heading.
|
|
||||||
= A {
|
|
||||||
"B"
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test styling.
|
// Test styling.
|
||||||
= Heading
|
= Heading
|
||||||
|
Loading…
x
Reference in New Issue
Block a user