Expand description
Syntax highlighting for code blocks using syntect
This plugin will highlight indented code blocks and fenced code blocks.
Fenced block will read the first token as language, for example ```rust.
unknown language and indented code blocks will be rendered as plain text.
This plugin use InspiredGitHub theme and render inline styles by default.
Use set_theme to select another built-in syntect theme.
It will panic when get an unknown theme.
Use available_themes to view all available themes.
Use set_to_classed or set_to_classed_with_prefix to switch classed mode.
In this mode, you need to provide yourself styles.
You can also use theme_css get the CSS for selected built-in theme.
In inline mode, it will return None.
Fenced code blocks can mark highlighted lines with a {...} line spec in the info string,
such as ```rust {1, 3-5}.
Line number started with 1.
let mut md = markdown_it::MarkdownIt::new();
markdown_it::plugins::cmark::add(&mut md);
markdown_it::plugins::extra::syntect::add(&mut md);
markdown_it::plugins::extra::syntect::set_theme(&mut md, "base16-ocean.dark");
let html = md.parse("```rust\nfn main() {}\n```").render();
assert!(html.contains(r#"class="language-rust""#));Structs§
- Syntect
Rule - Replaces code blocks with syntect highlighted HTML.
- Syntect
Snippet - Rendered HTML produced by the syntect plugin.
Functions§
- add
- Add the syntect highlighting rule.
- available_
themes - Return the names of all built-in syntect themes available to this plugin.
- set_
prefix - Set the class prefix used for line highlighting and classed mode.
- set_
theme - Set the theme used for syntax highlighting.
- set_
to_ classed - switch to stylesheet-based highlighting mode with default
syntect-prefix. - set_
to_ classed_ with_ prefix - Switch to stylesheet-based highlighting with a custom class prefix.
- theme_
css - Generate CSS for selected built-in theme