diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2024-04-21 13:57:03 +1200 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2024-04-21 13:57:36 +1200 |
commit | 13cb719b87bcef41c4dd398f5a651ddb2b561e0d (patch) | |
tree | e9e52ed33d5ed5a4d68a1161c3db5c2d8c38dd42 /src/lib.rs | |
parent | 54f5e9fd883e207931baa9c87b6181ca724d6bab (diff) | |
download | markdown-13cb719b87bcef41c4dd398f5a651ddb2b561e0d.zip |
Completely rewrite the libraryv1.0.0
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 44 |
1 files changed, 12 insertions, 32 deletions
@@ -1,33 +1,13 @@ -#![feature(iter_zip)] - -mod block; -mod parse; -mod parse_heirarchical; -mod table; -mod text; - -pub use block::Block; -pub use parse::parse; -pub use parse_heirarchical::parse_heirarchical; -pub use table::{Alignment, Column, Table}; -pub use text::{Hyperlink, Text}; - -pub type Line = Vec<Text>; - -pub fn line_to_string(line: &[Text]) -> String { - let mut output = String::new(); - for text in line { - match text { - Text::Normal(content) => output.push_str(&content), - Text::Bold(content) => output.push_str(&format!("**{}**", content)), - Text::Italic(content) => output.push_str(&format!("_{}_", content)), - Text::BoldItalic(content) => output.push_str(&format!("**_{}_**", content)), - Text::Code(content) => output.push_str(&format!("`{}`", content)), - Text::WikiLink(content) => output.push_str(&format!("[[{}]]", content)), - Text::Hyperlink(Hyperlink { label, target }) => { - output.push_str(&format!("[{}]({})", label, target)) - } - } - } - return output; +mod document; +mod elements; + +pub use document::*; +pub use elements::*; + +pub(crate) fn is_whitespace(c: &char) -> bool { + c.is_whitespace() || r#".,'"“”_:;-/\()[]{}?"#.contains(*c) } +pub(crate) fn is_contentful(s:&str, non_content_chars: &[char]) -> bool { + s.chars().any(|c| !non_content_chars.contains(&c)) + && s.chars().nth(0).map(|c| !non_content_chars.contains(&c)).unwrap_or(false) + && s.chars().last().map(|c| !non_content_chars.contains(&c)).unwrap_or(false) } |