|
@@ -82,21 +82,35 @@ fn fix_link(link: &str, context: &RenderContext) -> Result<String> { |
|
|
Ok(result) |
|
|
Ok(result) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn start_tag(temp_header: &mut TempHeader, tag: &Tag) -> bool { |
|
|
|
|
|
match tag { |
|
|
|
|
|
Tag::Emphasis => temp_header.add_html("<em>"), |
|
|
|
|
|
Tag::Strong => temp_header.add_html("<strong>"), |
|
|
|
|
|
Tag::Code => temp_header.add_html("<code>"), |
|
|
|
|
|
// Tag::Link is handled elsewhere |
|
|
|
|
|
_ => return false, |
|
|
|
|
|
} |
|
|
|
|
|
true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn end_tag(temp_header: &mut TempHeader, tag: &Tag) -> bool { |
|
|
|
|
|
match tag { |
|
|
|
|
|
Tag::Emphasis => temp_header.add_html("</em>"), |
|
|
|
|
|
Tag::Strong => temp_header.add_html("</strong>"), |
|
|
|
|
|
Tag::Code => temp_header.add_html("</code>"), |
|
|
|
|
|
Tag::Link(_, _) => temp_header.add_html("</a>"), |
|
|
|
|
|
_ => return false, |
|
|
|
|
|
} |
|
|
|
|
|
true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// returns true if event have been processed |
|
|
/// returns true if event have been processed |
|
|
fn push_to_temp_header(event: &Event, temp_header: &mut TempHeader) -> bool { |
|
|
fn push_to_temp_header(event: &Event, temp_header: &mut TempHeader) -> bool { |
|
|
match event { |
|
|
match event { |
|
|
Event::End(Tag::Link(_, _)) => { |
|
|
|
|
|
temp_header.add_html("</a>"); |
|
|
|
|
|
} |
|
|
|
|
|
Event::Start(Tag::Code) => { |
|
|
|
|
|
temp_header.add_html("<code>"); |
|
|
|
|
|
} |
|
|
|
|
|
Event::End(Tag::Code) => { |
|
|
|
|
|
temp_header.add_html("</code>"); |
|
|
|
|
|
} |
|
|
|
|
|
_ => return false, |
|
|
|
|
|
|
|
|
Event::Start(tag) => start_tag(temp_header, tag), |
|
|
|
|
|
Event::End(tag) => end_tag(temp_header, tag), |
|
|
|
|
|
_ => false, |
|
|
} |
|
|
} |
|
|
true |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Rendered> { |
|
|
pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Rendered> { |
|
@@ -126,7 +140,7 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
let parser = Parser::new_ext(content, opts).map(|event| { |
|
|
let parser = Parser::new_ext(content, opts).map(|event| { |
|
|
// Header first |
|
|
|
|
|
|
|
|
// Trivial markup generation |
|
|
if in_header && push_to_temp_header(&event, &mut temp_header) { |
|
|
if in_header && push_to_temp_header(&event, &mut temp_header) { |
|
|
return Event::Html(Borrowed("")); |
|
|
return Event::Html(Borrowed("")); |
|
|
} |
|
|
} |
|
|