Struct Render
pub struct Render { pub hardbreaks: bool, pub github_pre_lang: bool, pub full_info_string: bool, pub width: usize, pub unsafe: bool, pub escape: bool, pub list_style: ListStyleType, pub sourcepos: bool, pub escaped_char_spans: bool, pub ignore_empty_links: bool, pub gfm_quirks: bool, pub prefer_fenced: bool, pub figure_with_caption: bool, pub tasklist_classes: bool, pub alert_style: AlertStyleType, pub ol_width: usize, pub experimental_minimize_commonmark: bool, pub compact_html: bool }
Options for formatter functions.
Fields
hardbreaks: boolSoft line breaks in the input translate into hard line breaks in the output.
# use ; let mut options = default; assert_eq!; options.render.hardbreaks = true; assert_eq!;github_pre_lang: boolGitHub-style
<pre lang="xyz">is used for fenced code blocks with info tags.# use ; let mut options = default; assert_eq!; options.render.github_pre_lang = true; assert_eq!;full_info_string: boolEnable full info strings for code blocks
# use ; let mut options = default; assert_eq!; options.render.full_info_string = true; let html = markdown_to_html; eprintln!; assert!;width: usizeThe wrap column when outputting CommonMark.
# use ; #unsafe: boolAllow rendering of raw HTML and potentially dangerous links.
# use ; let mut options = 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!; options.render.r#unsafe = true; assert_eq!;escape: boolEscape raw HTML instead of clobbering it.
# use ; let mut options = default; let input = "<i>italic text</i>"; assert_eq!; options.render.escape = true; assert_eq!;list_style: ListStyleTypeSet the type of bullet list marker to use. Options are:
ListStyleType::Dashto use-(default)ListStyleType::Plusto use+ListStyleType::Starto use*
# use ; let mut options = default; let input = "- one\n- two\n- three"; assert_eq!; // default is Dash options.render.list_style = Plus; assert_eq!; options.render.list_style = Star; assert_eq!;sourcepos: boolInclude 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 https://github.com/kivikakk/comrak/blob/3bb6d4ce/src/tests/description_lists.rs#L60-L125.
# use ; let mut options = default; options.render.sourcepos = true; let input = "Hello *world*!"; assert_eq!;escaped_char_spans: boolWrap escaped characters in a
<span>to allow any post-processing to recognize them.# use ; let mut options = default; let input = "Notify user \\@example"; assert_eq!; options.render.escaped_char_spans = true; assert_eq!;Enabling this option will cause the
escaped_char_spansparse option to be enabled.ignore_empty_links: boolIgnore empty links in input.
# use ; let mut options = default; let input = "[]()"; assert_eq!; options.render.ignore_empty_links = true; assert_eq!;gfm_quirks: boolEnables GFM quirks in HTML output which break CommonMark compatibility.
# use ; let mut options = default; let input = "****abcd**** *_foo_*"; assert_eq!; options.render.gfm_quirks = true; assert_eq!;prefer_fenced: boolPrefer fenced code blocks when outputting CommonMark.
# use str; # use ; let arena = new; let mut options = default; let input = "```\nhello\n```\n"; let root = parse_document; let mut buf = Stringnew; format_commonmark; assert_eq!; buf.clear; options.render.prefer_fenced = true; format_commonmark; assert_eq!;figure_with_caption: boolRender the image as a figure element with the title as its caption.
# use ; let mut options = default; let input = ""; assert_eq!; options.render.figure_with_caption = true; assert_eq!;tasklist_classes: boolAdd classes to the output of the tasklist extension. This allows tasklists to be styled.
# use ; let mut options = default; options.extension.tasklist = true; let input = "- [ ] Foo"; assert_eq!; options.render.tasklist_classes = true; assert_eq!;alert_style: AlertStyleTypeHow to render alert blocks. Options are:
AlertStyleType::Specificto usedivs withmarkdown-prefixed classes (default)AlertStyleType::Semanticto useasides with anadmonitionclass
# use ; let mut options = default; options.extension.alerts = true; options.render.alert_style = Semantic; assert_eq!;ol_width: usizeRender ordered list with a minimum marker width. Having a width lower than 3 doesn't do anything.
# use ; let mut options = default; let input = "1. Something"; assert_eq!; options.render.ol_width = 5; assert_eq!;experimental_minimize_commonmark: boolMinimise escapes used in CommonMark output (
-t commonmark) by removing each individually and seeing if the resulting document roundtrips. Brute-force and expensive, but produces nicer output. Note that the result may not in fact be minimal.# use ; let mut options = default; let input = "__hi"; assert_eq!; options.render.experimental_minimize_commonmark = true; assert_eq!;compact_html: boolSuppress pretty-printing newlines between block-level HTML elements.
Normally comrak puts a
\nafter closing tags like</p>,</li>, etc. With this option on, those newlines are omitted.# use ; let mut options = default; assert_eq!; options.render.compact_html = true; assert_eq!;
Trait Implementations
impl Clone for Render
fn clone(&self) -> Self
impl Copy for Render
impl Debug for Render
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for Render
fn default() -> Self
Auto Trait Implementations
impl Freeze for Render
impl RefUnwindSafe for Render
impl Send for Render
impl Sync for Render
impl Unpin for Render
impl UnsafeUnpin for Render
impl UnwindSafe for Render
Blanket Implementations
impl<T> Any for Render
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Render
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Render
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Render
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Render
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Render
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Render
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Render
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Render
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>