Don't allow empty lists and enums

This commit is contained in:
Laurenz 2022-04-05 15:04:35 +02:00
parent b865accae6
commit b8233a9e01
5 changed files with 14 additions and 4 deletions

View File

@ -277,6 +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()) {
p.eat_while(|kind| kind.is_space());
markup_line(p); markup_line(p);
marker.end(p, NodeKind::Heading); marker.end(p, NodeKind::Heading);
} else { } else {
@ -291,8 +292,8 @@ fn list_node(p: &mut Parser, at_start: bool) {
let text: EcoString = p.peek_src().into(); let text: EcoString = p.peek_src().into();
p.eat_assert(&NodeKind::Minus); p.eat_assert(&NodeKind::Minus);
if at_start && p.peek().map_or(true, |kind| kind.is_space()) { let column = p.column(p.prev_end());
let column = p.column(p.prev_end()); if at_start && p.eat_if(&NodeKind::Space(0)) && !p.eof() {
markup_indented(p, column); markup_indented(p, column);
marker.end(p, NodeKind::List); marker.end(p, NodeKind::List);
} else { } else {
@ -306,8 +307,8 @@ fn enum_node(p: &mut Parser, at_start: bool) {
let text: EcoString = p.peek_src().into(); let text: EcoString = p.peek_src().into();
p.eat(); p.eat();
if at_start && p.peek().map_or(true, |kind| kind.is_space()) { let column = p.column(p.prev_end());
let column = p.column(p.prev_end()); if at_start && p.eat_if(&NodeKind::Space(0)) && !p.eof() {
markup_indented(p, column); markup_indented(p, column);
marker.end(p, NodeKind::Enum); marker.end(p, NodeKind::Enum);
} else { } else {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -46,6 +46,10 @@
[Red], [Green], [Blue], [Red], [Green], [Blue],
) )
---
// Lone dot is not a list.
.
--- ---
// Error: 18-20 invalid pattern // Error: 18-20 invalid pattern
#set enum(label: "") #set enum(label: "")

View File

@ -49,3 +49,8 @@ paragraphs.
// This doesn't work because of mixed tabs and spaces. // This doesn't work because of mixed tabs and spaces.
- A with 2 spaces - A with 2 spaces
- B with 2 tabs - B with 2 tabs
---
#set list(label: [-])
- Bare hyphen
- is not a list