pub struct ParseOptions {
pub constructs: Constructs,
pub inline_code_info: bool,
pub html_block_blank_lines: bool,
pub html_tag_namespaces: bool,
pub strikethrough_single_tilde: bool,
pub math_text_single_dollar: bool,
}Expand description
Configuration that describes how to parse from markdown.
You can use this:
- To control what markdown constructs are turned on and off
- To control some of those constructs
In most cases, you will want to use the default trait or gfm method.
§Examples
use base_markdown::ParseOptions;
// Use the default trait to parse markdown according to `CommonMark`:
let commonmark = ParseOptions::default();
// Use the `gfm` method to parse markdown according to GFM:
let gfm = ParseOptions::gfm();Fields§
§constructs: ConstructsWhich constructs to enable and disable.
The default is to follow CommonMark.
§Examples
use base_markdown::{to_html, to_html_with_options, Constructs, Options, ParseOptions};
// `markdown-rs` follows CommonMark by default:
assert_eq!(
to_html(" indented code?"),
"<pre><code>indented code?\n</code></pre>"
);
// Pass `constructs` to choose what to enable and disable:
assert_eq!(
to_html_with_options(
" indented code?",
&Options {
parse: ParseOptions {
constructs: Constructs {
code_indented: false,
..Constructs::default()
},
..ParseOptions::default()
},
..Options::default()
}
),
"<p>indented code?</p>"
);inline_code_info: boolWhether to parse a language prefix, such as ruby:, before inline code.
When enabled, the prefix is removed from the surrounding text and
stored as the inline code node’s lang value. The default is false.
html_block_blank_lines: boolWhether indented type 6 and type 7 HTML blocks continue across blank lines when later content keeps a consistent indentation.
The default is false, which follows CommonMark’s blank-line rule.
html_tag_namespaces: boolWhether : is allowed in HTML tag names for namespace prefixes such
as svg:circle.
The default is false to preserve CommonMark parsing of text such as
<m:abc>.
strikethrough_single_tilde: boolWhether to support strikethrough with a single tilde
This option does nothing if strikethrough is not turned on in
constructs.
This option does not affect strikethrough with double tildes.
The default is true, which follows how markdown on github.com
works, as strikethrough with single tildes is supported.
Pass false, to follow the GFM spec more strictly, by not allowing
strikethrough with single tildes.
§Examples
use base_markdown::{to_html_with_options, Constructs, Options, ParseOptions};
// `markdown-rs` supports single tildes by default:
assert_eq!(
to_html_with_options(
"~a~",
&Options {
parse: ParseOptions {
constructs: Constructs::gfm(),
..ParseOptions::default()
},
..Options::default()
}
),
"<p><del>a</del></p>"
);
// Pass `strikethrough_single_tilde: false` to turn that off:
assert_eq!(
to_html_with_options(
"~a~",
&Options {
parse: ParseOptions {
constructs: Constructs::gfm(),
strikethrough_single_tilde: false,
..ParseOptions::default()
},
..Options::default()
}
),
"<p>~a~</p>"
);math_text_single_dollar: boolWhether to support math (text) with a single dollar
This option does nothing if math_text is not turned on in
constructs.
This option does not affect math (text) with two or more dollars.
The default is true, which is more close to how code (text) and
Pandoc work, as it allows math with a single dollar to form.
However, single dollars can interfere with “normal” dollars in text.
Pass false, to only allow math (text) to form when two or more
dollars are used.
If you pass false, you can still use two or more dollars for text
math.
§Examples
use base_markdown::{to_html_with_options, Constructs, Options, ParseOptions};
// `markdown-rs` supports single dollars by default:
assert_eq!(
to_html_with_options(
"$a$",
&Options {
parse: ParseOptions {
constructs: Constructs {
math_text: true,
..Constructs::default()
},
..ParseOptions::default()
},
..Options::default()
}
),
"<p><code class=\"language-math math-inline\">a</code></p>"
);
// Pass `math_text_single_dollar: false` to turn that off:
assert_eq!(
to_html_with_options(
"$a$",
&Options {
parse: ParseOptions {
constructs: Constructs {
math_text: true,
..Constructs::default()
},
math_text_single_dollar: false,
..ParseOptions::default()
},
..Options::default()
}
),
"<p>$a$</p>"
);Implementations§
Source§impl ParseOptions
impl ParseOptions
Sourcepub fn gfm() -> Self
pub fn gfm() -> Self
GFM.
GFM stands for GitHub flavored markdown.
GFM extends CommonMark and adds support for autolink literals,
footnotes, strikethrough, tables, and tasklists.
For more information, see the GFM specification: https://github.github.com/gfm/