Skip to main content

Crate ironmark

Crate ironmark 

Source
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:

SyntaxHTML outputOption
~~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):

SyntaxHTML outputOption
[[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§

ast
ffi

Structs§

AnsiOptions
Display options for the ANSI terminal renderer.
HtmlParseOptions
Options for HTML-to-AST parsing.
ParseOptions
Options for customizing Markdown parsing and rendering behavior.

Enums§

UnknownInlineHandling
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 markdown and 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.