From 4af6ab9487b3006144abfb8b50cdbed99bcadad2 Mon Sep 17 00:00:00 2001 From: trivernis Date: Tue, 2 Jun 2020 22:37:26 +0200 Subject: [PATCH] Add Superscript and update Readme with Roadmap --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 29 ++++++++++++++++++++++++++++- src/format/html.rs | 7 +++++++ src/parsing/elements.rs | 7 +++++++ src/parsing/inline.rs | 9 +++++++++ src/parsing/mod.rs | 2 +- src/parsing/parser.rs | 2 +- src/parsing/placeholders.rs | 1 + src/parsing/tokens.rs | 6 ++++-- 10 files changed, 60 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67b4808..7d0f2ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -382,7 +382,7 @@ dependencies = [ [[package]] name = "snekdown" -version = "0.8.5" +version = "0.9.0" dependencies = [ "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index d7a528e..b6b6684 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snekdown" -version = "0.8.5" +version = "0.9.0" authors = ["trivernis "] edition = "2018" license-file = "LICENSE" diff --git a/README.md b/README.md index 75c8a49..96a6497 100644 --- a/README.md +++ b/README.md @@ -146,4 +146,31 @@ Set options for placeholders ``` || These two lines || are centered -``` \ No newline at end of file +``` + +### Inline + +```md +*Italic* +**Bold** +~Striked~ +_Underlined_ +^Superscript^ +`Monospace` +``` + +## Roadmap + +The end goal is to have a markdown language similar to LaTeX. + +- [] Emojis (\:emoji:) +- [] Bibliography +- [] Math +- [] Figures +- [] Text sizes +- [] Colors +- [] Cross References +- [] Title pages +- [] Glossary +- [] EPUB Rendering (PDF is too hard +- [] Custom Elements via templates diff --git a/src/format/html.rs b/src/format/html.rs index 317972c..e0b98a1 100644 --- a/src/format/html.rs +++ b/src/format/html.rs @@ -56,6 +56,7 @@ impl ToHtml for Inline { Inline::Image(img) => img.to_html(), Inline::Placeholder(placeholder) => placeholder.lock().unwrap().to_html(), Inline::Reference(reference) => reference.to_html(), + Inline::Superscript(superscript) => superscript.to_html(), } } } @@ -349,6 +350,12 @@ impl ToHtml for StrikedText { } } +impl ToHtml for SuperscriptText { + fn to_html(&self) -> String { + format!("{}", self.value.to_html()) + } +} + impl ToHtml for MonospaceText { fn to_html(&self) -> String { format!( diff --git a/src/parsing/elements.rs b/src/parsing/elements.rs index 3fae1dd..9007762 100644 --- a/src/parsing/elements.rs +++ b/src/parsing/elements.rs @@ -165,6 +165,7 @@ pub enum Inline { Underlined(UnderlinedText), Striked(StrikedText), Monospace(MonospaceText), + Superscript(SuperscriptText), Url(Url), Image(Image), Placeholder(Arc>), @@ -201,6 +202,11 @@ pub struct MonospaceText { pub(crate) value: String, } +#[derive(Clone, Debug)] +pub struct SuperscriptText { + pub(crate) value: Box, +} + #[derive(Clone, Debug)] pub struct Url { pub description: Option, @@ -241,6 +247,7 @@ pub struct Reference { #[derive(Clone, Debug)] pub struct ReferenceEntry { pub(crate) value: Option, + pub(crate) reference_count: usize, } #[derive(Clone, Debug)] diff --git a/src/parsing/inline.rs b/src/parsing/inline.rs index 7b5cd8e..0c60336 100644 --- a/src/parsing/inline.rs +++ b/src/parsing/inline.rs @@ -13,6 +13,7 @@ pub(crate) trait ParseInline { fn parse_striked(&mut self) -> Result; fn parse_monospace(&mut self) -> Result; fn parse_underlined(&mut self) -> Result; + fn parse_superscript(&mut self) -> Result; fn parse_plain(&mut self) -> Result; fn parse_surrounded(&mut self, surrounding: &char) -> Result; } @@ -38,6 +39,8 @@ impl ParseInline for Parser { Ok(Inline::Monospace(mono)) } else if let Ok(striked) = self.parse_striked() { Ok(Inline::Striked(striked)) + } else if let Ok(superscript) = self.parse_superscript() { + Ok(Inline::Superscript(superscript)) } else { Ok(Inline::Plain(self.parse_plain()?)) } @@ -141,6 +144,12 @@ impl ParseInline for Parser { }) } + fn parse_superscript(&mut self) -> Result { + Ok(SuperscriptText { + value: Box::new(self.parse_surrounded(&SUPER)?), + }) + } + /// parses plain text as a string until it encounters an unescaped special inline char fn parse_plain(&mut self) -> Result { if self.check_linebreak() { diff --git a/src/parsing/mod.rs b/src/parsing/mod.rs index e9d6906..3c8d04b 100644 --- a/src/parsing/mod.rs +++ b/src/parsing/mod.rs @@ -1,6 +1,6 @@ pub mod charstate; pub mod elements; +pub mod inline; pub mod parser; pub mod placeholders; -pub mod subtext; pub mod tokens; diff --git a/src/parsing/parser.rs b/src/parsing/parser.rs index abe6814..65cdbcf 100644 --- a/src/parsing/parser.rs +++ b/src/parsing/parser.rs @@ -1,8 +1,8 @@ use super::elements::*; use super::tokens::*; use crate::parsing::charstate::CharStateMachine; +use crate::parsing::inline::ParseInline; use crate::parsing::placeholders::ProcessPlaceholders; -use crate::parsing::subtext::ParseInline; use crossbeam_utils::sync::WaitGroup; use std::collections::HashMap; use std::error::Error; diff --git a/src/parsing/placeholders.rs b/src/parsing/placeholders.rs index ae5f39b..69ee724 100644 --- a/src/parsing/placeholders.rs +++ b/src/parsing/placeholders.rs @@ -184,6 +184,7 @@ impl ProcessPlaceholders for Document { pholder.value = Some(Element::Line(Box::new(Line::ReferenceEntry( ReferenceEntry { value: Some(RefValue::BibEntry(entry)), + reference_count: 0, }, )))); } diff --git a/src/parsing/tokens.rs b/src/parsing/tokens.rs index 8772651..e09c078 100644 --- a/src/parsing/tokens.rs +++ b/src/parsing/tokens.rs @@ -24,6 +24,7 @@ pub(crate) const EQ: char = '='; pub(crate) const DOUBLE_QUOTE: char = '"'; pub(crate) const SINGLE_QUOTE: char = '\''; pub(crate) const DOT: char = '.'; +pub(crate) const UP: char = '^'; // aliases @@ -46,6 +47,7 @@ pub(crate) const ITALIC: char = ASTERISK; pub(crate) const MONOSPACE: char = BACKTICK; pub(crate) const STRIKED: char = TILDE; pub(crate) const UNDERLINED: char = UNDERSCR; +pub(crate) const SUPER: char = UP; pub(crate) const BOLD: [char; 2] = [ASTERISK, ASTERISK]; // groups @@ -64,8 +66,8 @@ pub(crate) const BLOCK_SPECIAL_CHARS: [&[char]; 9] = [ &SQ_CENTERED_START, ]; -pub(crate) const INLINE_SPECIAL_CHARS: [char; 8] = [ - BACKTICK, TILDE, UNDERSCR, ASTERISK, DESC_OPEN, IMG_START, URL_OPEN, LB, +pub(crate) const INLINE_SPECIAL_CHARS: [char; 9] = [ + BACKTICK, TILDE, UNDERSCR, ASTERISK, DESC_OPEN, IMG_START, URL_OPEN, LB, SUPER, ]; pub(crate) const LIST_SPECIAL_CHARS: [char; 14] = [