mod export;
mod import;
mod inline;
mod table;
#[cfg(test)]
mod tests;
pub use export::serialize;
pub use import::{parse, parse_with};
pub(crate) use inline::image_markdown;
use crate::doc::{Flag, SOFT};
use crate::features::Features;
use pulldown_cmark::Options;
fn options(features: Features) -> Options {
let mut options = Options::empty();
options.set(Options::ENABLE_STRIKETHROUGH, features.strikethrough);
options.set(Options::ENABLE_TASKLISTS, features.task_lists);
options.set(Options::ENABLE_TABLES, features.tables);
options
}
fn is_break(c: char) -> bool {
c == '\n' || c == SOFT
}
fn html_flag(tag: &str) -> Option<(Flag, bool)> {
match tag {
"<strong>" => Some((Flag::Bold, false)),
"</strong>" => Some((Flag::Bold, true)),
"<em>" => Some((Flag::Italic, false)),
"</em>" => Some((Flag::Italic, true)),
"<del>" => Some((Flag::Strike, false)),
"</del>" => Some((Flag::Strike, true)),
_ => None,
}
}
fn flag_bit(flag: Flag) -> u8 {
match flag {
Flag::Bold => 1,
Flag::Italic => 2,
Flag::Strike => 4,
Flag::Code => 8,
}
}
fn flag_tag(flag: Flag, closing: bool) -> &'static str {
match (flag, closing) {
(Flag::Bold, false) => "<strong>",
(Flag::Bold, true) => "</strong>",
(Flag::Italic, false) => "<em>",
(Flag::Italic, true) => "</em>",
(Flag::Strike, false) => "<del>",
(Flag::Strike, true) => "</del>",
(Flag::Code, false) => "<code>",
(Flag::Code, true) => "</code>",
}
}
pub fn normalize(markdown: &str) -> String {
serialize(&parse(markdown))
}