Skip to main content

Crate rushdown_highlighting

Crate rushdown_highlighting 

Source
Expand description

§rushdown-highlighting

rushdown-highlighting is a server-side syntax highlighting plugin for rushdown, a markdown parser.

§Installation

Add dependency to your Cargo.toml:

[dependencies]
rushdown-highlighting = "x.y.z"

§Usage

§Example

use rushdown::{
    new_markdown_to_html,
    parser::{self, Parser, ParserExtension },
    renderer::html,
    text,
};
use rushdown_highlighting::{
    highlighting_html_renderer_extension, HighlightingHtmlRendererOptions, HighlightingMode,
};

let markdown_to_html = new_markdown_to_html(
    parser::Options::default(),
    html::Options::default(),
    parser::NO_EXTENSIONS,
    highlighting_html_renderer_extension(HighlightingHtmlRendererOptions {
        mode: HighlightingMode::Attribute,
        ..HighlightingHtmlRendererOptions::default()
    }),
);
let mut output = String::new();
let input = r#"
```rust
let a = 10;
```
"#;
match markdown_to_html(&mut output, input) {
    Ok(_) => {
        println!("HTML output:\n{}", output);
    }
    Err(e) => {
        println!("Error: {:?}", e);
    }
}

§Options

OptionTypeDefaultDescription
theme&strInspiredGitHubThe name of the syntax highlighting theme to use. This option is only applicable when mode is set to Attribute
modeHighlightingModeAttributeThe mode to use for syntax highlighting. Attribute mode adds a style attribute to the HTML elements, while Class mode adds a class attribute.
theme_setOption<Rc<ThemeSet>>NoneA custom set of syntax highlighting themes. If this option is not provided, the default themes from the syntect crate will be used.

§Donation

BTC: 1NEDSyUmo4SMTDP83JJQSWi1MvQUGGNMZB

Github sponsors also welcome.

§License

MIT

§Author

Yusuke Inuzuka

Structs§

HighlightingHtmlRendererOptions
Options for the HighlightingHtmlRenderer.

Enums§

HighlightingMode
The mode to use for syntax highlighting. This determines how the HTML output is structured.

Functions§

generate_css
Generates CSS for the specified theme. This is only necessary if the mode in HighlightingHtmlRendererOptions is set to HighlightingMode::Class.
highlighting_html_renderer_extension
Returns a renderer extension that adds support for rendering code blocks with syntax highlighting.