Skip to content

Commit daa1714

Browse files
committed
Switch markdown renderer to hoedown
Fixes: #21
1 parent 1ceb872 commit daa1714

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ r2d2_postgres = "0.10.1"
3030
url = "1.1.1"
3131
params = "0.2.2"
3232
libc = "0.2"
33+
hoedown = "5.0"
3334

3435
[dependencies.badge]
3536
path = "src/web/badge"

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern crate iron;
1717
extern crate router;
1818
extern crate staticfile;
1919
extern crate handlebars_iron;
20-
extern crate pulldown_cmark;
20+
extern crate hoedown;
2121
extern crate r2d2;
2222
extern crate r2d2_postgres;
2323
extern crate url;

src/web/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,24 @@ fn match_version(conn: &Connection, name: &str, version: Option<&str>) -> Option
208208

209209
/// Wrapper around the pulldown-cmark parser and renderer to render markdown
210210
fn render_markdown(text: &str) -> String {
211-
// I got this from mdBook::src::utils
212-
use pulldown_cmark::{Parser, html, Options, OPTION_ENABLE_TABLES, OPTION_ENABLE_FOOTNOTES};
213-
let mut s = String::with_capacity(text.len() * 3 / 2);
211+
use hoedown::{Markdown, Html, Render, Extension};
212+
use hoedown::renderer::html;
214213

215-
let mut opts = Options::empty();
216-
opts.insert(OPTION_ENABLE_TABLES);
217-
opts.insert(OPTION_ENABLE_FOOTNOTES);
214+
let extensions = {
215+
use hoedown::{FENCED_CODE, FOOTNOTES, SUPERSCRIPT, TABLES};
218216

219-
let p = Parser::new_ext(&text, opts);
220-
html::push_html(&mut s, p);
221-
s
217+
let mut extensions = Extension::empty();
218+
extensions.insert(FENCED_CODE);
219+
extensions.insert(FOOTNOTES);
220+
extensions.insert(SUPERSCRIPT);
221+
extensions.insert(TABLES);
222+
223+
extensions
224+
};
225+
226+
let doc = Markdown::new(text).extensions(extensions);
227+
let mut html = Html::new(html::Flags::empty(), 0);
228+
html.render(&doc).to_str().unwrap().to_owned()
222229
}
223230

224231

0 commit comments

Comments
 (0)