aboutsummaryrefslogtreecommitdiffstats
path: root/markdown-tool/src/main.rs
blob: f321c63b9d3d3af4c86ffec06e20ebde22aa387b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use std::io::BufRead;

use pulldown_cmark::{html, Options, Parser};

fn main() {
  let stdin = std::io::stdin();
  let mut markdown_input = format!("");
  for line in stdin.lock().lines() {
    markdown_input = format!("{markdown_input}{}\n", line.unwrap())
  }

  let mut options = Options::empty();
  options.insert(Options::ENABLE_STRIKETHROUGH);
  options.insert(Options::ENABLE_FOOTNOTES);
  options.insert(Options::ENABLE_TABLES);
  options.insert(Options::ENABLE_TASKLISTS);
  options.insert(Options::ENABLE_YAML_STYLE_METADATA_BLOCKS);
  options.insert(Options::ENABLE_GFM);
  let parser = Parser::new_ext(&markdown_input, options);
  let mut html_output: String = String::with_capacity(markdown_input.len() * 3 / 2);
  html::push_html(&mut html_output, parser);
  println!(
    "<style>@import url(\"/assets/md.css\")</style>
{html_output}"
  )
}