Crate cmark_hamlet

Source
Expand description

This library provides an adapter from pulldown-cmark events to hamlet tokens.

Note that block/inline html within markdown is not parsed into proper hamlet tokens.

§Example

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 eventAction
Start(tag)Context dependent; see Tag mapping
End(tag)Context dependent
Text(text)Context dependent; see Text handling
Html(html)Token::RawText(html)
InlineHtml(html)Token::RawText(html)
SoftBreak"\n" (see Text handling)
HardBreakToken representing <br />
FootnoteReference(_)unimplemented!

§Tag mapping

pulldown_cmark tagHtml tag name
BlockQuoteblockquote
CodeBlock(lang)pre and code (see CodeBlock handling)
Codecode
Emphasisem
FootnoteDefinition(_)unimplemented!
Header(level)h{level}
Image(_, _)img
Itemli
Link(_, _)a
List(None)ul
List(Some(_))ol
Paragraphp
Rulehr
Strongstrong
Table(_)table
TableCelltd or th
TableHeadtr
TableRowtr

§Text handling

All successive Text and SoftBreak events are clumped together to form a single hamlet::Text token, if group_text argument 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.

Structs§

Adapter
The adapter! An iterator that generates hamlet::Tokens.