Add Superscript and update Readme with Roadmap

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

2
Cargo.lock generated

@ -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)",

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

@ -146,4 +146,31 @@ Set options for placeholders
```
|| These two lines
|| 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::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!("<sup>{}</sup>", self.value.to_html())
}
}
impl ToHtml for MonospaceText {
fn to_html(&self) -> String {
format!(

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

@ -13,6 +13,7 @@ pub(crate) trait ParseInline {
fn parse_striked(&mut self) -> Result<StrikedText, ParseError>;
fn parse_monospace(&mut self) -> Result<MonospaceText, 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_surrounded(&mut self, surrounding: &char) -> Result<Inline, ParseError>;
}
@ -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<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
fn parse_plain(&mut self) -> Result<PlainText, ParseError> {
if self.check_linebreak() {

@ -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;

@ -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;

@ -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,
},
))));
}

@ -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] = [

Loading…
Cancel
Save