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
//! This library provides an adapter from [pulldown-cmark][] events to
//! [hamlet][] tokens.
//!
//! [pulldown-cmark]: https://github.com/google/pulldown-cmark
//! [hamlet]: https://github.com/Nemo157/hamlet
//!
//! Note that block/inline html within markdown is not parsed into proper hamlet
//! tokens.
//!
//! ## Example
//!
//! ```rust
//! extern crate pulldown_cmark;
//! extern crate cmark_hamlet;
//!
//! use std::fmt::Write;
//! use pulldown_cmark::Parser;
//! use cmark_hamlet::Adapter;
//!
//! fn main() {
//! let md = "Ok, [google][ref]\n\n- - -\n\n\
//! ```rust\n\
//! use hamlet;\n\
//! ```\n\n\
//! [ref]: http://google.com";
//! let ada = Adapter::new(Parser::new(md), false);
//! let mut res = String::from("");
//! for token in ada {
//! write!(res, "{}", token).unwrap();
//! }
//! assert_eq!("<p>Ok, <a href=\"http://google.com\">google</a></p><hr />\
//! <pre data-lang=\"rust\"><code>use hamlet;\n</code></pre>",
//! res);
//! }
//! ```
//!
//! ## Translation
//!
//! ### Event mapping
//!
//! `pulldown_cmark` event | Action
//! ---------------------- | ------
//! `Start(tag)` | Context dependent; see [Tag mapping](#tag-mapping)
//! `End(tag)` | Context dependent
//! `Text(text)` | Context dependent; see [Text handling](#text-handling)
//! `Html(html)` | `Token::RawText(html)`
//! `InlineHtml(html)` | `Token::RawText(html)`
//! `SoftBreak` | `"\n"` (see [Text handling](#text-handling))
//! `HardBreak` | `Token` representing `<br />`
//! `FootnoteReference(_)` | unimplemented!
//!
//! ### Tag mapping
//!
//! `pulldown_cmark` tag | Html tag name
//! ----------------------- | -------------
//! `BlockQuote` | `blockquote`
//! `CodeBlock(lang)` | `pre` and `code` (see [`CodeBlock` handling](#codeblock-handling))
//! `Code` | `code`
//! `Emphasis` | `em`
//! `FootnoteDefinition(_)` | unimplemented!
//! `Header(level)` | `h{level}`
//! `Image(_, _)` | `img`
//! `Item` | `li`
//! `Link(_, _)` | `a`
//! `List(None)` | `ul`
//! `List(Some(_))` | `ol`
//! `Paragraph` | `p`
//! `Rule` | `hr`
//! `Strong` | `strong`
//! `Table(_)` | `table`
//! `TableCell` | `td` or `th`
//! `TableHead` | `tr`
//! `TableRow` | `tr`
//!
//! ### Text handling
//!
//! All successive `Text` and `SoftBreak` events are clumped together to form a
//! single `hamlet::Text` token, if [`group_text`
//! argument](struct.Adapter.html#method.new) provided was `true`.
//!
//! ### `CodeBlock` handling
//!
//! If `lang` attribute is not empty, then a `data-lang` attribute is added to
//! the `pre` tag with that value.
extern crate pulldown_cmark as cmark;
extern crate hamlet;
pub use Adapter;