From 269e26840fc5dc579988f94e0d286f97336ef8eb Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 31 May 2020 09:59:53 +0200 Subject: [PATCH] Update README and Cargo.toml --- Cargo.toml | 14 +++++++++++++- README.md | 18 ++++++++++++++++++ src/parser.rs | 35 +++++++++++++++++++++++------------ src/tokens.rs | 2 +- 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fa33728..40c1e5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,20 @@ [package] name = "snekdown" version = "0.1.0" -authors = ["trivernis "] +authors = ["trivernis "] edition = "2018" +license-file = "LICENSE" +readme = "README.md" +description = "A parser for the custom snekdown markdown syntax" +homepage = "https://github.com/Trivernis/snekdown" + +[lib] +name = "snekdown" +crate-type = ["lib"] + +[[bin]] +name = "snekdown" +path = "src/main.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index dc89bf4..c6a267e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,24 @@ This projects goal is to implement a fast markdown parser with an extended syntax fitted for my needs. +## Usage + +``` +USAGE: + snekdown [OPTIONS] + +FLAGS: + -h, --help Prints help information + -V, --version Prints version information + +OPTIONS: + -f, --format [default: html] + +ARGS: + + +``` + ## Syntax ### Images diff --git a/src/parser.rs b/src/parser.rs index 7c735da..6a51f95 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -53,6 +53,7 @@ pub struct Parser { paths: Arc>>, wg: WaitGroup, is_child: bool, + subtext_break_at: Vec, } impl Parser { @@ -95,6 +96,7 @@ impl Parser { paths, wg: WaitGroup::new(), is_child, + subtext_break_at: Vec::new(), } } @@ -487,6 +489,7 @@ impl Parser { /// Parses a paragraph fn parse_paragraph(&mut self) -> Result { + self.seek_whitespace(); let mut paragraph = Paragraph::new(); while let Ok(token) = self.parse_inline() { paragraph.add_element(token); @@ -595,22 +598,23 @@ impl Parser { /// parses a markdown table fn parse_table(&mut self) -> Result { - let header = self.parse_row()?; // TODO: Fix this row not being included - let start_index = self.index; + let header = self.parse_row()?; self.seek_whitespace(); - if self.check_special(&MINUS) { - if self.next_char() != Some(PIPE) { - return Err(self.revert_with_error(start_index)); - } - } - while let Some(char) = self.next_char() { - if char == '\n' { - break; + 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; + } } + } else { + return Ok(table); } - self.seek_whitespace(); - let mut table = Table::new(header); + self.seek_whitespace(); while let Ok(row) = self.parse_row() { table.add_row(row); self.seek_whitespace(); @@ -623,14 +627,18 @@ impl Parser { pub fn parse_row(&mut self) -> Result { let start_index = self.index; self.seek_inline_whitespace(); + self.subtext_break_at.push(PIPE); if self.check_special(&PIPE) { if self.next_char() == None { + self.subtext_break_at.clear(); return Err(self.revert_with_error(start_index)); } } else { + self.subtext_break_at.clear(); return Err(self.revert_with_error(start_index)); } + self.seek_inline_whitespace(); let mut row = Row::new(); while let Ok(element) = self.parse_inline() { row.add_cell(Cell { text: element }); @@ -642,7 +650,9 @@ impl Parser { if self.check_linebreak() { break; } + self.seek_inline_whitespace(); } + self.subtext_break_at.clear(); if row.cells.len() > 0 { Ok(row) @@ -843,6 +853,7 @@ impl Parser { loop { if self.check_special_group(&INLINE_SPECIAL_CHARS) || (count > 0 && self.check_special_group(&INLINE_SPECIAL_CHARS_SECOND)) + || (count > 0 && self.check_special_group(&self.subtext_break_at)) { break; } else if !self.check_special(&SPECIAL_ESCAPE) { diff --git a/src/tokens.rs b/src/tokens.rs index a631734..d29d192 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -48,7 +48,7 @@ pub(crate) const BLOCK_SPECIAL_CHARS: [char; 7] = [ IMPORT_START, ]; -pub(crate) const INLINE_SPECIAL_CHARS: [char; 6] = [LB, ASTERISK, UNDERSCR, TILDE, PIPE, BACKTICK]; +pub(crate) const INLINE_SPECIAL_CHARS: [char; 5] = [LB, ASTERISK, UNDERSCR, TILDE, BACKTICK]; pub(crate) const INLINE_SPECIAL_CHARS_SECOND: [char; 3] = [DESC_OPEN, IMG_START, URL_OPEN]; pub(crate) const LIST_SPECIAL_CHARS: [char; 4] = [MINUS, PLUS, ASTERISK, O];