chore(cheddar): Bump crate dependencies

This required some minor Comrak-related refactoring.

Change-Id: I5c5898eb895bd5d8743949458ee9406087fcff22
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2690
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
Reviewed-by: lukegb <lukegb@tvl.fyi>
Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
Vincent Ambo 2021-03-27 17:48:17 +02:00 committed by tazjin
parent c710509078
commit ca578c04ec
3 changed files with 553 additions and 515 deletions

999
tools/cheddar/Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,15 +1,15 @@
[package] [package]
name = "cheddar" name = "cheddar"
version = "0.1.0" version = "0.2.0"
authors = ["Vincent Ambo <mail@tazj.in>"] authors = ["Vincent Ambo <mail@tazj.in>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
clap = "2.33" clap = "2.33"
comrak = "0.7" comrak = "0.10"
lazy_static = "1.4" lazy_static = "1.4"
rouille = "3.0" rouille = "3.0"
syntect = "4.2.0" syntect = "4.5.0"
serde_json = "1.0" serde_json = "1.0"
[dependencies.serde] [dependencies.serde]

View file

@ -37,17 +37,23 @@ lazy_static! {
// Configure Comrak's Markdown rendering with all the bells & // Configure Comrak's Markdown rendering with all the bells &
// whistles! // whistles!
static ref MD_OPTS: ComrakOptions = ComrakOptions{ static ref MD_OPTS: ComrakOptions = {
ext_strikethrough: true, let mut options = ComrakOptions::default();
ext_tagfilter: true,
ext_table: true, // Enable non-standard Markdown features:
ext_autolink: true, options.extension.strikethrough = true;
ext_tasklist: true, options.extension.tagfilter = true;
ext_header_ids: Some(String::new()), // yyeeesss! options.extension.table = true;
ext_footnotes: true, options.extension.autolink = true;
ext_description_lists: true, options.extension.tasklist = true;
unsafe_: true, // required for tagfilter options.extension.header_ids = Some(String::new()); // yyeeesss!
..ComrakOptions::default() options.extension.footnotes = true;
options.extension.description_lists = true;
// Required for tagfilter
options.render.unsafe_ = true;
options
}; };
// Configures a map of specific filenames to languages, for cases // Configures a map of specific filenames to languages, for cases
@ -125,10 +131,8 @@ fn highlight_code_block(code_block: &NodeCodeBlock) -> NodeValue {
buf buf
}; };
let block = NodeHtmlBlock { let mut block = NodeHtmlBlock::default();
block_type: 1, // It's unclear what behaviour is toggled by this block.literal = rendered.into_bytes();
literal: rendered.into_bytes(),
};
NodeValue::HtmlBlock(block) NodeValue::HtmlBlock(block)
} }
@ -173,10 +177,9 @@ fn format_callout_paragraph(callout: Callout) -> NodeValue {
Callout::Tip => "cheddar-tip", Callout::Tip => "cheddar-tip",
}; };
NodeValue::HtmlBlock(NodeHtmlBlock { let mut block = NodeHtmlBlock::default();
block_type: 1, block.literal = format!("<p class=\"cheddar-callout {}\">", class).into_bytes();
literal: format!("<p class=\"cheddar-callout {}\">", class).into_bytes(), NodeValue::HtmlBlock(block)
})
} }
fn format_markdown<R: BufRead, W: Write>(reader: &mut R, writer: &mut W) { fn format_markdown<R: BufRead, W: Write>(reader: &mut R, writer: &mut W) {
@ -194,23 +197,21 @@ fn format_markdown<R: BufRead, W: Write>(reader: &mut R, writer: &mut W) {
// This node must exist with a lifetime greater than that of the parsed AST // This node must exist with a lifetime greater than that of the parsed AST
// in case that callouts are encountered (otherwise insertion into the tree // in case that callouts are encountered (otherwise insertion into the tree
// is not possible). // is not possible).
let p_close = Node::new(RefCell::new(Ast { let mut p_close_value = NodeHtmlBlock::default();
start_line: 0, // TODO(tazjin): hrmm p_close_value.literal = b"</p>".to_vec();
content: vec![],
open: false,
last_line_blank: false,
value: NodeValue::HtmlBlock(NodeHtmlBlock {
block_type: 1,
literal: b"</p>".to_vec(),
}),
}));
// Syntax highlighting is implemented by traversing the arena and let p_close_node = Ast::new(NodeValue::HtmlBlock(p_close_value));
// replacing all code blocks with HTML blocks rendered by syntect. let p_close = Node::new(RefCell::new(p_close_node));
// Special features of Cheddar are implemented by traversing the
// arena and reacting on nodes that we might want to modify.
iter_nodes(root, &|node| { iter_nodes(root, &|node| {
let mut ast = node.data.borrow_mut(); let mut ast = node.data.borrow_mut();
let new = match &ast.value { let new = match &ast.value {
// Syntax highlighting is implemented by replacing the
// code block node with literal HTML.
NodeValue::CodeBlock(code) => Some(highlight_code_block(code)), NodeValue::CodeBlock(code) => Some(highlight_code_block(code)),
NodeValue::Paragraph => { NodeValue::Paragraph => {
if let Some(callout) = has_callout(node) { if let Some(callout) = has_callout(node) {
node.insert_after(&p_close); node.insert_after(&p_close);