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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! YAMD - Yet Another Markdown Document (flavour)
//!
//! Simplified version of [CommonMark](https://spec.commonmark.org/).
//!
//! For formatting check [`YAMD`](nodes::Yamd) struct documentation.
//!
//! # Quick start
//!
//! ```rust
//! use yamd::deserialize;
//!
//! let input = "# Hello\n\nA paragraph with **bold** text.";
//! let yamd = deserialize(input);
//!
//! // Access the AST
//! assert_eq!(yamd.body.len(), 2);
//!
//! // Round-trip back to markdown
//! assert_eq!(yamd.to_string(), input);
//! ```
//!
//! # Reasoning
//!
//! Simplified set of rules allows to have simpler, more efficient, parser and renderer.
//! [YAMD](nodes::Yamd) does not provide render functionality, instead it is a [serde]
//! serializable structure that allows you to write any renderer for that structure. All HTML
//! equivalents in this doc are provided as an example to what it can be rendered.
//!
//! # Difference from CommonMark
//!
//! While YAMD tries to utilize as much CommonMark syntax as possible, there are differences.
//!
//! ## Escaping
//!
//! Escaping done on a [lexer] level. Every symbol following the `\` symbol will be treated as a
//! [literal](lexer::TokenKind::Literal).
//!
//! Example:
//!
//! | YAMD | HTML equivalent |
//! |-----------|-----------------|
//! | `\**foo**`|`<p>**foo**</p>` |
//!
//! ## Precedence
//!
//! [CommonMark](https://spec.commonmark.org/0.31.2/#precedence) defines container blocks and leaf
//! blocks. And that container block indicator has higher precedence. YAMD does not discriminate by
//! block type, every node (block) is the same. In practice, there are no additional rules to encode
//! and remember.
//!
//! Example:
//!
//! | YAMD | HTML equivalent |
//! |-----------------------|-----------------------------------------------|
//! | ``- `one\n- two` `` | `<ol><li><code>one\n- two</code></li></ol>` |
//!
//!
//! If you want to have two [ListItem](nodes::ListItem)'s use escaping:
//!
//! | YAMD | HTML equivalent |
//! |---------------------------|-------------------------------------------|
//! | ``- \`one\n- two\` `` | ``<ol><li>`one</li><li>two`</li><ol>`` |
//!
//! The reasoning is that those kind issues can be caught with tooling like linters/lsp. That tooling
//! does not exist yet.
//!
//! ## Nodes
//!
//! List of supported [nodes] and their formatting. The best starting point is [YAMD](nodes::Yamd).
//!
//! # MSRV
//!
//! YAMD minimal supported Rust version is 1.80.0 due to [Option::take_if] usage
pub use Yamd;
pub use parse;
pub use to_yamd;
/// Deserialize a string into a Yamd struct
/// # Example
/// ```
/// use yamd::deserialize;
/// let input = "# header";
/// let yamd = deserialize(input);
/// ```