Crate cmark_syntax[−][src]
Expand description
cmark syntax highlighting
This crate provides a preprocessor for pulldown_cmark events that implements syntax highlighting. It is based on the work of Maciej Hirsz for the Ramhorns templating engine.
Supported languages
- Rust
- JavaScript
- TOML
Files defining language syntax are located in src/languages directory.
The syntax is defined using regexes, which the Logos procedural
macro turns into a parser on compile time.
PRs implementing new languages are very welcome!
Features
With latex2mathml feature enabled, blocks denoted by math containing LaTeX formulas
are rendered into MathML in iniline mode
and analogously for blocks denoted by mathblock, in block mode.
Use
This preprocessor can be used as a callback for the Ramhorns templating engine.
use ramhorns::encoding::Encoder;
pub fn encode<E: Encoder>(source: &str, encoder: &mut E) -> Result<(), E::Error> {
let parser = pulldown_cmark::Parser::new(source);
let processed = cmark_syntax::SyntaxPreprocessor::new(parser);
encoder.write_html(processed)
}Modules
Definition of syntaxes of various languages.
Structs
A preprocessor that highlights syntax in pulldown_cmark events.
Enums
Possible kind of a token in the highlighted syntax.
Traits
A type of token that can be highlighted.
Functions
Highlight the code in source, placing the output into buf.
