Expand description
§ironmark
A fast, CommonMark 0.31.2 compliant Markdown-to-HTML parser with extensions.
§Usage
use ironmark::{render_html, ParseOptions};
// With defaults (all extensions enabled)
let html = render_html("# Hello, **world**!", &ParseOptions::default());
// Disable specific extensions
let opts = ParseOptions {
enable_strikethrough: false,
enable_tables: false,
..Default::default()
};
let html = render_html("Plain CommonMark only.", &opts);§Security
When rendering untrusted input, enable these options:
use ironmark::{render_html, ParseOptions};
let opts = ParseOptions {
disable_raw_html: true, // escape HTML blocks & inline HTML
max_input_size: 1_000_000, // limit input to 1 MB
..Default::default()
};
let html = render_html("<script>alert(1)</script>", &opts);
assert!(!html.contains("<script>"));Additionally, javascript:, vbscript:, and data: URIs (except data:image/…)
are always stripped from link and image destinations regardless of options.
§Extensions
Extensions enabled by default via ParseOptions:
| Syntax | HTML output | Option |
|---|---|---|
~~text~~ | <del> | enable_strikethrough |
==text== | <mark> | enable_highlight |
++text++ | <u> | enable_underline |
| table | | <table> | enable_tables |
- [x] task | <input type="checkbox"> | enable_task_lists |
| bare URLs / emails | <a> | enable_autolink |
| newlines | <br /> | hard_breaks |
Extensions disabled by default (opt-in):
| Syntax | HTML output | Option |
|---|---|---|
[[wiki]] | <a href="wiki"> | enable_wiki_links |
$math$ | <span class="math-inline"> | enable_latex_math |
$$math$$ | <span class="math-display"> | enable_latex_math |
# heading with id= | <h1 id="heading"> | enable_heading_ids |
# heading with anchor | <h1>… <a class="anchor"> | enable_heading_anchors |
#Heading (no space) | <h1> | permissive_atx_headers |
Re-exports§
pub use ast::Block;pub use ast::ListKind;pub use ast::TableAlignment;pub use ast::TableData;
Modules§
Structs§
- Ansi
Options - Display options for the ANSI terminal renderer.
- Html
Parse Options - Options for HTML-to-AST parsing.
- Parse
Options - Options for customizing Markdown parsing and rendering behavior.
Enums§
- Unknown
Inline Handling - How to handle HTML elements without Markdown equivalents.
Functions§
- html_
to_ markdown - Parse HTML and render directly to Markdown.
- parse_
html_ to_ ast - Parse an HTML string and return the block-level AST.
- parse_
markdown - Parse a Markdown string and return the block-level AST.
- render_
ansi_ terminal - Parse
markdownand render it as ANSI-coloured terminal output. - render_
html - Parse a Markdown string and return the rendered HTML.
- render_
markdown - Renders an AST back into a Markdown string.