From d6c255a35da53c910444a3df5703da597e9c7e4f Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 21 Dec 2019 14:45:11 +0000 Subject: feat(cheddar): Render Markdown via Comrak Renders any ".md" file by pushing it through the Comrak rendering pipeline. This does not yet implement syntax highlighting of fenced blocks, but we're getting there. --- tools/cheddar/src/main.rs | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/tools/cheddar/src/main.rs b/tools/cheddar/src/main.rs index 76bf834cb8..7affc3bc9c 100644 --- a/tools/cheddar/src/main.rs +++ b/tools/cheddar/src/main.rs @@ -1,13 +1,15 @@ +use comrak::{markdown_to_html, ComrakOptions}; +use lazy_static::lazy_static; use std::env; use std::ffi::OsStr; use std::io::BufRead; +use std::io::Read; use std::io; use std::path::Path; -use syntect::easy::HighlightLines; use syntect::dumps::from_binary; +use syntect::easy::HighlightLines; use syntect::highlighting::ThemeSet; use syntect::parsing::SyntaxSet; -use lazy_static::lazy_static; use syntect::html::{ append_highlighted_html_for_styled_line, @@ -43,7 +45,26 @@ fn should_continue(res: &io::Result) -> bool { } fn format_markdown() { - unimplemented!("Not able to format Markdown just yet"); + let mut buffer = String::new(); + let stdin = io::stdin(); + let mut stdin = stdin.lock(); + stdin.read_to_string(&mut buffer).expect("failed to read stdin"); + + // Markdown rendering is configurd with most of the bells & + // whistles here: + let opts = ComrakOptions{ + ext_strikethrough: true, + ext_tagfilter: true, + ext_table: true, + ext_autolink: true, + ext_tasklist: true, + ext_header_ids: Some(String::new()), // yyeeesss! + ext_footnotes: true, + ext_description_lists: true, + ..ComrakOptions::default() + }; + + print!("{}", markdown_to_html(&buffer, &opts)); } fn format_code(extension: String) { @@ -62,12 +83,6 @@ fn format_code(extension: String) { .or_else(|| SYNTAXES.find_syntax_by_first_line(&linebuf)) .unwrap_or_else(|| SYNTAXES.find_syntax_plain_text()); - // We're doing a completely different thing if the file is - // Markdown, so lets do that thing. - if syntax.name == "markdown" { - - } - let mut hl = HighlightLines::new(syntax, theme); let (mut outbuf, bg) = start_highlighted_html_snippet(theme); -- cgit 1.4.1