From d43410de70e5c4a7f4c3f9c99dcba3f8786ca249 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 31 May 2020 10:09:59 +0200 Subject: [PATCH] Fix table parsing --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 14 ++++++++++++++ src/parser.rs | 17 ++++++++--------- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1c77c80..e0ca5a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -153,7 +153,7 @@ dependencies = [ [[package]] name = "snekdown" -version = "0.1.0" +version = "0.1.1" dependencies = [ "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "htmlescape 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 40c1e5b..b17822a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snekdown" -version = "0.1.0" +version = "0.1.1" authors = ["trivernis "] edition = "2018" license-file = "LICENSE" diff --git a/README.md b/README.md index c6a267e..3fbeeee 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,20 @@ Quote with metadata (e.g. Author) Imports can be used to import a different document to be attached to the main document. Imports are parsed via multithreading. +### Tables + +Tables MUST start with a pipe character `|` + +``` +Standalone header: +| header | header | header + +Header with rows +| header | header | header +|--------|--------|------- +| row | row | row +``` + ``` <[path] ``` \ No newline at end of file diff --git a/src/parser.rs b/src/parser.rs index 6a51f95..fef4149 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -601,16 +601,15 @@ impl Parser { let header = self.parse_row()?; self.seek_whitespace(); let mut table = Table::new(header); - if self.check_special_group(&[MINUS, PIPE]) - && self.next_char() != None - && self.check_special_group(&[MINUS, PIPE]) - { - while let Some(char) = self.next_char() { - if char == '\n' { - break; - } + let seek_start = self.index; + while let Some(char) = self.next_char() { + self.seek_inline_whitespace(); + if char == '\n' || !self.check_special_group(&[MINUS, PIPE]) { + break; } - } else { + } + if !self.current_char.is_whitespace() || self.check_special_group(&[MINUS, PIPE]) { + self.revert_to(seek_start)?; return Ok(table); }