Struct comrak::RenderOptionsBuilder
source · pub struct RenderOptionsBuilder { /* private fields */ }
Expand description
Builder for RenderOptions
.
Implementations§
source§impl RenderOptionsBuilder
impl RenderOptionsBuilder
sourcepub fn hardbreaks(&mut self, value: bool) -> &mut Self
pub fn hardbreaks(&mut self, value: bool) -> &mut Self
Soft line breaks in the input translate into hard line breaks in the output.
let mut options = Options::default();
assert_eq!(markdown_to_html("Hello.\nWorld.\n", &options),
"<p>Hello.\nWorld.</p>\n");
options.render.hardbreaks = true;
assert_eq!(markdown_to_html("Hello.\nWorld.\n", &options),
"<p>Hello.<br />\nWorld.</p>\n");
sourcepub fn github_pre_lang(&mut self, value: bool) -> &mut Self
pub fn github_pre_lang(&mut self, value: bool) -> &mut Self
GitHub-style <pre lang="xyz">
is used for fenced code blocks with info tags.
let mut options = Options::default();
assert_eq!(markdown_to_html("``` rust\nfn hello();\n```\n", &options),
"<pre><code class=\"language-rust\">fn hello();\n</code></pre>\n");
options.render.github_pre_lang = true;
assert_eq!(markdown_to_html("``` rust\nfn hello();\n```\n", &options),
"<pre lang=\"rust\"><code>fn hello();\n</code></pre>\n");
sourcepub fn full_info_string(&mut self, value: bool) -> &mut Self
pub fn full_info_string(&mut self, value: bool) -> &mut Self
Enable full info strings for code blocks
let mut options = Options::default();
assert_eq!(markdown_to_html("``` rust extra info\nfn hello();\n```\n", &options),
"<pre><code class=\"language-rust\">fn hello();\n</code></pre>\n");
options.render.full_info_string = true;
let html = markdown_to_html("``` rust extra info\nfn hello();\n```\n", &options);
let re = regex::Regex::new(r#"data-meta="extra info""#).unwrap();
assert!(re.is_match(&html));
sourcepub fn width(&mut self, value: usize) -> &mut Self
pub fn width(&mut self, value: usize) -> &mut Self
The wrap column when outputting CommonMark.
let mut options = Options::default();
let node = parse_document(&arena, "hello hello hello hello hello hello", &options);
let mut output = vec![];
format_commonmark(node, &options, &mut output).unwrap();
assert_eq!(String::from_utf8(output).unwrap(),
"hello hello hello hello hello hello\n");
options.render.width = 20;
let mut output = vec![];
format_commonmark(node, &options, &mut output).unwrap();
assert_eq!(String::from_utf8(output).unwrap(),
"hello hello hello\nhello hello hello\n");
sourcepub fn unsafe_(&mut self, value: bool) -> &mut Self
pub fn unsafe_(&mut self, value: bool) -> &mut Self
Allow rendering of raw HTML and potentially dangerous links.
let mut options = Options::default();
let input = "<script>\nalert('xyz');\n</script>\n\n\
Possibly <marquee>annoying</marquee>.\n\n\
[Dangerous](javascript:alert(document.cookie)).\n\n\
[Safe](http://commonmark.org).\n";
assert_eq!(markdown_to_html(input, &options),
"<!-- raw HTML omitted -->\n\
<p>Possibly <!-- raw HTML omitted -->annoying<!-- raw HTML omitted -->.</p>\n\
<p><a href=\"\">Dangerous</a>.</p>\n\
<p><a href=\"http://commonmark.org\">Safe</a>.</p>\n");
options.render.unsafe_ = true;
assert_eq!(markdown_to_html(input, &options),
"<script>\nalert(\'xyz\');\n</script>\n\
<p>Possibly <marquee>annoying</marquee>.</p>\n\
<p><a href=\"javascript:alert(document.cookie)\">Dangerous</a>.</p>\n\
<p><a href=\"http://commonmark.org\">Safe</a>.</p>\n");
sourcepub fn escape(&mut self, value: bool) -> &mut Self
pub fn escape(&mut self, value: bool) -> &mut Self
Escape raw HTML instead of clobbering it.
let mut options = Options::default();
let input = "<i>italic text</i>";
assert_eq!(markdown_to_html(input, &options),
"<p><!-- raw HTML omitted -->italic text<!-- raw HTML omitted --></p>\n");
options.render.escape = true;
assert_eq!(markdown_to_html(input, &options),
"<p><i>italic text</i></p>\n");
sourcepub fn list_style(&mut self, value: ListStyleType) -> &mut Self
pub fn list_style(&mut self, value: ListStyleType) -> &mut Self
Set the type of bullet list marker to use. Options are:
ListStyleType::Dash
to use-
(default)ListStyleType::Plus
to use+
ListStyleType::Star
to use*
let mut options = Options::default();
let input = "- one\n- two\n- three";
assert_eq!(markdown_to_commonmark(input, &options),
"- one\n- two\n- three\n"); // default is Dash
options.render.list_style = ListStyleType::Plus;
assert_eq!(markdown_to_commonmark(input, &options),
"+ one\n+ two\n+ three\n");
options.render.list_style = ListStyleType::Star;
assert_eq!(markdown_to_commonmark(input, &options),
"* one\n* two\n* three\n");
sourcepub fn sourcepos(&mut self, value: bool) -> &mut Self
pub fn sourcepos(&mut self, value: bool) -> &mut Self
Include source position attributes in HTML and XML output.
Sourcepos information is reliable for all core block items, and most extensions. The description lists extension still has issues; see https://github.com/kivikakk/comrak/blob/3bb6d4ce/src/tests/description_lists.rs#L60-L125.
Sourcepos information is not reliable for inlines, and is not
included in HTML without also setting [experimental_inline_sourcepos
].
See https://github.com/kivikakk/comrak/pull/439 for a discussion.
let mut options = Options::default();
options.render.sourcepos = true;
let input = "## Hello world!";
let xml = markdown_to_commonmark_xml(input, &options);
assert!(xml.contains("<text sourcepos=\"1:4-1:15\" xml:space=\"preserve\">"));
sourcepub fn experimental_inline_sourcepos(&mut self, value: bool) -> &mut Self
pub fn experimental_inline_sourcepos(&mut self, value: bool) -> &mut Self
Include inline sourcepos in HTML output, which is known to have issues. See https://github.com/kivikakk/comrak/pull/439 for a discussion.
let mut options = Options::default();
options.render.sourcepos = true;
let input = "Hello *world*!";
assert_eq!(markdown_to_html(input, &options),
"<p data-sourcepos=\"1:1-1:14\">Hello <em>world</em>!</p>\n");
options.render.experimental_inline_sourcepos = true;
assert_eq!(markdown_to_html(input, &options),
"<p data-sourcepos=\"1:1-1:14\">Hello <em data-sourcepos=\"1:7-1:13\">world</em>!</p>\n");
sourcepub fn escaped_char_spans(&mut self, value: bool) -> &mut Self
pub fn escaped_char_spans(&mut self, value: bool) -> &mut Self
Wrap escaped characters in a <span>
to allow any
post-processing to recognize them.
let mut options = Options::default();
let input = "Notify user \\@example";
assert_eq!(markdown_to_html(input, &options),
"<p>Notify user @example</p>\n");
options.render.escaped_char_spans = true;
assert_eq!(markdown_to_html(input, &options),
"<p>Notify user <span data-escaped-char>@</span>example</p>\n");
sourcepub fn ignore_setext(&mut self, value: bool) -> &mut Self
pub fn ignore_setext(&mut self, value: bool) -> &mut Self
Ignore setext headings in input.
let mut options = Options::default();
let input = "setext heading\n---";
assert_eq!(markdown_to_html(input, &options),
"<h2>setext heading</h2>\n");
options.render.ignore_setext = true;
assert_eq!(markdown_to_html(input, &options),
"<p>setext heading</p>\n<hr />\n");
sourcepub fn ignore_empty_links(&mut self, value: bool) -> &mut Self
pub fn ignore_empty_links(&mut self, value: bool) -> &mut Self
Ignore empty links in input.
let mut options = Options::default();
let input = "[]()";
assert_eq!(markdown_to_html(input, &options),
"<p><a href=\"\"></a></p>\n");
options.render.ignore_empty_links = true;
assert_eq!(markdown_to_html(input, &options), "<p>[]()</p>\n");
sourcepub fn gfm_quirks(&mut self, value: bool) -> &mut Self
pub fn gfm_quirks(&mut self, value: bool) -> &mut Self
Enables GFM quirks in HTML output which break CommonMark compatibility.
let mut options = Options::default();
let input = "****abcd**** *_foo_*";
assert_eq!(markdown_to_html(input, &options),
"<p><strong><strong>abcd</strong></strong> <em><em>foo</em></em></p>\n");
options.render.gfm_quirks = true;
assert_eq!(markdown_to_html(input, &options),
"<p><strong>abcd</strong> <em><em>foo</em></em></p>\n");
sourcepub fn prefer_fenced(&mut self, value: bool) -> &mut Self
pub fn prefer_fenced(&mut self, value: bool) -> &mut Self
Prefer fenced code blocks when outputting CommonMark.
let arena = Arena::new();
let mut options = Options::default();
let input = "```\nhello\n```\n";
let root = parse_document(&arena, input, &options);
let mut buf = Vec::new();
format_commonmark(&root, &options, &mut buf);
assert_eq!(str::from_utf8(&buf).unwrap(), " hello\n");
buf.clear();
options.render.prefer_fenced = true;
format_commonmark(&root, &options, &mut buf);
assert_eq!(str::from_utf8(&buf).unwrap(), "```\nhello\n```\n");
Render the image as a figure element with the title as its caption.
let mut options = Options::default();
let input = "![image](https://example.com/image.png \"this is an image\")";
assert_eq!(markdown_to_html(input, &options),
"<p><img src=\"https://example.com/image.png\" alt=\"image\" title=\"this is an image\" /></p>\n");
options.render.figure_with_caption = true;
assert_eq!(markdown_to_html(input, &options),
"<p><figure><img src=\"https://example.com/image.png\" alt=\"image\" title=\"this is an image\" /><figcaption>this is an image</figcaption></figure></p>\n");
sourcepub fn build(&self) -> Result<RenderOptions, RenderOptionsBuilderError>
pub fn build(&self) -> Result<RenderOptions, RenderOptionsBuilderError>
Trait Implementations§
source§impl Clone for RenderOptionsBuilder
impl Clone for RenderOptionsBuilder
source§fn clone(&self) -> RenderOptionsBuilder
fn clone(&self) -> RenderOptionsBuilder
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for RenderOptionsBuilder
impl RefUnwindSafe for RenderOptionsBuilder
impl Send for RenderOptionsBuilder
impl Sync for RenderOptionsBuilder
impl Unpin for RenderOptionsBuilder
impl UnwindSafe for RenderOptionsBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)