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]
name = "cheddar"
version = "0.1.0"
version = "0.2.0"
authors = ["Vincent Ambo <mail@tazj.in>"]
edition = "2018"
[dependencies]
clap = "2.33"
comrak = "0.7"
comrak = "0.10"
lazy_static = "1.4"
rouille = "3.0"
syntect = "4.2.0"
syntect = "4.5.0"
serde_json = "1.0"
[dependencies.serde]

View file

@ -37,17 +37,23 @@ lazy_static! {
// Configure Comrak's Markdown rendering with all the bells &
// whistles!
static ref MD_OPTS: ComrakOptions = 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,
unsafe_: true, // required for tagfilter
..ComrakOptions::default()
static ref MD_OPTS: ComrakOptions = {
let mut options = ComrakOptions::default();
// Enable non-standard Markdown features:
options.extension.strikethrough = true;
options.extension.tagfilter = true;
options.extension.table = true;
options.extension.autolink = true;
options.extension.tasklist = true;
options.extension.header_ids = Some(String::new()); // yyeeesss!
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
@ -125,10 +131,8 @@ fn highlight_code_block(code_block: &NodeCodeBlock) -> NodeValue {
buf
};
let block = NodeHtmlBlock {
block_type: 1, // It's unclear what behaviour is toggled by this
literal: rendered.into_bytes(),
};
let mut block = NodeHtmlBlock::default();
block.literal = rendered.into_bytes();
NodeValue::HtmlBlock(block)
}
@ -173,10 +177,9 @@ fn format_callout_paragraph(callout: Callout) -> NodeValue {
Callout::Tip => "cheddar-tip",
};
NodeValue::HtmlBlock(NodeHtmlBlock {
block_type: 1,
literal: format!("<p class=\"cheddar-callout {}\">", class).into_bytes(),
})
let mut block = NodeHtmlBlock::default();
block.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) {
@ -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
// in case that callouts are encountered (otherwise insertion into the tree
// is not possible).
let p_close = Node::new(RefCell::new(Ast {
start_line: 0, // TODO(tazjin): hrmm
content: vec![],
open: false,
last_line_blank: false,
value: NodeValue::HtmlBlock(NodeHtmlBlock {
block_type: 1,
literal: b"</p>".to_vec(),
}),
}));
let mut p_close_value = NodeHtmlBlock::default();
p_close_value.literal = b"</p>".to_vec();
// Syntax highlighting is implemented by traversing the arena and
// replacing all code blocks with HTML blocks rendered by syntect.
let p_close_node = Ast::new(NodeValue::HtmlBlock(p_close_value));
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| {
let mut ast = node.data.borrow_mut();
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::Paragraph => {
if let Some(callout) = has_callout(node) {
node.insert_after(&p_close);