[][src]Struct comrak::ComrakOptions

pub struct ComrakOptions {
    pub hardbreaks: bool,
    pub smart: bool,
    pub github_pre_lang: bool,
    pub width: usize,
    pub default_info_string: Option<String>,
    pub unsafe_: bool,
    pub ext_strikethrough: bool,
    pub ext_tagfilter: bool,
    pub ext_table: bool,
    pub ext_autolink: bool,
    pub ext_tasklist: bool,
    pub ext_superscript: bool,
    pub ext_header_ids: Option<String>,
    pub ext_footnotes: bool,
    pub ext_description_lists: bool,
}

Options for both parser and formatter functions.

Fields

hardbreaks: bool

Soft line breaks in the input translate into hard line breaks in the output.

let mut options = ComrakOptions::default();
assert_eq!(markdown_to_html("Hello.\nWorld.\n", &options),
           "<p>Hello.\nWorld.</p>\n");

options.hardbreaks = true;
assert_eq!(markdown_to_html("Hello.\nWorld.\n", &options),
           "<p>Hello.<br />\nWorld.</p>\n");
smart: bool

Punctuation (quotes, full-stops and hyphens) are converted into 'smart' punctuation.

let mut options = ComrakOptions::default();
assert_eq!(markdown_to_html("'Hello,' \"world\" ...", &options),
           "<p>'Hello,' &quot;world&quot; ...</p>\n");

options.smart = true;
assert_eq!(markdown_to_html("'Hello,' \"world\" ...", &options),
           "<p>‘Hello,’ “world” …</p>\n");
github_pre_lang: bool

GitHub-style <pre lang="xyz"> is used for fenced code blocks with info tags.

let mut options = ComrakOptions::default();
assert_eq!(markdown_to_html("``` rust\nfn hello();\n```\n", &options),
           "<pre><code class=\"language-rust\">fn hello();\n</code></pre>\n");

options.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");
width: usize

The wrap column when outputting CommonMark.

let mut options = ComrakOptions::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.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");
default_info_string: Option<String>

The default info string for fenced code blocks.

let mut options = ComrakOptions::default();
assert_eq!(markdown_to_html("```\nfn hello();\n```\n", &options),
           "<pre><code>fn hello();\n</code></pre>\n");

options.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");
unsafe_: bool

Allow rendering of raw HTML and potentially dangerous links.

let mut options = ComrakOptions::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.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");
ext_strikethrough: bool

Enables the strikethrough extension from the GFM spec.

let options = ComrakOptions {
  ext_strikethrough: true,
  ..ComrakOptions::default()
};
assert_eq!(markdown_to_html("Hello ~world~ there.\n", &options),
           "<p>Hello <del>world</del> there.</p>\n");
ext_tagfilter: bool

Enables the tagfilter extension from the GFM spec.

let options = ComrakOptions {
  unsafe_: true,
  ext_tagfilter: true,
  ..ComrakOptions::default()
};
assert_eq!(markdown_to_html("Hello <xmp>.\n\n<xmp>", &options),
           "<p>Hello &lt;xmp>.</p>\n&lt;xmp>\n");
ext_table: bool

Enables the table extension from the GFM spec.

let options = ComrakOptions {
  ext_table: true,
  ..ComrakOptions::default()
};
assert_eq!(markdown_to_html("| a | b |\n|---|---|\n| c | d |\n", &options),
           "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n</tr>\n</thead>\n\
            <tbody>\n<tr>\n<td>c</td>\n<td>d</td>\n</tr>\n</tbody>\n</table>\n");
ext_autolink: bool

Enables the autolink extension from the GFM spec.

let options = ComrakOptions {
  ext_autolink: true,
  ..ComrakOptions::default()
};
assert_eq!(markdown_to_html("Hello www.github.com.\n", &options),
           "<p>Hello <a href=\"http://www.github.com\">www.github.com</a>.</p>\n");
ext_tasklist: bool

Enables the 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.

let options = ComrakOptions {
  unsafe_: true,
  ext_tasklist: true,
  ..ComrakOptions::default()
};
assert_eq!(markdown_to_html("* [x] Done\n* [ ] Not done\n", &options),
           "<ul>\n<li><input type=\"checkbox\" disabled=\"\" checked=\"\" /> Done</li>\n\
           <li><input type=\"checkbox\" disabled=\"\" /> Not done</li>\n</ul>\n");
ext_superscript: bool

Enables the superscript Comrak extension.

let options = ComrakOptions {
  ext_superscript: true,
  ..ComrakOptions::default()
};
assert_eq!(markdown_to_html("e = mc^2^.\n", &options),
           "<p>e = mc<sup>2</sup>.</p>\n");
ext_header_ids: Option<String>

Enables the header IDs Comrak extension.

let options = ComrakOptions {
  ext_header_ids: Some("user-content-".to_string()),
  ..ComrakOptions::default()
};
assert_eq!(markdown_to_html("# README\n", &options),
           "<h1><a href=\"#readme\" aria-hidden=\"true\" class=\"anchor\" id=\"user-content-readme\"></a>README</h1>\n");
ext_footnotes: bool

Enables the footnotes extension per cmark-gfm.

For usage, see src/tests.rs. The extension is modelled after Kramdown.

let options = ComrakOptions {
  ext_footnotes: true,
  ..ComrakOptions::default()
};
assert_eq!(markdown_to_html("Hi[^x].\n\n[^x]: A greeting.\n", &options),
           "<p>Hi<sup class=\"footnote-ref\"><a href=\"#fn1\" id=\"fnref1\">1</a></sup>.</p>\n<section class=\"footnotes\">\n<ol>\n<li id=\"fn1\">\n<p>A greeting. <a href=\"#fnref1\" class=\"footnote-backref\">↩</a></p>\n</li>\n</ol>\n</section>\n");
ext_description_lists: 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.

First term

: Details for the **first term**

Second term

: Details for the **second term**

    More details in second paragraph.
let options = ComrakOptions {
  ext_description_lists: true,
  ..ComrakOptions::default()
};
assert_eq!(markdown_to_html("Term\n\n: Definition", &options),
           "<dl><dt>\n<p>Term</p>\n</dt>\n<dd>\n<p>Definition</p>\n</dd>\n</dl>\n");

Trait Implementations

impl Default for ComrakOptions[src]

impl Clone for ComrakOptions[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for ComrakOptions[src]

Auto Trait Implementations

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]