about summary refs log tree commit diff
path: root/tools/cheddar/src
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-12-21T14·45+0000
committerVincent Ambo <tazjin@google.com>2019-12-21T14·49+0000
commitd6c255a35da53c910444a3df5703da597e9c7e4f (patch)
treec37e1c90e04b19c6e0ba1e65889dfc87be05dd48 /tools/cheddar/src
parentd35aa4ae46083e1655506749760fd87ff954c205 (diff)
feat(cheddar): Render Markdown via Comrak r/282
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.
Diffstat (limited to 'tools/cheddar/src')
-rw-r--r--tools/cheddar/src/main.rs33
1 files changed, 24 insertions, 9 deletions
diff --git a/tools/cheddar/src/main.rs b/tools/cheddar/src/main.rs
index 76bf834cb806..7affc3bc9cf8 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<usize>) -> 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);