pub struct RenderOptionsBuilder<S: State = Empty> { /* private fields */ }
Expand description
Use builder syntax to set the inputs and finish with build()
.
Implementations§
Source§impl<S: State> RenderOptionsBuilder<S>
impl<S: State> RenderOptionsBuilder<S>
Sourcepub fn build(self) -> RenderOptionswhere
S: IsComplete,
pub fn build(self) -> RenderOptionswhere
S: IsComplete,
Finish building and return the requested object
Sourcepub fn hardbreaks(self, value: bool) -> RenderOptionsBuilder<SetHardbreaks<S>>where
S::Hardbreaks: IsUnset,
pub fn hardbreaks(self, value: bool) -> RenderOptionsBuilder<SetHardbreaks<S>>where
S::Hardbreaks: IsUnset,
Optional (Some / Option setters). Default: false
.
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 maybe_hardbreaks(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetHardbreaks<S>>where
S::Hardbreaks: IsUnset,
pub fn maybe_hardbreaks(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetHardbreaks<S>>where
S::Hardbreaks: IsUnset,
Optional (Some / Option setters). Default: false
.
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(
self,
value: bool,
) -> RenderOptionsBuilder<SetGithubPreLang<S>>where
S::GithubPreLang: IsUnset,
pub fn github_pre_lang(
self,
value: bool,
) -> RenderOptionsBuilder<SetGithubPreLang<S>>where
S::GithubPreLang: IsUnset,
Optional (Some / Option setters). Default: false
.
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 maybe_github_pre_lang(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetGithubPreLang<S>>where
S::GithubPreLang: IsUnset,
pub fn maybe_github_pre_lang(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetGithubPreLang<S>>where
S::GithubPreLang: IsUnset,
Optional (Some / Option setters). Default: false
.
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(
self,
value: bool,
) -> RenderOptionsBuilder<SetFullInfoString<S>>where
S::FullInfoString: IsUnset,
pub fn full_info_string(
self,
value: bool,
) -> RenderOptionsBuilder<SetFullInfoString<S>>where
S::FullInfoString: IsUnset,
Optional (Some / Option setters). Default: false
.
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 maybe_full_info_string(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetFullInfoString<S>>where
S::FullInfoString: IsUnset,
pub fn maybe_full_info_string(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetFullInfoString<S>>where
S::FullInfoString: IsUnset,
Optional (Some / Option setters). Default: false
.
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(self, value: usize) -> RenderOptionsBuilder<SetWidth<S>>where
S::Width: IsUnset,
pub fn width(self, value: usize) -> RenderOptionsBuilder<SetWidth<S>>where
S::Width: IsUnset,
Optional (Some / Option setters). Default: 0
.
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 maybe_width(
self,
value: Option<usize>,
) -> RenderOptionsBuilder<SetWidth<S>>where
S::Width: IsUnset,
pub fn maybe_width(
self,
value: Option<usize>,
) -> RenderOptionsBuilder<SetWidth<S>>where
S::Width: IsUnset,
Optional (Some / Option setters). Default: 0
.
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_(self, value: bool) -> RenderOptionsBuilder<SetUnsafe<S>>where
S::Unsafe: IsUnset,
pub fn unsafe_(self, value: bool) -> RenderOptionsBuilder<SetUnsafe<S>>where
S::Unsafe: IsUnset,
Optional (Some / Option setters). Default: false
.
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 maybe_unsafe_(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetUnsafe<S>>where
S::Unsafe: IsUnset,
pub fn maybe_unsafe_(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetUnsafe<S>>where
S::Unsafe: IsUnset,
Optional (Some / Option setters). Default: false
.
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(self, value: bool) -> RenderOptionsBuilder<SetEscape<S>>where
S::Escape: IsUnset,
pub fn escape(self, value: bool) -> RenderOptionsBuilder<SetEscape<S>>where
S::Escape: IsUnset,
Optional (Some / Option setters). Default: false
.
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 maybe_escape(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetEscape<S>>where
S::Escape: IsUnset,
pub fn maybe_escape(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetEscape<S>>where
S::Escape: IsUnset,
Optional (Some / Option setters). Default: false
.
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(
self,
value: ListStyleType,
) -> RenderOptionsBuilder<SetListStyle<S>>where
S::ListStyle: IsUnset,
pub fn list_style(
self,
value: ListStyleType,
) -> RenderOptionsBuilder<SetListStyle<S>>where
S::ListStyle: IsUnset,
Optional (Some / Option setters). Default: <ListStyleType as Default>::default()
.
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 maybe_list_style(
self,
value: Option<ListStyleType>,
) -> RenderOptionsBuilder<SetListStyle<S>>where
S::ListStyle: IsUnset,
pub fn maybe_list_style(
self,
value: Option<ListStyleType>,
) -> RenderOptionsBuilder<SetListStyle<S>>where
S::ListStyle: IsUnset,
Optional (Some / Option setters). Default: <ListStyleType as Default>::default()
.
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(self, value: bool) -> RenderOptionsBuilder<SetSourcepos<S>>where
S::Sourcepos: IsUnset,
pub fn sourcepos(self, value: bool) -> RenderOptionsBuilder<SetSourcepos<S>>where
S::Sourcepos: IsUnset,
Optional (Some / Option setters). Default: false
.
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 maybe_sourcepos(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetSourcepos<S>>where
S::Sourcepos: IsUnset,
pub fn maybe_sourcepos(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetSourcepos<S>>where
S::Sourcepos: IsUnset,
Optional (Some / Option setters). Default: false
.
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(
self,
value: bool,
) -> RenderOptionsBuilder<SetExperimentalInlineSourcepos<S>>where
S::ExperimentalInlineSourcepos: IsUnset,
pub fn experimental_inline_sourcepos(
self,
value: bool,
) -> RenderOptionsBuilder<SetExperimentalInlineSourcepos<S>>where
S::ExperimentalInlineSourcepos: IsUnset,
Optional (Some / Option setters). Default: false
.
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 maybe_experimental_inline_sourcepos(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetExperimentalInlineSourcepos<S>>where
S::ExperimentalInlineSourcepos: IsUnset,
pub fn maybe_experimental_inline_sourcepos(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetExperimentalInlineSourcepos<S>>where
S::ExperimentalInlineSourcepos: IsUnset,
Optional (Some / Option setters). Default: false
.
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(
self,
value: bool,
) -> RenderOptionsBuilder<SetEscapedCharSpans<S>>where
S::EscapedCharSpans: IsUnset,
pub fn escaped_char_spans(
self,
value: bool,
) -> RenderOptionsBuilder<SetEscapedCharSpans<S>>where
S::EscapedCharSpans: IsUnset,
Optional (Some / Option setters). Default: false
.
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 maybe_escaped_char_spans(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetEscapedCharSpans<S>>where
S::EscapedCharSpans: IsUnset,
pub fn maybe_escaped_char_spans(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetEscapedCharSpans<S>>where
S::EscapedCharSpans: IsUnset,
Optional (Some / Option setters). Default: false
.
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(
self,
value: bool,
) -> RenderOptionsBuilder<SetIgnoreSetext<S>>where
S::IgnoreSetext: IsUnset,
pub fn ignore_setext(
self,
value: bool,
) -> RenderOptionsBuilder<SetIgnoreSetext<S>>where
S::IgnoreSetext: IsUnset,
Optional (Some / Option setters). Default: false
.
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 maybe_ignore_setext(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetIgnoreSetext<S>>where
S::IgnoreSetext: IsUnset,
pub fn maybe_ignore_setext(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetIgnoreSetext<S>>where
S::IgnoreSetext: IsUnset,
Optional (Some / Option setters). Default: false
.
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(
self,
value: bool,
) -> RenderOptionsBuilder<SetIgnoreEmptyLinks<S>>where
S::IgnoreEmptyLinks: IsUnset,
pub fn ignore_empty_links(
self,
value: bool,
) -> RenderOptionsBuilder<SetIgnoreEmptyLinks<S>>where
S::IgnoreEmptyLinks: IsUnset,
Optional (Some / Option setters). Default: false
.
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 maybe_ignore_empty_links(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetIgnoreEmptyLinks<S>>where
S::IgnoreEmptyLinks: IsUnset,
pub fn maybe_ignore_empty_links(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetIgnoreEmptyLinks<S>>where
S::IgnoreEmptyLinks: IsUnset,
Optional (Some / Option setters). Default: false
.
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(self, value: bool) -> RenderOptionsBuilder<SetGfmQuirks<S>>where
S::GfmQuirks: IsUnset,
pub fn gfm_quirks(self, value: bool) -> RenderOptionsBuilder<SetGfmQuirks<S>>where
S::GfmQuirks: IsUnset,
Optional (Some / Option setters). Default: false
.
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 maybe_gfm_quirks(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetGfmQuirks<S>>where
S::GfmQuirks: IsUnset,
pub fn maybe_gfm_quirks(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetGfmQuirks<S>>where
S::GfmQuirks: IsUnset,
Optional (Some / Option setters). Default: false
.
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(
self,
value: bool,
) -> RenderOptionsBuilder<SetPreferFenced<S>>where
S::PreferFenced: IsUnset,
pub fn prefer_fenced(
self,
value: bool,
) -> RenderOptionsBuilder<SetPreferFenced<S>>where
S::PreferFenced: IsUnset,
Optional (Some / Option setters). Default: false
.
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");
Sourcepub fn maybe_prefer_fenced(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetPreferFenced<S>>where
S::PreferFenced: IsUnset,
pub fn maybe_prefer_fenced(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetPreferFenced<S>>where
S::PreferFenced: IsUnset,
Optional (Some / Option setters). Default: false
.
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");
Optional (Some / Option setters). Default: false
.
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");
Optional (Some / Option setters). Default: false
.
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 tasklist_classes(
self,
value: bool,
) -> RenderOptionsBuilder<SetTasklistClasses<S>>where
S::TasklistClasses: IsUnset,
pub fn tasklist_classes(
self,
value: bool,
) -> RenderOptionsBuilder<SetTasklistClasses<S>>where
S::TasklistClasses: IsUnset,
Optional (Some / Option setters). Default: false
.
Add classes to the output of the tasklist extension. This allows tasklists to be styled.
let mut options = Options::default();
options.extension.tasklist = true;
let input = "- [ ] Foo";
assert_eq!(markdown_to_html(input, &options),
"<ul>\n<li><input type=\"checkbox\" disabled=\"\" /> Foo</li>\n</ul>\n");
options.render.tasklist_classes = true;
assert_eq!(markdown_to_html(input, &options),
"<ul class=\"contains-task-list\">\n<li class=\"task-list-item\"><input type=\"checkbox\" class=\"task-list-item-checkbox\" disabled=\"\" /> Foo</li>\n</ul>\n");
Sourcepub fn maybe_tasklist_classes(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetTasklistClasses<S>>where
S::TasklistClasses: IsUnset,
pub fn maybe_tasklist_classes(
self,
value: Option<bool>,
) -> RenderOptionsBuilder<SetTasklistClasses<S>>where
S::TasklistClasses: IsUnset,
Optional (Some / Option setters). Default: false
.
Add classes to the output of the tasklist extension. This allows tasklists to be styled.
let mut options = Options::default();
options.extension.tasklist = true;
let input = "- [ ] Foo";
assert_eq!(markdown_to_html(input, &options),
"<ul>\n<li><input type=\"checkbox\" disabled=\"\" /> Foo</li>\n</ul>\n");
options.render.tasklist_classes = true;
assert_eq!(markdown_to_html(input, &options),
"<ul class=\"contains-task-list\">\n<li class=\"task-list-item\"><input type=\"checkbox\" class=\"task-list-item-checkbox\" disabled=\"\" /> Foo</li>\n</ul>\n");
Sourcepub fn ol_width(self, value: usize) -> RenderOptionsBuilder<SetOlWidth<S>>where
S::OlWidth: IsUnset,
pub fn ol_width(self, value: usize) -> RenderOptionsBuilder<SetOlWidth<S>>where
S::OlWidth: IsUnset,
Optional (Some / Option setters). Default: 0
.
Render ordered list with a minimum marker width. Having a width lower than 3 doesn’t do anything.
let mut options = Options::default();
let input = "1. Something";
assert_eq!(markdown_to_commonmark(input, &options),
"1. Something\n");
options.render.ol_width = 5;
assert_eq!(markdown_to_commonmark(input, &options),
"1. Something\n");
Sourcepub fn maybe_ol_width(
self,
value: Option<usize>,
) -> RenderOptionsBuilder<SetOlWidth<S>>where
S::OlWidth: IsUnset,
pub fn maybe_ol_width(
self,
value: Option<usize>,
) -> RenderOptionsBuilder<SetOlWidth<S>>where
S::OlWidth: IsUnset,
Optional (Some / Option setters). Default: 0
.
Render ordered list with a minimum marker width. Having a width lower than 3 doesn’t do anything.
let mut options = Options::default();
let input = "1. Something";
assert_eq!(markdown_to_commonmark(input, &options),
"1. Something\n");
options.render.ol_width = 5;
assert_eq!(markdown_to_commonmark(input, &options),
"1. Something\n");