Expand description
§rushdown-fenced-div
rushdown-fenced-div is a small extension crate for rushdown
that adds Pandoc-style fenced div containers.
It parses fenced div blocks opened by ::: fences, supports admonition-style shorthand class or
attribute list, allows nested fenced divs, and provides a default HTML renderer that emits
<div> elements with the parsed attributes.
For the upstream syntax definition, see Pandoc’s Fenced Divs documentation.
§Installation
Add the crate to your Cargo.toml:
[dependencies]
rushdown = "0.12"
rushdown-fenced-div = "0.1"§Syntax
Shorthand class:
::: note
Inside the div.
:::Attached shorthand class:
:::note
Inside the div.
:::Attribute list:
::: {.note #tip data-kind="callout"}
Inside the div.
:::Trailing colons after the opener payload:
::: Warning ::::::
Inside the div.
:::Nested fenced divs:
:::: outer
::: inner
Nested content.
:::
::::§Usage
use rushdown::new_markdown_to_html;
use rushdown::parser;
use rushdown::renderer::html;
use rushdown_fenced_div::{
fenced_div_html_renderer_extension,
fenced_div_parser_extension,
FencedDivHtmlRendererOptions,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let markdown_to_html = new_markdown_to_html(
parser::Options::default(),
html::Options::default(),
fenced_div_parser_extension(),
fenced_div_html_renderer_extension(FencedDivHtmlRendererOptions::default()),
);
let input = r#"
::: {.note #tip data-kind="callout"} :::
inside
::::::::::::::::::::::::::::::::::::::::
"#;
let mut output = String::new();
markdown_to_html(&mut output, input)?;
assert_eq!(
output.trim(),
"<div class=\"note\" id=\"tip\" data-kind=\"callout\"><p>inside</p>\n</div>"
);
Ok(())
}§Notes
- Trailing colons after a valid opener payload are accepted.
§License
MIT
Structs§
- Fenced
Div - AST node for a fenced div container.
- Fenced
DivHtml Renderer Options
Functions§
- fenced_
div_ html_ renderer_ extension - Returns a renderer extension that renders fenced div blocks in HTML.
- fenced_
div_ parser_ extension - Returns a parser extension that parses fenced div blocks.