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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
//! Doccy is a simple brace based markup language, an alternative to writing HTML for people who enjoy the power and flexibility but do not enjoy writing it.
//!
//!
//! # Syntax
//! ## Elements
//!
//! Anything between two curley-braces is considered an element.
//!
//!
//! ### Regular Elements
//!
//! Writing an element is easy:
//!
//! ```doccy
//! {h1: Top-level heading}
//! ```
//!
//! Renders as:
//!
//! ```html
//! <h1>Top-level heading</h1>
//! ```
//!
//!
//! ### Self closing Elements
//!
//! Some elements do not support children, and are self closing in which case the colon can be skipped entirely. For example line breaks (`<br>`) can be written as:
//!
//! ```doccy
//! {br}
//! ```
//!
//! Renders as:
//!
//! ```html
//! <br>
//! ```
//!
//! If you use this syntax for elements that do not support being self closing in HTML, then a closing tag will be rendered:
//!
//! ```doccy
//! {div}
//! ```
//!
//! Renders as:
//!
//! ```html
//! <div></div>
//! ```
//!
//!
//! ### Preformatted Elements
//!
//! Sometimes it is necessary to ignore Doccy syntax, you can do this with a Preformatted Element:
//!
//! ```doccy
//! {pre:#
//! You can use all of the {brackets} in here and they {em: won't be parsed!}
//! #}
//! ```
//!
//! Renders as:
//!
//! ```html
//! <pre>You can use all of the {brackets} in here and they {em: won't be parsed!}</pre>
//! ```
//!
//! This isn't just limited to the HTML `pre` element either, you can use it on any element.
//!
//!
//! ## Attributes
//!
//! Anything between the name of an element and colon is expected to be an attribute.
//!
//!
//! ### Named Attributes
//!
//! A named attribute with a value looks like:
//!
//! ```doccy
//! {h1 @class main header: Header}
//! ```
//!
//! Renders as:
//!
//! ```html
//! <h1 class="main header">Header</h1>
//! ```
//!
//! Without a value:
//!
//! ```doccy
//! {input @required}
//! ```
//!
//! Renders as:
//!
//! ```html
//! <input required>
//! ```
//!
//! Values containing special characters must be escaped:
//!
//! ```doccy
//! {h1 @test Bad characters\: \@\#\%\.\{\}: ...}
//! ```
//!
//! Renders as:
//! ```html
//! <h1 test="Bad characters: @#%.{}">...</h1>
//! ```
//!
//! Unless they are part of a URL:
//!
//!
//! ```doccy
//! {a @href https://www.example.com: Example}
//! ```
//!
//! Renders as:
//! ```html
//! <a href="https://www.example.com">Example</h1>
//! ```
//!
//!
//! ### Data Attributes
//!
//! A shorthand for `data-` attributes:
//!
//! ```doccy
//! {pre %lang html: ...}
//! {pre %html: ...}
//! ```
//!
//! Renders as:
//!
//! ```html
//! <pre data-lang="html">...</pre>
//! <pre data-html>...</pre>
//! ```
//!
//! As with named attributes, special characters must be escaped.
//!
//!
//! ### Class Attributes
//!
//! A shorthand for `class="..."` attributes:
//!
//! ```doccy
//! {h1.main.header: Header}
//! ```
//!
//! Renders as:
//!
//! ```html
//! <h1 class="main header">Header</h1>
//! ```
//!
//!
//! ### Id Attributes
//!
//! A shorthand for `id="..."` attributes:
//!
//! ```doccy
//! {h1#main: Header}
//! ```
//!
//! Renders as:
//!
//! ```html
//! <h1 id="main">Header</h1>
//! ```
//!
//!
//! ## Paragraphs
//!
//! Any text contained within specific contexts will be treated as one or more paragraphs if separated by two or more line breaks and it contains only inline elements.
//!
//!
//! ### In the document body
//!
//! ```doccy
//! This is a paragraph.
//!
//! {h1: This is a header.}
//!
//! And this is another.
//! ```
//!
//! Renders as:
//!
//! ```html
//! <p>This is a paragraph.</p>
//! <h1>This is a header.</h1>
//! <p>And this is another.</p>
//! ```
//!
//!
//! #### In content elements
//!
//! The following elements also automatically wrap paragraphs: `article`, `aside`, `blockquote`, `div`, `fieldset`, `footer`, `form`, `header`, `hgroup`, `main` and `section`.
//!
//! ```doccy
//! {blockquote: This is a paragraph.
//!
//! And this is another.}
//! ```
//!
//! Renders as:
//!
//! ```html
//! <blockquote>
//! <p>This is a paragraph.</p>
//! <p>And this is another.</p>
//! </blockquote>
//! ```
//!
//!
//! # Examples
//! ## Parsing and rendering documents:
//!
//! ```
//! use doccy::doccy_to_html;
//!
//! match doccy_to_html("your document {em: here}") {
//! // <p>your document <em>here</em></p>
//! Ok(html) => println!("{}", html),
//! Err(error) => {}
//! };
//! ```
//!
//!
//! ## Using grammar and Renderer directly:
//!
//! ```
//! use doccy::grammar;
//! use doccy::render::Renderer;
//!
//! let mut renderer = Renderer::new();
//!
//! if let Ok(ast) = grammar::attributes("@href https\\://example\\.com") {
//! renderer.attributes(&ast);
//! }
//!
//! println!("{}", renderer.output); // href="https://example.com"
//! ```
extern crate lazy_static;
use Data;
use ;
use Renderer;