\n");
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub autolink: bool,
/// Enables the
/// [task list items extension](https://github.github.com/gfm/#task-list-items-extension-)
/// from the GFM spec.
///
/// Note that the spec does not define the precise output, so only the bare essentials are
/// rendered.
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// options.extension.tasklist = true;
/// options.render.r#unsafe = true;
/// assert_eq!(markdown_to_html("* [x] Done\n* [ ] Not done\n", &options),
/// "
\n");
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub superscript: bool,
/// Enables the header IDs Comrak extension, with the given ID prefix.
///
/// When set, each heading gains an anchor element with an `id` attribute
/// formed by prefixing the slugified heading text. This is useful for
/// namespacing heading anchors to avoid collisions when rendered Markdown
/// is embedded alongside other content on a page (e.g. GitHub uses the
/// prefix `"user-content-"` for this purpose).
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// options.extension.header_id_prefix = Some("user-content-".to_string());
/// assert_eq!(markdown_to_html("# README\n", &options),
/// "
README
\n");
/// ```
pub header_id_prefix: Option,
/// When enabled alongside [`header_id_prefix`](#structfield.header_id_prefix), the header ID
/// prefix is also applied to the `href` anchor in the generated link.
///
/// Has no effect if `header_id_prefix` is `None`.
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// options.extension.header_id_prefix = Some("user-content-".to_string());
/// options.extension.header_id_prefix_in_href = true;
/// assert_eq!(markdown_to_html("# README\n", &options),
/// "
README
\n");
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub header_id_prefix_in_href: bool,
/// Enables the footnotes extension per `cmark-gfm`.
///
/// For usage, see `src/tests.rs`. The extension is modelled after
/// [Kramdown](https://kramdown.gettalong.org/syntax.html#footnotes).
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// options.extension.footnotes = true;
/// assert_eq!(markdown_to_html("Hi[^x].\n\n[^x]: A greeting.\n", &options),
/// "
\n\n\n");
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub inline_footnotes: bool,
/// Enables the description lists extension.
///
/// Each term must be defined in one paragraph, followed by a blank line,
/// and then by the details. Details begins with a colon.
///
/// Not (yet) compatible with render.sourcepos.
///
/// ```markdown
/// First term
///
/// : Details for the **first term**
///
/// Second term
///
/// : Details for the **second term**
///
/// More details in second paragraph.
/// ```
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// options.extension.description_lists = true;
/// assert_eq!(markdown_to_html("Term\n\n: Definition", &options),
/// "
\n
Term
\n
\n
Definition
\n
\n
\n");
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub description_lists: bool,
/// Enables the front matter extension.
///
/// Front matter, which begins with the delimiter string at the beginning of the file and ends
/// at the end of the next line that contains only the delimiter, is passed through unchanged
/// in markdown output and omitted from HTML output.
///
/// ```markdown
/// ---
/// layout: post
/// title: Formatting Markdown with Comrak
/// ---
///
/// # Shorter Title
///
/// etc.
/// ```
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// options.extension.front_matter_delimiter = Some("---".to_owned());
/// assert_eq!(
/// markdown_to_html("---\nlayout: post\n---\nText\n", &options),
/// markdown_to_html("Text\n", &Options::default()));
/// ```
///
/// ```rust
/// # use comrak::{format_commonmark, Arena, Options};
/// use comrak::parse_document;
/// let mut options = Options::default();
/// options.extension.front_matter_delimiter = Some("---".to_owned());
/// let arena = Arena::new();
/// let input = "---\nlayout: post\n---\nText\n";
/// let root = parse_document(&arena, input, &options);
/// let mut buf = String::new();
/// format_commonmark(&root, &options, &mut buf);
/// assert_eq!(buf, input);
/// ```
pub front_matter_delimiter: Option,
/// Enables the multiline block quote extension.
///
/// Place `>>>` before and after text to make it into
/// a block quote.
///
/// ```markdown
/// Paragraph one
///
/// >>>
/// Paragraph two
///
/// - one
/// - two
/// >>>
/// ```
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// options.extension.multiline_block_quotes = true;
/// assert_eq!(markdown_to_html(">>>\nparagraph\n>>>", &options),
/// "
\n");
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub underline: bool,
/// Enables subscript text using single tildes.
///
/// If the strikethrough option is also enabled, this overrides the single
/// tilde case to output subscript text.
///
/// ```md
/// H~2~O
/// ```
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// options.extension.subscript = true;
///
/// assert_eq!(markdown_to_html("H~2~O", &options),
/// "
H2O
\n");
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub subscript: bool,
/// Enables spoilers using double vertical bars
///
/// ```md
/// Darth Vader is ||Luke's father||
/// ```
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// options.extension.spoiler = true;
///
/// assert_eq!(markdown_to_html("Darth Vader is ||Luke's father||", &options),
/// "
Darth Vader is Luke's father
\n");
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub spoiler: bool,
/// Requires at least one space after a `>` character to generate a blockquote,
/// and restarts blockquote nesting across unique lines of input
///
/// ```md
/// >implying implications
///
/// > one
/// > > two
/// > three
/// ```
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// options.extension.greentext = true;
///
/// assert_eq!(markdown_to_html(">implying implications", &options),
/// "
\n");
/// ```
pub default_info_string: Option,
/// Whether or not a simple `x` or `X` is used for tasklist or any other symbol is allowed.
#[cfg_attr(feature = "bon", builder(default))]
pub relaxed_tasklist_matching: bool,
/// 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.
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// options.extension.table = true;
/// options.extension.tasklist = true;
/// assert_eq!(markdown_to_html("| val |\n| - |\n| [ ] |\n", &options),
/// "
\n");
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub tasklist_in_table: bool,
/// 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.
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// options.extension.autolink = true;
/// assert_eq!(markdown_to_html("[https://foo.com]", &options),
/// "
\n\n");
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub ignore_setext: bool,
/// 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`].
///
/// ```rust
/// # use std::{str, sync::Arc};
/// # use comrak::{markdown_to_html, options::BrokenLinkReference, Options, ResolvedReference};
/// 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,
/// "
Cool input!
\n
Wow look at this cool \
/// link. \
/// A [broken link] renders as text.
\n");
/// ```
#[cfg_attr(feature = "arbitrary", arbitrary(default))]
pub broken_link_callback: Option>,
/// 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.
///
/// ```rust
/// # use comrak::{Arena, parse_document, Node, Options};
/// 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"],
/// );
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub leave_footnote_definitions: bool,
/// Leave escaped characters in an `Escaped` node in the document tree.
///
/// ```rust
/// # use comrak::{Arena, parse_document, Node, Options};
/// 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.
#[cfg_attr(feature = "bon", builder(default))]
pub escaped_char_spans: bool,
/// When enabled, the [`column`][crate::nodes::LineColumn::column] values in
/// [`Sourcepos`][crate::nodes::Sourcepos] are counted as Unicode characters
/// (i.e. `char`s) rather than as UTF-8 bytes.
///
/// By default, column values follow cmark behaviour: each byte of a
/// multi-byte UTF-8 character counts as a separate column. Enabling this
/// option converts those byte-based columns to character-based columns after
/// parsing, so that a 3-byte character such as `好` occupies only one
/// column position instead of three.
///
/// ```rust
/// # use comrak::{Arena, parse_document, Options};
/// let arena = Arena::new();
/// let mut options = Options::default();
///
/// // Default (byte-based): "好" spans columns 1-3
/// let root = parse_document(&arena, "好", &options);
/// let sp = root.first_child().unwrap().data().sourcepos;
/// assert_eq!(sp.start.column, 1);
/// assert_eq!(sp.end.column, 3);
///
/// // Char-based: "好" occupies only column 1
/// options.parse.sourcepos_chars = true;
/// let root = parse_document(&arena, "好", &options);
/// let sp = root.first_child().unwrap().data().sourcepos;
/// assert_eq!(sp.start.column, 1);
/// assert_eq!(sp.end.column, 1);
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub sourcepos_chars: bool,
}
/// The type of the callback used when a reference link is encountered with no
/// matching reference.
///
/// The details of the broken reference are passed in the
/// [`BrokenLinkReference`] argument. If a [`ResolvedReference`] is returned, it
/// is used as the link; otherwise, no link is made and the reference text is
/// preserved in its entirety.
pub trait BrokenLinkCallback: RefUnwindSafe + Send + Sync {
/// Potentially resolve a single broken link reference.
fn resolve(&self, broken_link_reference: BrokenLinkReference) -> Option;
}
impl Debug for dyn BrokenLinkCallback + '_ {
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), fmt::Error> {
formatter.write_str("")
}
}
impl BrokenLinkCallback for F
where
F: Fn(BrokenLinkReference) -> Option,
F: RefUnwindSafe + Send + Sync,
{
fn resolve(&self, broken_link_reference: BrokenLinkReference) -> Option {
self(broken_link_reference)
}
}
/// Struct to the broken link callback, containing details on the link reference
/// which failed to find a match.
#[derive(Debug)]
pub struct BrokenLinkReference<'l> {
/// The normalized reference link label. Unicode case folding is applied;
/// see for a
/// discussion on the details of what this exactly means.
pub normalized: &'l str,
/// The original text in the link label.
pub original: &'l str,
}
#[derive(Default, Debug, Clone, Copy)]
#[cfg_attr(feature = "bon", derive(Builder))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
/// Options for formatter functions.
pub struct Render {
/// [Soft line breaks](http://spec.commonmark.org/0.27/#soft-line-breaks) in the input
/// translate into hard line breaks in the output.
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// assert_eq!(markdown_to_html("Hello.\nWorld.\n", &options),
/// "
` is used for fenced code blocks with info tags.
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// assert_eq!(markdown_to_html("``` rust\nfn hello();\n```\n", &options),
/// "
\n");
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub escape: bool,
/// Set the type of [bullet list marker](https://spec.commonmark.org/0.30/#bullet-list-marker) to use. Options are:
///
/// * [`ListStyleType::Dash`] to use `-` (default)
/// * [`ListStyleType::Plus`] to use `+`
/// * [`ListStyleType::Star`] to use `*`
///
/// ```rust
/// # use comrak::{markdown_to_commonmark, Options, options::ListStyleType};
/// 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");
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub list_style: ListStyleType,
/// Include source position attributes in HTML and XML output.
///
/// Sourcepos information is reliable for core block items excluding
/// lists and list items, all inlines, and most extensions.
/// The description lists extension still has issues; see
/// .
///
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// options.render.sourcepos = true;
/// let input = "Hello *world*!";
/// assert_eq!(markdown_to_html(input, &options),
/// "
Hello world!
\n");
/// ```
#[cfg_attr(feature = "bon", builder(default))]
pub sourcepos: bool,
/// Wrap escaped characters in a `` to allow any
/// post-processing to recognize them.
///
/// ```rust
/// # use comrak::{markdown_to_html, Options};
/// let mut options = Options::default();
/// let input = "Notify user \\@example";
///
/// assert_eq!(markdown_to_html(input, &options),
/// "