pub struct ParseBuilder<'c, S: State = Empty> { /* private fields */ }Expand description
Use builder syntax to set the inputs and finish with build().
Implementations§
Source§impl<'c, S: State> ParseBuilder<'c, S>
impl<'c, S: State> ParseBuilder<'c, S>
Sourcepub fn build(self) -> Parse<'c>where
S: IsComplete,
pub fn build(self) -> Parse<'c>where
S: IsComplete,
Finish building and return the requested object
Sourcepub fn smart(self, value: bool) -> ParseBuilder<'c, SetSmart<S>>where
S::Smart: IsUnset,
pub fn smart(self, value: bool) -> ParseBuilder<'c, SetSmart<S>>where
S::Smart: IsUnset,
Optional (Some / Option setters). Default: false.
Punctuation (quotes, full-stops and hyphens) are converted into ‘smart’ punctuation.
let mut options = Options::default();
assert_eq!(markdown_to_html("'Hello,' \"world\" ...", &options),
"<p>'Hello,' "world" ...</p>\n");
options.parse.smart = true;
assert_eq!(markdown_to_html("'Hello,' \"world\" ...", &options),
"<p>‘Hello,’ “world” …</p>\n");Sourcepub fn maybe_smart(self, value: Option<bool>) -> ParseBuilder<'c, SetSmart<S>>where
S::Smart: IsUnset,
pub fn maybe_smart(self, value: Option<bool>) -> ParseBuilder<'c, SetSmart<S>>where
S::Smart: IsUnset,
Optional (Some / Option setters). Default: false.
Punctuation (quotes, full-stops and hyphens) are converted into ‘smart’ punctuation.
let mut options = Options::default();
assert_eq!(markdown_to_html("'Hello,' \"world\" ...", &options),
"<p>'Hello,' "world" ...</p>\n");
options.parse.smart = true;
assert_eq!(markdown_to_html("'Hello,' \"world\" ...", &options),
"<p>‘Hello,’ “world” …</p>\n");Sourcepub fn default_info_string(
self,
value: String,
) -> ParseBuilder<'c, SetDefaultInfoString<S>>where
S::DefaultInfoString: IsUnset,
pub fn default_info_string(
self,
value: String,
) -> ParseBuilder<'c, SetDefaultInfoString<S>>where
S::DefaultInfoString: IsUnset,
Optional (Some / Option setters).
The default info string for fenced code blocks.
let mut options = Options::default();
assert_eq!(markdown_to_html("```\nfn hello();\n```\n", &options),
"<pre><code>fn hello();\n</code></pre>\n");
options.parse.default_info_string = Some("rust".into());
assert_eq!(markdown_to_html("```\nfn hello();\n```\n", &options),
"<pre><code class=\"language-rust\">fn hello();\n</code></pre>\n");Sourcepub fn maybe_default_info_string(
self,
value: Option<String>,
) -> ParseBuilder<'c, SetDefaultInfoString<S>>where
S::DefaultInfoString: IsUnset,
pub fn maybe_default_info_string(
self,
value: Option<String>,
) -> ParseBuilder<'c, SetDefaultInfoString<S>>where
S::DefaultInfoString: IsUnset,
Optional (Some / Option setters).
The default info string for fenced code blocks.
let mut options = Options::default();
assert_eq!(markdown_to_html("```\nfn hello();\n```\n", &options),
"<pre><code>fn hello();\n</code></pre>\n");
options.parse.default_info_string = Some("rust".into());
assert_eq!(markdown_to_html("```\nfn hello();\n```\n", &options),
"<pre><code class=\"language-rust\">fn hello();\n</code></pre>\n");Sourcepub fn relaxed_tasklist_matching(
self,
value: bool,
) -> ParseBuilder<'c, SetRelaxedTasklistMatching<S>>where
S::RelaxedTasklistMatching: IsUnset,
pub fn relaxed_tasklist_matching(
self,
value: bool,
) -> ParseBuilder<'c, SetRelaxedTasklistMatching<S>>where
S::RelaxedTasklistMatching: IsUnset,
Sourcepub fn maybe_relaxed_tasklist_matching(
self,
value: Option<bool>,
) -> ParseBuilder<'c, SetRelaxedTasklistMatching<S>>where
S::RelaxedTasklistMatching: IsUnset,
pub fn maybe_relaxed_tasklist_matching(
self,
value: Option<bool>,
) -> ParseBuilder<'c, SetRelaxedTasklistMatching<S>>where
S::RelaxedTasklistMatching: IsUnset,
Sourcepub fn tasklist_in_table(
self,
value: bool,
) -> ParseBuilder<'c, SetTasklistInTable<S>>where
S::TasklistInTable: IsUnset,
pub fn tasklist_in_table(
self,
value: bool,
) -> ParseBuilder<'c, SetTasklistInTable<S>>where
S::TasklistInTable: IsUnset,
Optional (Some / Option setters). Default: false.
Whether tasklist items can be parsed in table cells. At present, the tasklist item must be the only content in the cell. Both tables and tasklists much be enabled for this to work.
let mut options = Options::default();
options.extension.table = true;
options.extension.tasklist = true;
assert_eq!(markdown_to_html("| val |\n| - |\n| [ ] |\n", &options),
"<table>\n<thead>\n<tr>\n<th>val</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>[ ]</td>\n</tr>\n</tbody>\n</table>\n");
options.parse.tasklist_in_table = true;
assert_eq!(markdown_to_html("| val |\n| - |\n| [ ] |\n", &options),
"<table>\n<thead>\n<tr>\n<th>val</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>\n<input type=\"checkbox\" disabled=\"\" /> </td>\n</tr>\n</tbody>\n</table>\n");Sourcepub fn maybe_tasklist_in_table(
self,
value: Option<bool>,
) -> ParseBuilder<'c, SetTasklistInTable<S>>where
S::TasklistInTable: IsUnset,
pub fn maybe_tasklist_in_table(
self,
value: Option<bool>,
) -> ParseBuilder<'c, SetTasklistInTable<S>>where
S::TasklistInTable: IsUnset,
Optional (Some / Option setters). Default: false.
Whether tasklist items can be parsed in table cells. At present, the tasklist item must be the only content in the cell. Both tables and tasklists much be enabled for this to work.
let mut options = Options::default();
options.extension.table = true;
options.extension.tasklist = true;
assert_eq!(markdown_to_html("| val |\n| - |\n| [ ] |\n", &options),
"<table>\n<thead>\n<tr>\n<th>val</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>[ ]</td>\n</tr>\n</tbody>\n</table>\n");
options.parse.tasklist_in_table = true;
assert_eq!(markdown_to_html("| val |\n| - |\n| [ ] |\n", &options),
"<table>\n<thead>\n<tr>\n<th>val</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>\n<input type=\"checkbox\" disabled=\"\" /> </td>\n</tr>\n</tbody>\n</table>\n");Sourcepub fn relaxed_autolinks(
self,
value: bool,
) -> ParseBuilder<'c, SetRelaxedAutolinks<S>>where
S::RelaxedAutolinks: IsUnset,
pub fn relaxed_autolinks(
self,
value: bool,
) -> ParseBuilder<'c, SetRelaxedAutolinks<S>>where
S::RelaxedAutolinks: IsUnset,
Optional (Some / Option setters). Default: false.
Relax parsing of autolinks, allow links to be detected inside brackets
and allow all url schemes. It is intended to allow a very specific type of autolink
detection, such as [this http://and.com that] or {http://foo.com}, on a best can basis.
let mut options = Options::default();
options.extension.autolink = true;
assert_eq!(markdown_to_html("[https://foo.com]", &options),
"<p>[https://foo.com]</p>\n");
options.parse.relaxed_autolinks = true;
assert_eq!(markdown_to_html("[https://foo.com]", &options),
"<p>[<a href=\"https://foo.com\">https://foo.com</a>]</p>\n");Sourcepub fn maybe_relaxed_autolinks(
self,
value: Option<bool>,
) -> ParseBuilder<'c, SetRelaxedAutolinks<S>>where
S::RelaxedAutolinks: IsUnset,
pub fn maybe_relaxed_autolinks(
self,
value: Option<bool>,
) -> ParseBuilder<'c, SetRelaxedAutolinks<S>>where
S::RelaxedAutolinks: IsUnset,
Optional (Some / Option setters). Default: false.
Relax parsing of autolinks, allow links to be detected inside brackets
and allow all url schemes. It is intended to allow a very specific type of autolink
detection, such as [this http://and.com that] or {http://foo.com}, on a best can basis.
let mut options = Options::default();
options.extension.autolink = true;
assert_eq!(markdown_to_html("[https://foo.com]", &options),
"<p>[https://foo.com]</p>\n");
options.parse.relaxed_autolinks = true;
assert_eq!(markdown_to_html("[https://foo.com]", &options),
"<p>[<a href=\"https://foo.com\">https://foo.com</a>]</p>\n");Sourcepub fn ignore_setext(self, value: bool) -> ParseBuilder<'c, SetIgnoreSetext<S>>where
S::IgnoreSetext: IsUnset,
pub fn ignore_setext(self, value: bool) -> ParseBuilder<'c, 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.parse.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>,
) -> ParseBuilder<'c, SetIgnoreSetext<S>>where
S::IgnoreSetext: IsUnset,
pub fn maybe_ignore_setext(
self,
value: Option<bool>,
) -> ParseBuilder<'c, 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.parse.ignore_setext = true;
assert_eq!(markdown_to_html(input, &options),
"<p>setext heading</p>\n<hr />\n");Sourcepub fn broken_link_callback(
self,
value: Arc<dyn BrokenLinkCallback + 'c>,
) -> ParseBuilder<'c, SetBrokenLinkCallback<S>>where
S::BrokenLinkCallback: IsUnset,
pub fn broken_link_callback(
self,
value: Arc<dyn BrokenLinkCallback + 'c>,
) -> ParseBuilder<'c, SetBrokenLinkCallback<S>>where
S::BrokenLinkCallback: IsUnset,
Optional (Some / Option setters).
In case the parser encounters any potential links that have a broken
reference (e.g [foo] when there is no [foo]: url entry at the
bottom) the provided callback will be called with the reference name,
both in normalized form and unmodified, and the returned pair will be
used as the link destination and title if not None.
let cb = |link_ref: BrokenLinkReference| match link_ref.normalized {
"foo" => Some(ResolvedReference {
url: "https://www.rust-lang.org/".to_string(),
title: "The Rust Language".to_string(),
}),
_ => None,
};
let mut options = Options::default();
options.parse.broken_link_callback = Some(Arc::new(cb));
let output = markdown_to_html(
"# Cool input!\nWow look at this cool [link][foo]. A [broken link] renders as text.",
&options,
);
assert_eq!(output,
"<h1>Cool input!</h1>\n<p>Wow look at this cool \
<a href=\"https://www.rust-lang.org/\" title=\"The Rust Language\">link</a>. \
A [broken link] renders as text.</p>\n");Sourcepub fn maybe_broken_link_callback(
self,
value: Option<Arc<dyn BrokenLinkCallback + 'c>>,
) -> ParseBuilder<'c, SetBrokenLinkCallback<S>>where
S::BrokenLinkCallback: IsUnset,
pub fn maybe_broken_link_callback(
self,
value: Option<Arc<dyn BrokenLinkCallback + 'c>>,
) -> ParseBuilder<'c, SetBrokenLinkCallback<S>>where
S::BrokenLinkCallback: IsUnset,
Optional (Some / Option setters).
In case the parser encounters any potential links that have a broken
reference (e.g [foo] when there is no [foo]: url entry at the
bottom) the provided callback will be called with the reference name,
both in normalized form and unmodified, and the returned pair will be
used as the link destination and title if not None.
let cb = |link_ref: BrokenLinkReference| match link_ref.normalized {
"foo" => Some(ResolvedReference {
url: "https://www.rust-lang.org/".to_string(),
title: "The Rust Language".to_string(),
}),
_ => None,
};
let mut options = Options::default();
options.parse.broken_link_callback = Some(Arc::new(cb));
let output = markdown_to_html(
"# Cool input!\nWow look at this cool [link][foo]. A [broken link] renders as text.",
&options,
);
assert_eq!(output,
"<h1>Cool input!</h1>\n<p>Wow look at this cool \
<a href=\"https://www.rust-lang.org/\" title=\"The Rust Language\">link</a>. \
A [broken link] renders as text.</p>\n");Sourcepub fn leave_footnote_definitions(
self,
value: bool,
) -> ParseBuilder<'c, SetLeaveFootnoteDefinitions<S>>where
S::LeaveFootnoteDefinitions: IsUnset,
pub fn leave_footnote_definitions(
self,
value: bool,
) -> ParseBuilder<'c, SetLeaveFootnoteDefinitions<S>>where
S::LeaveFootnoteDefinitions: IsUnset,
Optional (Some / Option setters). Default: false.
Leave footnote definitions in place in the document tree, rather than reordering them to the end. This will also cause unreferenced footnote definitions to remain in the tree, rather than being removed.
Comrak’s default formatters expect this option to be turned off, so use with care if you use the default formatters.
let mut options = Options::default();
options.extension.footnotes = true;
let arena = Arena::new();
let input = concat!(
"Remember burning a CD?[^cd]\n",
"\n",
"[^cd]: In the Old Days, a 4x burner was considered good.\n",
"\n",
"[^dvd]: And DVD-RWs? Those were something else.\n",
"\n",
"Me neither.",
);
fn node_kinds<'a>(doc: Node<'a>) -> Vec<&'static str> {
doc.descendants().map(|n| n.data().value.xml_node_name()).collect()
}
let root = parse_document(&arena, input, &options);
assert_eq!(
node_kinds(root),
&["document", "paragraph", "text", "footnote_reference", "paragraph", "text",
"footnote_definition", "paragraph", "text"],
);
options.parse.leave_footnote_definitions = true;
let root = parse_document(&arena, input, &options);
assert_eq!(
node_kinds(root),
&["document", "paragraph", "text", "footnote_reference", "footnote_definition",
"paragraph", "text", "footnote_definition", "paragraph", "text", "paragraph", "text"],
);Sourcepub fn maybe_leave_footnote_definitions(
self,
value: Option<bool>,
) -> ParseBuilder<'c, SetLeaveFootnoteDefinitions<S>>where
S::LeaveFootnoteDefinitions: IsUnset,
pub fn maybe_leave_footnote_definitions(
self,
value: Option<bool>,
) -> ParseBuilder<'c, SetLeaveFootnoteDefinitions<S>>where
S::LeaveFootnoteDefinitions: IsUnset,
Optional (Some / Option setters). Default: false.
Leave footnote definitions in place in the document tree, rather than reordering them to the end. This will also cause unreferenced footnote definitions to remain in the tree, rather than being removed.
Comrak’s default formatters expect this option to be turned off, so use with care if you use the default formatters.
let mut options = Options::default();
options.extension.footnotes = true;
let arena = Arena::new();
let input = concat!(
"Remember burning a CD?[^cd]\n",
"\n",
"[^cd]: In the Old Days, a 4x burner was considered good.\n",
"\n",
"[^dvd]: And DVD-RWs? Those were something else.\n",
"\n",
"Me neither.",
);
fn node_kinds<'a>(doc: Node<'a>) -> Vec<&'static str> {
doc.descendants().map(|n| n.data().value.xml_node_name()).collect()
}
let root = parse_document(&arena, input, &options);
assert_eq!(
node_kinds(root),
&["document", "paragraph", "text", "footnote_reference", "paragraph", "text",
"footnote_definition", "paragraph", "text"],
);
options.parse.leave_footnote_definitions = true;
let root = parse_document(&arena, input, &options);
assert_eq!(
node_kinds(root),
&["document", "paragraph", "text", "footnote_reference", "footnote_definition",
"paragraph", "text", "footnote_definition", "paragraph", "text", "paragraph", "text"],
);Sourcepub fn escaped_char_spans(
self,
value: bool,
) -> ParseBuilder<'c, SetEscapedCharSpans<S>>where
S::EscapedCharSpans: IsUnset,
pub fn escaped_char_spans(
self,
value: bool,
) -> ParseBuilder<'c, SetEscapedCharSpans<S>>where
S::EscapedCharSpans: IsUnset,
Optional (Some / Option setters). Default: false.
Leave escaped characters in an Escaped node in the document tree.
let mut options = Options::default();
let arena = Arena::new();
let input = "Notify user \\@example";
fn node_kinds<'a>(doc: Node<'a>) -> Vec<&'static str> {
doc.descendants().map(|n| n.data().value.xml_node_name()).collect()
}
let root = parse_document(&arena, input, &options);
assert_eq!(
node_kinds(root),
&["document", "paragraph", "text"],
);
options.parse.escaped_char_spans = true;
let root = parse_document(&arena, input, &options);
assert_eq!(
node_kinds(root),
&["document", "paragraph", "text", "escaped", "text", "text"],
);Note that enabling the escaped_char_spans render option will cause
this option to be enabled.
Sourcepub fn maybe_escaped_char_spans(
self,
value: Option<bool>,
) -> ParseBuilder<'c, SetEscapedCharSpans<S>>where
S::EscapedCharSpans: IsUnset,
pub fn maybe_escaped_char_spans(
self,
value: Option<bool>,
) -> ParseBuilder<'c, SetEscapedCharSpans<S>>where
S::EscapedCharSpans: IsUnset,
Optional (Some / Option setters). Default: false.
Leave escaped characters in an Escaped node in the document tree.
let mut options = Options::default();
let arena = Arena::new();
let input = "Notify user \\@example";
fn node_kinds<'a>(doc: Node<'a>) -> Vec<&'static str> {
doc.descendants().map(|n| n.data().value.xml_node_name()).collect()
}
let root = parse_document(&arena, input, &options);
assert_eq!(
node_kinds(root),
&["document", "paragraph", "text"],
);
options.parse.escaped_char_spans = true;
let root = parse_document(&arena, input, &options);
assert_eq!(
node_kinds(root),
&["document", "paragraph", "text", "escaped", "text", "text"],
);Note that enabling the escaped_char_spans render option will cause
this option to be enabled.