Struct comrak::ComrakOptions [] [src]

pub struct ComrakOptions {
    pub hardbreaks: bool,
    pub github_pre_lang: bool,
    pub width: usize,
    pub default_info_string: Option<String>,
    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,
}

Options for both parser and formatter functions.

Fields

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");

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");

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");

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");

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");

Enables the tagfilter extension from the GFM spec.

let options = ComrakOptions {
  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");

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></tbody></table>\n");

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");

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 {
  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");

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");

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");

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");

Trait Implementations

impl Default for ComrakOptions
[src]

[src]

Returns the "default value" for a type. Read more

impl Debug for ComrakOptions
[src]

[src]

Formats the value using the given formatter. Read more

impl Clone for ComrakOptions
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for ComrakOptions

impl Sync for ComrakOptions