Add Superscript and update Readme with Roadmap

pull/1/head
trivernis 5 years ago
parent 5ee46ac8df
commit 4af6ab9487

2
Cargo.lock generated

@ -382,7 +382,7 @@ dependencies = [
[[package]] [[package]]
name = "snekdown" name = "snekdown"
version = "0.8.5" version = "0.9.0"
dependencies = [ dependencies = [
"chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",

@ -1,6 +1,6 @@
[package] [package]
name = "snekdown" name = "snekdown"
version = "0.8.5" version = "0.9.0"
authors = ["trivernis <trivernis@protonmail.com>"] authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018" edition = "2018"
license-file = "LICENSE" license-file = "LICENSE"

@ -147,3 +147,30 @@ Set options for placeholders
|| These two lines || These two lines
|| are centered || are centered
``` ```
### 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

@ -56,6 +56,7 @@ impl ToHtml for Inline {
Inline::Image(img) => img.to_html(), Inline::Image(img) => img.to_html(),
Inline::Placeholder(placeholder) => placeholder.lock().unwrap().to_html(), Inline::Placeholder(placeholder) => placeholder.lock().unwrap().to_html(),
Inline::Reference(reference) => reference.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!("<sup>{}</sup>", self.value.to_html())
}
}
impl ToHtml for MonospaceText { impl ToHtml for MonospaceText {
fn to_html(&self) -> String { fn to_html(&self) -> String {
format!( format!(

@ -165,6 +165,7 @@ pub enum Inline {
Underlined(UnderlinedText), Underlined(UnderlinedText),
Striked(StrikedText), Striked(StrikedText),
Monospace(MonospaceText), Monospace(MonospaceText),
Superscript(SuperscriptText),
Url(Url), Url(Url),
Image(Image), Image(Image),
Placeholder(Arc<Mutex<Placeholder>>), Placeholder(Arc<Mutex<Placeholder>>),
@ -201,6 +202,11 @@ pub struct MonospaceText {
pub(crate) value: String, pub(crate) value: String,
} }
#[derive(Clone, Debug)]
pub struct SuperscriptText {
pub(crate) value: Box<Inline>,
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Url { pub struct Url {
pub description: Option<String>, pub description: Option<String>,
@ -241,6 +247,7 @@ pub struct Reference {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct ReferenceEntry { pub struct ReferenceEntry {
pub(crate) value: Option<RefValue>, pub(crate) value: Option<RefValue>,
pub(crate) reference_count: usize,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]

@ -13,6 +13,7 @@ pub(crate) trait ParseInline {
fn parse_striked(&mut self) -> Result<StrikedText, ParseError>; fn parse_striked(&mut self) -> Result<StrikedText, ParseError>;
fn parse_monospace(&mut self) -> Result<MonospaceText, ParseError>; fn parse_monospace(&mut self) -> Result<MonospaceText, ParseError>;
fn parse_underlined(&mut self) -> Result<UnderlinedText, ParseError>; fn parse_underlined(&mut self) -> Result<UnderlinedText, ParseError>;
fn parse_superscript(&mut self) -> Result<SuperscriptText, ParseError>;
fn parse_plain(&mut self) -> Result<PlainText, ParseError>; fn parse_plain(&mut self) -> Result<PlainText, ParseError>;
fn parse_surrounded(&mut self, surrounding: &char) -> Result<Inline, ParseError>; fn parse_surrounded(&mut self, surrounding: &char) -> Result<Inline, ParseError>;
} }
@ -38,6 +39,8 @@ impl ParseInline for Parser {
Ok(Inline::Monospace(mono)) Ok(Inline::Monospace(mono))
} else if let Ok(striked) = self.parse_striked() { } else if let Ok(striked) = self.parse_striked() {
Ok(Inline::Striked(striked)) Ok(Inline::Striked(striked))
} else if let Ok(superscript) = self.parse_superscript() {
Ok(Inline::Superscript(superscript))
} else { } else {
Ok(Inline::Plain(self.parse_plain()?)) Ok(Inline::Plain(self.parse_plain()?))
} }
@ -141,6 +144,12 @@ impl ParseInline for Parser {
}) })
} }
fn parse_superscript(&mut self) -> Result<SuperscriptText, ParseError> {
Ok(SuperscriptText {
value: Box::new(self.parse_surrounded(&SUPER)?),
})
}
/// parses plain text as a string until it encounters an unescaped special inline char /// parses plain text as a string until it encounters an unescaped special inline char
fn parse_plain(&mut self) -> Result<PlainText, ParseError> { fn parse_plain(&mut self) -> Result<PlainText, ParseError> {
if self.check_linebreak() { if self.check_linebreak() {

@ -1,6 +1,6 @@
pub mod charstate; pub mod charstate;
pub mod elements; pub mod elements;
pub mod inline;
pub mod parser; pub mod parser;
pub mod placeholders; pub mod placeholders;
pub mod subtext;
pub mod tokens; pub mod tokens;

@ -1,8 +1,8 @@
use super::elements::*; use super::elements::*;
use super::tokens::*; use super::tokens::*;
use crate::parsing::charstate::CharStateMachine; use crate::parsing::charstate::CharStateMachine;
use crate::parsing::inline::ParseInline;
use crate::parsing::placeholders::ProcessPlaceholders; use crate::parsing::placeholders::ProcessPlaceholders;
use crate::parsing::subtext::ParseInline;
use crossbeam_utils::sync::WaitGroup; use crossbeam_utils::sync::WaitGroup;
use std::collections::HashMap; use std::collections::HashMap;
use std::error::Error; use std::error::Error;

@ -184,6 +184,7 @@ impl ProcessPlaceholders for Document {
pholder.value = Some(Element::Line(Box::new(Line::ReferenceEntry( pholder.value = Some(Element::Line(Box::new(Line::ReferenceEntry(
ReferenceEntry { ReferenceEntry {
value: Some(RefValue::BibEntry(entry)), value: Some(RefValue::BibEntry(entry)),
reference_count: 0,
}, },
)))); ))));
} }

@ -24,6 +24,7 @@ pub(crate) const EQ: char = '=';
pub(crate) const DOUBLE_QUOTE: char = '"'; pub(crate) const DOUBLE_QUOTE: char = '"';
pub(crate) const SINGLE_QUOTE: char = '\''; pub(crate) const SINGLE_QUOTE: char = '\'';
pub(crate) const DOT: char = '.'; pub(crate) const DOT: char = '.';
pub(crate) const UP: char = '^';
// aliases // aliases
@ -46,6 +47,7 @@ pub(crate) const ITALIC: char = ASTERISK;
pub(crate) const MONOSPACE: char = BACKTICK; pub(crate) const MONOSPACE: char = BACKTICK;
pub(crate) const STRIKED: char = TILDE; pub(crate) const STRIKED: char = TILDE;
pub(crate) const UNDERLINED: char = UNDERSCR; pub(crate) const UNDERLINED: char = UNDERSCR;
pub(crate) const SUPER: char = UP;
pub(crate) const BOLD: [char; 2] = [ASTERISK, ASTERISK]; pub(crate) const BOLD: [char; 2] = [ASTERISK, ASTERISK];
// groups // groups
@ -64,8 +66,8 @@ pub(crate) const BLOCK_SPECIAL_CHARS: [&[char]; 9] = [
&SQ_CENTERED_START, &SQ_CENTERED_START,
]; ];
pub(crate) const INLINE_SPECIAL_CHARS: [char; 8] = [ pub(crate) const INLINE_SPECIAL_CHARS: [char; 9] = [
BACKTICK, TILDE, UNDERSCR, ASTERISK, DESC_OPEN, IMG_START, URL_OPEN, LB, BACKTICK, TILDE, UNDERSCR, ASTERISK, DESC_OPEN, IMG_START, URL_OPEN, LB, SUPER,
]; ];
pub(crate) const LIST_SPECIAL_CHARS: [char; 14] = [ pub(crate) const LIST_SPECIAL_CHARS: [char; 14] = [

Loading…
Cancel
Save