1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct Grammar {
/// Enable `[admin]foo[/admin]` blocks
pub admin: bool,
/// Maximum nesting depth.
///
/// - `None` means there is no depth limit
/// - `Some(0)` means that only `Text` and `NewLine` nodes are produced
/// - `Some(1)` renders `_foo_` as `<em>foo</em>` but renders `**_foo_**` as `<strong>_foo_</strong>`.
pub depth: Option<u8>,
/// Enable `_foo_` spans
pub emphasis: bool,
/// Set of allowed icon keys
pub icons: HashSet<String>,
/// Set of allowed link protocols
pub links: HashSet<String>,
/// Enable `[mod]foo[/mod]` blocks
pub r#mod: bool,
/// Enable `[quote]foo[/quote]` blocks
pub quote: bool,
/// Enable `||foo||` spans
pub spoiler: bool,
/// Enable `**foo**` spans
pub strong: bool,
/// Enable `~~foo~~` spans
pub strikethrough: bool,
}
impl Grammar {
pub fn full() -> Self {
Self {
admin: true,
emphasis: true,
depth: Some(4),
icons: {
let mut icons = HashSet::new();
icons.insert(String::from("etwin"));
icons
},
links: {
let mut links = HashSet::new();
links.insert(String::from("http"));
links.insert(String::from("https"));
links
},
r#mod: true,
quote: true,
spoiler: true,
strong: true,
strikethrough: true,
}
}
}