iced_markdown_editor/markdown/
mod.rs1mod export;
22mod import;
23mod inline;
24mod table;
25#[cfg(test)]
26mod tests;
27
28pub use export::serialize;
29pub use import::{parse, parse_with};
30pub(crate) use inline::image_markdown;
31
32use crate::doc::{Flag, SOFT};
33use crate::features::Features;
34use pulldown_cmark::Options;
35
36fn options(features: Features) -> Options {
37 let mut options = Options::empty();
38 options.set(Options::ENABLE_STRIKETHROUGH, features.strikethrough);
39 options.set(Options::ENABLE_TASKLISTS, features.task_lists);
40 options.set(Options::ENABLE_TABLES, features.tables);
41 options
42}
43
44fn is_break(c: char) -> bool {
45 c == '\n' || c == SOFT
46}
47
48fn html_flag(tag: &str) -> Option<(Flag, bool)> {
50 match tag {
51 "<strong>" => Some((Flag::Bold, false)),
52 "</strong>" => Some((Flag::Bold, true)),
53 "<em>" => Some((Flag::Italic, false)),
54 "</em>" => Some((Flag::Italic, true)),
55 "<del>" => Some((Flag::Strike, false)),
56 "</del>" => Some((Flag::Strike, true)),
57 _ => None,
58 }
59}
60
61fn flag_bit(flag: Flag) -> u8 {
62 match flag {
63 Flag::Bold => 1,
64 Flag::Italic => 2,
65 Flag::Strike => 4,
66 Flag::Code => 8,
67 }
68}
69
70fn flag_tag(flag: Flag, closing: bool) -> &'static str {
71 match (flag, closing) {
72 (Flag::Bold, false) => "<strong>",
73 (Flag::Bold, true) => "</strong>",
74 (Flag::Italic, false) => "<em>",
75 (Flag::Italic, true) => "</em>",
76 (Flag::Strike, false) => "<del>",
77 (Flag::Strike, true) => "</del>",
78 (Flag::Code, false) => "<code>",
79 (Flag::Code, true) => "</code>",
80 }
81}
82
83pub fn normalize(markdown: &str) -> String {
85 serialize(&parse(markdown))
86}