Update README and Cargo.toml

pull/1/head
trivernis 5 years ago
parent 242ae666a0
commit 269e26840f

@ -1,8 +1,20 @@
[package] [package]
name = "snekdown" name = "snekdown"
version = "0.1.0" version = "0.1.0"
authors = ["trivernis <trivernis@gmail.com>"] authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018" 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 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -3,6 +3,24 @@
This projects goal is to implement a fast markdown parser with an extended syntax fitted This projects goal is to implement a fast markdown parser with an extended syntax fitted
for my needs. for my needs.
## Usage
```
USAGE:
snekdown [OPTIONS] <input> <output>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-f, --format <format> [default: html]
ARGS:
<input>
<output>
```
## Syntax ## Syntax
### Images ### Images

@ -53,6 +53,7 @@ pub struct Parser {
paths: Arc<Mutex<Vec<String>>>, paths: Arc<Mutex<Vec<String>>>,
wg: WaitGroup, wg: WaitGroup,
is_child: bool, is_child: bool,
subtext_break_at: Vec<char>,
} }
impl Parser { impl Parser {
@ -95,6 +96,7 @@ impl Parser {
paths, paths,
wg: WaitGroup::new(), wg: WaitGroup::new(),
is_child, is_child,
subtext_break_at: Vec::new(),
} }
} }
@ -487,6 +489,7 @@ impl Parser {
/// Parses a paragraph /// Parses a paragraph
fn parse_paragraph(&mut self) -> Result<Paragraph, ParseError> { fn parse_paragraph(&mut self) -> Result<Paragraph, ParseError> {
self.seek_whitespace();
let mut paragraph = Paragraph::new(); let mut paragraph = Paragraph::new();
while let Ok(token) = self.parse_inline() { while let Ok(token) = self.parse_inline() {
paragraph.add_element(token); paragraph.add_element(token);
@ -595,22 +598,23 @@ impl Parser {
/// parses a markdown table /// parses a markdown table
fn parse_table(&mut self) -> Result<Table, ParseError> { fn parse_table(&mut self) -> Result<Table, ParseError> {
let header = self.parse_row()?; // TODO: Fix this row not being included let header = self.parse_row()?;
let start_index = self.index;
self.seek_whitespace(); self.seek_whitespace();
if self.check_special(&MINUS) { let mut table = Table::new(header);
if self.next_char() != Some(PIPE) { if self.check_special_group(&[MINUS, PIPE])
return Err(self.revert_with_error(start_index)); && self.next_char() != None
} && self.check_special_group(&[MINUS, PIPE])
} {
while let Some(char) = self.next_char() { while let Some(char) = self.next_char() {
if char == '\n' { if char == '\n' {
break; break;
}
} }
} else {
return Ok(table);
} }
self.seek_whitespace();
let mut table = Table::new(header);
self.seek_whitespace();
while let Ok(row) = self.parse_row() { while let Ok(row) = self.parse_row() {
table.add_row(row); table.add_row(row);
self.seek_whitespace(); self.seek_whitespace();
@ -623,14 +627,18 @@ impl Parser {
pub fn parse_row(&mut self) -> Result<Row, ParseError> { pub fn parse_row(&mut self) -> Result<Row, ParseError> {
let start_index = self.index; let start_index = self.index;
self.seek_inline_whitespace(); self.seek_inline_whitespace();
self.subtext_break_at.push(PIPE);
if self.check_special(&PIPE) { if self.check_special(&PIPE) {
if self.next_char() == None { if self.next_char() == None {
self.subtext_break_at.clear();
return Err(self.revert_with_error(start_index)); return Err(self.revert_with_error(start_index));
} }
} else { } else {
self.subtext_break_at.clear();
return Err(self.revert_with_error(start_index)); return Err(self.revert_with_error(start_index));
} }
self.seek_inline_whitespace();
let mut row = Row::new(); let mut row = Row::new();
while let Ok(element) = self.parse_inline() { while let Ok(element) = self.parse_inline() {
row.add_cell(Cell { text: element }); row.add_cell(Cell { text: element });
@ -642,7 +650,9 @@ impl Parser {
if self.check_linebreak() { if self.check_linebreak() {
break; break;
} }
self.seek_inline_whitespace();
} }
self.subtext_break_at.clear();
if row.cells.len() > 0 { if row.cells.len() > 0 {
Ok(row) Ok(row)
@ -843,6 +853,7 @@ impl Parser {
loop { loop {
if self.check_special_group(&INLINE_SPECIAL_CHARS) if self.check_special_group(&INLINE_SPECIAL_CHARS)
|| (count > 0 && self.check_special_group(&INLINE_SPECIAL_CHARS_SECOND)) || (count > 0 && self.check_special_group(&INLINE_SPECIAL_CHARS_SECOND))
|| (count > 0 && self.check_special_group(&self.subtext_break_at))
{ {
break; break;
} else if !self.check_special(&SPECIAL_ESCAPE) { } else if !self.check_special(&SPECIAL_ESCAPE) {

@ -48,7 +48,7 @@ pub(crate) const BLOCK_SPECIAL_CHARS: [char; 7] = [
IMPORT_START, 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 INLINE_SPECIAL_CHARS_SECOND: [char; 3] = [DESC_OPEN, IMG_START, URL_OPEN];
pub(crate) const LIST_SPECIAL_CHARS: [char; 4] = [MINUS, PLUS, ASTERISK, O]; pub(crate) const LIST_SPECIAL_CHARS: [char; 4] = [MINUS, PLUS, ASTERISK, O];

Loading…
Cancel
Save