about summary refs log tree commit diff
path: root/tools/cheddar/src/lib.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@tvl.su>2023-09-08T12·37+0300
committertazjin <tazjin@tvl.su>2023-09-08T13·51+0000
commit87d63e4a1bd604a0cda6102cad9c59bbce8f792e (patch)
tree24decd163ad67862d161d65d8c04340a9a509e7b /tools/cheddar/src/lib.rs
parent94ebb30b1f2e2ca7e70c8c5e0e1f2b60add3d5ce (diff)
feat(tools/cheddar): allow disabling tagfilter extension r/6564
Makes it possible to do things like embedding YouTube videos in blog
posts rendered through Cheddar.

Change-Id: I6aed943c7bec0167b9f009d36dd067c52c6d3083
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9275
Tested-by: BuildkiteCI
Reviewed-by: Mark Shevchenko <markshevchenko@gmail.com>
Diffstat (limited to 'tools/cheddar/src/lib.rs')
-rw-r--r--tools/cheddar/src/lib.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/tools/cheddar/src/lib.rs b/tools/cheddar/src/lib.rs
index c56789eca914..be8bc7f82fb1 100644
--- a/tools/cheddar/src/lib.rs
+++ b/tools/cheddar/src/lib.rs
@@ -233,6 +233,7 @@ fn format_callout_paragraph(callout: Callout) -> NodeValue {
 pub fn format_markdown_with_shortlinks<R: BufRead, W: Write>(
     reader: &mut R,
     writer: &mut W,
+    tagfilter: bool,
     shortlinks: &[Shortlink],
 ) {
     let document = {
@@ -244,7 +245,13 @@ pub fn format_markdown_with_shortlinks<R: BufRead, W: Write>(
     };
 
     let arena = Arena::new();
-    let root = parse_document(&arena, &linkify_shortlinks(document, shortlinks), &MD_OPTS);
+
+    let mut opts = MD_OPTS.clone();
+    if !tagfilter {
+        opts.extension.tagfilter = false;
+    }
+
+    let root = parse_document(&arena, &linkify_shortlinks(document, shortlinks), &opts);
 
     // 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
@@ -280,11 +287,11 @@ pub fn format_markdown_with_shortlinks<R: BufRead, W: Write>(
         }
     });
 
-    format_html(root, &MD_OPTS, writer).expect("Markdown rendering failed");
+    format_html(root, &opts, writer).expect("Markdown rendering failed");
 }
 
-pub fn format_markdown<R: BufRead, W: Write>(reader: &mut R, writer: &mut W) {
-    format_markdown_with_shortlinks(reader, writer, &TVL_LINKS)
+pub fn format_markdown<R: BufRead, W: Write>(reader: &mut R, writer: &mut W, tagfilter: bool) {
+    format_markdown_with_shortlinks(reader, writer, tagfilter, &TVL_LINKS)
 }
 
 fn find_syntax_for_file(filename: &str) -> &'static SyntaxReference {