1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-12-23 23:41:24 +00:00

Reorganize makrdown rules, disable image embeds for now

This commit is contained in:
Felix Ableitner 2024-12-13 10:59:22 +01:00
parent ced6889635
commit 7e607c4dd7

View file

@ -2,10 +2,7 @@ use katex;
use markdown_it::{ use markdown_it::{
parser::inline::{InlineRule, InlineState}, parser::inline::{InlineRule, InlineState},
plugins::cmark::block::{heading::ATXHeading, lheading::SetextHeader}, plugins::cmark::block::{heading::ATXHeading, lheading::SetextHeader},
MarkdownIt, MarkdownIt, Node, NodeValue, Renderer,
Node,
NodeValue,
Renderer,
}; };
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
@ -28,17 +25,54 @@ pub fn render_markdown(text: &str) -> String {
fn markdown_parser() -> MarkdownIt { fn markdown_parser() -> MarkdownIt {
let mut parser = MarkdownIt::new(); let mut parser = MarkdownIt::new();
markdown_it::plugins::cmark::add(&mut parser); let p = &mut parser;
markdown_it_heading_anchors::add(&mut parser); {
markdown_it_footnote::add(&mut parser); // Markdown-it inline core features. Image is disabled to prevent embedding external
markdown_it::plugins::extra::strikethrough::add(&mut parser); // images. Later we need to add proper image support using pictrs.
markdown_it::plugins::extra::tables::add(&mut parser); use markdown_it::plugins::cmark::inline::*;
markdown_it::plugins::extra::typographer::add(&mut parser); newline::add(p);
markdown_it_block_spoiler::add(&mut parser); escape::add(p);
markdown_it_sub::add(&mut parser); backticks::add(p);
markdown_it_sup::add(&mut parser); emphasis::add(p);
link::add(p);
image::add(p);
autolink::add(p);
entity::add(p);
}
{
// Markdown-it block core features. Unchanged from defaults.
use markdown_it::plugins::cmark::block::*;
code::add(p);
fence::add(p);
blockquote::add(p);
hr::add(p);
list::add(p);
reference::add(p);
heading::add(p);
lheading::add(p);
paragraph::add(p);
}
{
// Some of the extras from markdown-it, others are intentionally excluded.
use markdown_it::plugins::extra::*;
strikethrough::add(p);
tables::add(p);
typographer::add(p);
}
// Extensions from various authors
markdown_it_heading_anchors::add(p);
markdown_it_block_spoiler::add(p);
markdown_it_footnote::add(p);
markdown_it_sub::add(p);
markdown_it_sup::add(p);
// Ibis custom extensions
parser.inline.add_rule::<ArticleLinkScanner>(); parser.inline.add_rule::<ArticleLinkScanner>();
parser.inline.add_rule::<MathEquationScanner>(); parser.inline.add_rule::<MathEquationScanner>();
parser parser
} }