### Example usage of codefence_syntax_highlighter with MockAdapter Source: https://docs.rs/comrak/latest/comrak/options/struct.RenderPluginsBuilder.html Demonstrates installing a custom syntax highlighter (MockAdapter) that wraps highlighted code in custom tags. It asserts the output HTML before and after setting the adapter. Note the 'math' key is not used by this map. ```rust use std::borrow::Cow; use std::collections::HashMap; use std::fmt::{self, Write}; let options = Options::default(); let mut plugins = Plugins::default(); let input = "```rust\nfn main<'a>();\n```"; assert_eq!(markdown_to_html_with_plugins(input, &options, &plugins), "
fn main<'a>();\n\n");
pub struct MockAdapter {}
impl SyntaxHighlighterAdapter for MockAdapter {
fn write_highlighted(&self, output: &mut dyn fmt::Write, lang: Option<&str>, code: &str) -> fmt::Result {
write!(output, "{}", lang.unwrap(), code)
}
fn write_pre_tag<'s>(&self, output: &mut dyn fmt::Write, _attributes: HashMap<&'static str, Cow<'s, str>>) -> fmt::Result {
output.write_str("")
}
fn write_code_tag<'s>(&self, output: &mut dyn fmt::Write, _attributes: HashMap<&'static str, Cow<'s, str>>) -> fmt::Result {
output.write_str("")
}
}
let adapter = MockAdapter {};
plugins.render.codefence_syntax_highlighter = Some(&adapter);
assert_eq!(markdown_to_html_with_plugins(input, &options, &plugins),
"fn main<'a>();\n
\n");
```
--------------------------------
### Highlight extension example
Source: https://docs.rs/comrak/latest/comrak/options/struct.ExtensionBuilder.html
Example input and Rust code for the highlight extension, showing the == syntax and the expected HTML output.
```markdown
Hey, ==this is important!==
```
```
let mut options = Options::default();
options.extension.highlight = true;
assert_eq!(markdown_to_html("Hey, ==this is important!==", &options),
"Hey, this is important!
\n");
```
--------------------------------
### Math Code Parsing Examples
Source: https://docs.rs/comrak/latest/src/comrak/parser/options.rs.html
Examples showing how math code blocks and inline math are parsed into HTML.
```rust
assert_eq!(markdown_to_html("$`1 + 2`$", &options),
"1 + 2
\n");
assert_eq!(markdown_to_html("```math\nx^2\n```\n", &options),
"x^2\n
\n");
```
--------------------------------
### Attributes Syntax Example
Source: https://docs.rs/comrak/latest/comrak/nodes/struct.Attributes.html
An example showing how attributes can be attached to an inline element in the source document.
```text
Some `code`{
a="hello"
b="privyet"
}
```
--------------------------------
### Custom Formatter Implementation Example
Source: https://docs.rs/comrak/latest/src/comrak/html.rs.html
This example demonstrates how to use the create_formatter macro to define custom rendering logic for specific AST nodes, such as bold text and image URLs, and then format a document using the resulting struct.
```rust
context.user += 1;
context.write_str(if entering { "" } else { "" })?;
},
NodeValue::Image(ref nl) => |context, node, entering| {
assert!(node.data().sourcepos == (3, 1, 3, 18).into());
if entering {
context.write_str(&nl.url.to_uppercase())?;
return Ok(ChildRendering::Skip);
}
},
});
let options = Options::default();
let arena = Arena::new();
let doc = parse_document(
&arena,
"_Hello_, **world**.\n\n",
&options,
);
let mut result: String = String::new();
let converted_count = CustomFormatter::format_document(doc, &options, &mut result, 0).unwrap();
assert_eq!(
result,
"Hello, world.
\n/IMG.PNG
\n"
);
assert_eq!(converted_count, 4);
```
--------------------------------
### create_formatter! macro example with custom emphasis and strong handling
Source: https://docs.rs/comrak/latest/src/comrak/html.rs.html
Shows how to use the create_formatter! macro to define a custom formatter with a user state of type usize. The formatter overrides NodeValue::Emph and NodeValue::Strong to write custom HTML tags and increments the user counter on each emphasis node. The example includes hidden setup lines (prefixed with #) that are part of the doctest.
```rust
create_formatter!(CustomFormatter, {
NodeValue::Emph => |context, entering| {
context.user += 1;
if entering {
context.write_str("")?;
} else {
context.write_str("")?;
}
},
NodeValue::Strong => |context, entering| {
if entering {
context.write_str("")?;
} else {
context.write_str("")?;
}
},
});
```
--------------------------------
### Description list example
Source: https://docs.rs/comrak/latest/comrak/nodes/enum.NodeValue.html
Example of a description list in Markdown, enabled with the `ext_description_lists` option. A blank line is required between terms and details.
```markdown
Term 1
: Details 1
Term 2
: Details 2
```
--------------------------------
### Insert extension input
Source: https://docs.rs/comrak/latest/comrak/options/struct.ExtensionBuilder.html
Example input for the insert extension, showing the ++ syntax for inserted text.
```markdown
This is ++added text++
```
--------------------------------
### smart option example
Source: https://docs.rs/comrak/latest/comrak/options/struct.Parse.html
Shows how setting `options.parse.smart = true` converts straight quotes and ellipses to smart punctuation.
```rust
let mut options = Options::default();
assert_eq!(markdown_to_html("'Hello,' \"world\" ...", &options),
"'Hello,' "world" ...
\n");
options.parse.smart = true;
assert_eq!(markdown_to_html("'Hello,' \"world\" ...", &options),
"‘Hello,’ “world” …
\n");
```
--------------------------------
### Enable insert extension
Source: https://docs.rs/comrak/latest/comrak/options/struct.ExtensionBuilder.html
Enables the insert extension and asserts the HTML output for the inserted text example.
```rust
let mut options = Options::default();
options.extension.insert = true;
assert_eq!(markdown_to_html("This is ++added text++", &options),
"This is added text
\n");
```
--------------------------------
### CommonMark URL input example
Source: https://docs.rs/comrak/latest/comrak/html/fn.escape_href.html
An example of a CommonMark link input that demonstrates how the function handles percent-encoded characters in query strings.
```markdown
[hi](https://ddg.gg/?q=a%20b)
```
--------------------------------
### width option example
Source: https://docs.rs/comrak/latest/comrak/options/struct.RenderBuilder.html
Shows default wrapping (no wrap) and the effect of setting options.render.width = 20, which wraps CommonMark output at 20 columns.
```rust
let mut options = Options::default();
let node = parse_document(&arena, "hello hello hello hello hello hello", &options);
let mut output = String::new();
format_commonmark(node, &options, &mut output).unwrap();
assert_eq!(output,
"hello hello hello hello hello hello\n");
options.render.width = 20;
let mut output = String::new();
format_commonmark(node, &options, &mut output).unwrap();
assert_eq!(output,
"hello hello hello\nhello hello hello\n");
```
--------------------------------
### Blockquote Formatting Example
Source: https://docs.rs/comrak/latest/src/comrak/parser/options.rs.html
Example of blockquote syntax requiring a space after the > character.
```md
>implying implications
> one
> > two
> three
```
--------------------------------
### List example
Source: https://docs.rs/comrak/latest/comrak/nodes/enum.NodeValue.html
Example of a list in Markdown, showing both unordered and ordered list items. The List node contains list items.
```markdown
* An unordered list
* Another item
1. An ordered list
2. Another item
```
--------------------------------
### default_info_string option example
Source: https://docs.rs/comrak/latest/comrak/options/struct.Parse.html
Shows how setting `options.parse.default_info_string` adds a language class to fenced code blocks.
```rust
let mut options = Options::default();
assert_eq!(markdown_to_html("```\nfn hello();\n```\n", &options),
"fn hello();\n
\n");
options.parse.default_info_string = Some("rust".into());
assert_eq!(markdown_to_html("```\nfn hello();\n```\n", &options),
"fn hello();\n
\n");
```
--------------------------------
### relaxed_autolinks option example
Source: https://docs.rs/comrak/latest/comrak/options/struct.Parse.html
Shows how enabling `options.parse.relaxed_autolinks` allows autolinks to be detected inside brackets.
```rust
let mut options = Options::default();
options.extension.autolink = true;
assert_eq!(markdown_to_html("[https://foo.com]", &options),
"[https://foo.com]
\n");
options.parse.relaxed_autolinks = true;
assert_eq!(markdown_to_html("[https://foo.com]", &options),
"\n");
```
--------------------------------
### Anchorizer anchorize method example
Source: https://docs.rs/comrak/latest/comrak/struct.Anchorizer.html
Shows the conversion of a header string into a GFM-compliant anchor, including the removal of special characters.
```rust
let mut anchorizer = Anchorizer::new();
let source = "Ticks aren't in";
assert_eq!("ticks-arent-in", anchorizer.anchorize(source));
```
--------------------------------
### Enable autolink extension
Source: https://docs.rs/comrak/latest/comrak/options/struct.Extension.html
Enables the GFM autolink extension. The example shows that a bare URL like `www.github.com` is turned into a hyperlink.
```rust
let mut options = Options::default();
options.extension.autolink = true;
assert_eq!(markdown_to_html("Hello www.github.com.\n", &options),
"Hello www.github.com.
\n");
```
--------------------------------
### Enable cjk_friendly_emphasis option
Source: https://docs.rs/comrak/latest/comrak/options/struct.Extension.html
Recognizes many emphasis that appear in CJK contexts but are not recognized by plain CommonMark. The example shows the markdown input and the option setting.
```markdown
**この文は重要です。**但这句话并不重要。
```
```rust
let mut options = Options::default();
options.extension.cjk_friendly_emphasis = true;
```
--------------------------------
### Block quote example
Source: https://docs.rs/comrak/latest/comrak/nodes/enum.NodeValue.html
Example of a block quote in Markdown. The BlockQuote node contains other blocks.
```markdown
> A block quote.
```
--------------------------------
### Enable math dollars with options.extension.math_dollars
Source: https://docs.rs/comrak/latest/comrak/options/struct.Extension.html
Enables math using dollar syntax. The first block shows inline and display math examples; the second shows how to enable the option and asserts the HTML output for both inline and display math.
```markdown
Inline math $1 + 2$ and display math $$x + y$$
$$
x^2
$$
```
```rust
let mut options = Options::default();
options.extension.math_dollars = true;
assert_eq!(markdown_to_html("$1 + 2$ and $$x = y$$", &options),
"1 + 2 and x = y
\n");
assert_eq!(markdown_to_html("$$\nx^2\n$$\n", &options),
"\nx^2\n
\n");
```
--------------------------------
### Enable description_lists extension with example and Rust assertion
Source: https://docs.rs/comrak/latest/comrak/options/struct.ExtensionBuilder.html
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
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");
```
--------------------------------
### build
Source: https://docs.rs/comrak/latest/comrak/options/struct.RenderPluginsBuilder.html
Finishes building the RenderPlugins object.
```APIDOC
## build
### Description
Finish building and return the requested object.
### Method
build
### Signature
`pub fn build(self) -> RenderPlugins<'p> where S: IsComplete`
### Parameters
- `self` - The builder instance.
### Returns
- `RenderPlugins<'p>` - The constructed render plugins object.
```
--------------------------------
### Rust example for escaped_char_spans option
Source: https://docs.rs/comrak/latest/src/comrak/parser/options.rs.html
Shows how to use the escaped_char_spans option in comrak. The example parses a markdown string with escaped characters and checks the resulting node kinds.
```rust
/// node_kinds(root),
/// &["document", "paragraph", "text", "escaped", "text", "text"],
/// );
/// ```
```
--------------------------------
### Node::reverse_traverse
Source: https://docs.rs/comrak/latest/comrak/nodes/type.AstNode.html
Returns an iterator of references to `NodeEdge` enums for each `Node` and its descendants, in _reverse_ order. `NodeEdge` enums represent the `Start` or `End` of each node. Use `descendants()` if you don't need `Start` and `End`.
```APIDOC
## Node::reverse_traverse
### Description
Returns an iterator of references to `NodeEdge` enums for each `Node` and its descendants, in _reverse_ order. `NodeEdge` enums represent the `Start` or `End` of each node. Use `descendants()` if you don't need `Start` and `End`.
### Method
reverse_traverse
### Signature
pub fn reverse_traverse(&'a self) -> ReverseTraverse<'a, T>
### Returns
- **ReverseTraverse<'a, T>** - An iterator of references to `NodeEdge` enums for each `Node` and its descendants, in reverse order.
```
--------------------------------
### Enable LaTeX math with options.extension.math_latex
Source: https://docs.rs/comrak/latest/comrak/options/struct.Extension.html
Enables math using LaTeX-style delimiters. The first block shows the markdown syntax for inline and display math; the second shows how to enable the option and asserts the HTML output.
```markdown
Inline math \(1 + 2\) and display math \[x + y\]
```
```rust
let mut options = Options::default();
options.extension.math_latex = true;
assert_eq!(markdown_to_html("\\(1 + 2\\) and \\[x = y\\]", &options),
"1 + 2 and x = y
\n");
```
--------------------------------
### Enable description lists with options.extension.description_lists
Source: https://docs.rs/comrak/latest/comrak/options/struct.Extension.html
Enables the description lists extension. The first block shows the markdown syntax for a description list; the second shows how to enable the option and asserts the HTML output. Not 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
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");
```
--------------------------------
### Node::traverse
Source: https://docs.rs/comrak/latest/comrak/nodes/type.AstNode.html
Returns an iterator of references to `NodeEdge` enums for each `Node` and its descendants, in tree order. `NodeEdge` enums represent the `Start` or `End` of each node. Use `descendants()` if you don't need `Start` and `End`.
```APIDOC
## Node::traverse
### Description
Returns an iterator of references to `NodeEdge` enums for each `Node` and its descendants, in tree order. `NodeEdge` enums represent the `Start` or `End` of each node. Use `descendants()` if you don't need `Start` and `End`.
### Method
traverse
### Signature
pub fn traverse(&'a self) -> Traverse<'a, T>
### Returns
- **Traverse<'a, T>** - An iterator of references to `NodeEdge` enums for each `Node` and its descendants, in tree order.
```
--------------------------------
### ExtensionBuilder::build
Source: https://docs.rs/comrak/latest/comrak/options/struct.ExtensionBuilder.html
Finishes building and returns the configured Extension object.
```APIDOC
## ExtensionBuilder::build
### Description
Finish building and return the requested object.
### Method
build
### Signature
pub fn build(self) -> Extension<'c>
where S: IsComplete
### Parameters
None
### Returns
- **Extension<'c>** - The configured extension object.
```
--------------------------------
### Rust example for sourcepos_chars option
Source: https://docs.rs/comrak/latest/src/comrak/parser/options.rs.html
Demonstrates the sourcepos_chars option which changes column counting from UTF-8 bytes to Unicode characters. The example shows that a 3-byte character like '好' spans columns 1-3 by default but only column 1 when the option is enabled.
```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);
```
--------------------------------
### Render Markdown to HTML with comrak
Source: https://docs.rs/comrak/latest/src/comrak/lib.rs.html
Two usage examples from the crate root documentation. The first shows the simplest way to render Markdown to HTML using `markdown_to_html` with default options. The second demonstrates parsing Markdown into an AST, manipulating text nodes, and formatting to HTML with `parse_document`, `format_html`, and `Arena`.
```rust
use comrak::{markdown_to_html, Options};
assert_eq!(
markdown_to_html("Olá, **世界**!", &Options::default()),
"Olá, 世界!
\n"
);
```
```rust
use comrak::{Arena, parse_document, format_html, Options};
use comrak::nodes::NodeValue;
# fn main() {
let arena = Arena::new();
let root = parse_document(
&arena,
"Hello, pretty world!\n\n1. Do you like [pretty](#) paintings?\n2. Or *pretty* music?\n",
&Options::default());
for node in root.descendants() {
if let NodeValue::Text(ref mut text) = node.data.borrow_mut().value {
*text = text.to_mut().replace("pretty", "beautiful").into()
}
}
let mut html = String::new();
format_html(root, &Options::default(), &mut html).unwrap();
assert_eq!(
&html,
"Hello, beautiful world!
\n\n \n\n - Do you like beautiful paintings?
\n\n - Or beautiful music?
\n\n
\n");
# }
```
--------------------------------
### Subtext input
Source: https://docs.rs/comrak/latest/comrak/options/struct.ExtensionBuilder.html
Example input for the subtext extension, showing block scoped subscript syntax.
```markdown
-# subtext
```
--------------------------------
### Enable GitHub alerts with options.extension.alerts
Source: https://docs.rs/comrak/latest/comrak/options/struct.Extension.html
Enables GitHub style alerts. The first block shows the markdown syntax for an alert; the second shows how to enable the option and asserts the HTML output.
```markdown
> [!note]
> Something of note
```
```rust
let mut options = Options::default();
options.extension.alerts = true;
assert_eq!(markdown_to_html("> [!note]\n> Something of note", &options),
"\nNote
\nSomething of note
\n\n");
```
--------------------------------
### Options<'c>
Source: https://docs.rs/comrak/latest/comrak/options/struct.Options.html
Umbrella options struct that holds extension, parse, and render configuration for comrak.
```APIDOC
## Options<'c>
### Description
Umbrella options struct for comrak, containing extension, parse, and render configuration.
### Fields
- **extension**: `Extension<'c>` - Enable CommonMark extensions.
- **parse**: `Parse<'c>` - Configure parse-time options.
- **render**: `Render` - Configure render-time options.
### Trait Implementations
- `Arbitrary<'arbitrary>` (available on crate feature `arbitrary` only)
- `Clone`
- `Debug`
- `Default`
### Default
Returns the default value for the type.
### Example
```rust
let options = Options::default();
```
```
--------------------------------
### version
Source: https://docs.rs/comrak/latest/comrak/fn.version.html
Returns the version of the crate.
```APIDOC
## version
### Description
Returns the version of the crate.
### Method
version
### Endpoint
version
### Parameters
None
### Request Example
None
### Response
#### Success Response
- **return** (&'static str) - The version of the crate.
#### Response Example
None
```
--------------------------------
### SyntaxHighlighterAdapter implementation for code highlighting
Source: https://docs.rs/comrak/latest/comrak/options/struct.RenderPlugins.html
Shows how to define a custom SyntaxHighlighterAdapter and enable it. The adapter wraps code in language-specific spans and custom pre/code tags. It is then assigned to plugins.render.codefence_syntax_highlighter.
```rust
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::{self, Write};
let options = Options::default();
let mut plugins = Plugins::default();
let input = "```rust\nfn main<'a>();\n```";
assert_eq!(markdown_to_html_with_plugins(input, &options, &plugins),
"fn main<'a>();\n
\n");
pub struct MockAdapter {}
impl SyntaxHighlighterAdapter for MockAdapter {
fn write_highlighted(&self, output: &mut dyn fmt::Write, lang: Option<&str>, code: &str) -> fmt::Result {
write!(output, "\n", lang.unwrap(), code)
}
fn write_pre_tag<'s>(&self, output: &mut dyn fmt::Write, _attributes: HashMap<&'static str, Cow<'s, str>>) -> fmt::Result {
output.write_str("")
}
fn write_code_tag<'s>(&self, output: &mut dyn fmt::Write, _attributes: HashMap<&'static str, Cow<'s, str>>) -> fmt::Result {
output.write_str("")
}
}
let adapter = MockAdapter {};
plugins.render.codefence_syntax_highlighter = Some(&adapter);
assert_eq!(markdown_to_html_with_plugins(input, &options, &plugins),
"fn main<'a>();\n
\n");
```
--------------------------------
### NodeEdge
Source: https://docs.rs/comrak/latest/comrak/arena_tree/enum.NodeEdge.html
Represents an edge of the node graph returned by a traversal iterator, indicating start or end of a node with children.
```APIDOC
## NodeEdge
### Description
An edge of the node graph returned by a traversal iterator.
### Declaration
```rust
pub enum NodeEdge {
Start(T),
End(T),
}
```
### Variants
- **Start(T)** - Indicates start of a node that has children. Yielded by `Traverse::next` before the node's descendants. Corresponds to an opening tag like ``.
- **End(T)** - Indicates end of a node that has children. Yielded by `Traverse::next` after the node's descendants. Corresponds to a closing tag like ``.
```
--------------------------------
### Enable superscript extension
Source: https://docs.rs/comrak/latest/comrak/options/struct.Extension.html
Enables the superscript Comrak extension. The example shows that `^2^` becomes `2`.
```rust
let mut options = Options::default();
options.extension.superscript = true;
assert_eq!(markdown_to_html("e = mc^2^.\n", &options),
"e = mc2.
\n");
```
--------------------------------
### github_pre_lang option example
Source: https://docs.rs/comrak/latest/comrak/options/struct.RenderBuilder.html
Shows default output with class="language-rust" and the effect of setting options.render.github_pre_lang = true, which uses .
```rust
let mut options = Options::default();
assert_eq!(markdown_to_html("``` rust\nfn hello();\n```\n", &options),
"fn hello();\n
\n");
options.render.github_pre_lang = true;
assert_eq!(markdown_to_html("``` rust\nfn hello();\n```\n", &options),
"fn hello();\n
\n");
```
--------------------------------
### Enable strikethrough extension
Source: https://docs.rs/comrak/latest/comrak/options/struct.Extension.html
Enables the GFM strikethrough extension. The example shows that `~world~` becomes `world`.
```rust
let mut options = Options::default();
options.extension.strikethrough = true;
assert_eq!(markdown_to_html("Hello ~world~ there.\n", &options),
"Hello world there.
\n");
```
--------------------------------
### Build SyntectAdapter with builder methods
Source: https://docs.rs/comrak/latest/src/comrak/plugins/syntect.rs.html
Defines the SyntectAdapterBuilder with builder methods for theme, CSS classes, syntax set, and theme set. The build method uses defaults: theme None (CSS classes), SyntaxSet::load_defaults_newlines(), and ThemeSet::load_defaults(). The css_with_class_prefix method sets a CSS class prefix.
```rust
#[derive(Debug, Default)]
/// A builder for [`SyntectAdapter`].
///
/// Allows customization of `Theme`, [`ThemeSet`], and [`SyntaxSet`].
pub struct SyntectAdapterBuilder {
theme: Option,
syntax_set: Option,
theme_set: Option,
css_class_prefix: Option<&'static str>,
}
impl SyntectAdapterBuilder {
/// Create a new empty [`SyntectAdapterBuilder`].
pub fn new() -> Self {
Default::default()
}
/// Set the theme.
pub fn theme(mut self, s: &str) -> Self {
self.theme.replace(s.into());
self
}
/// Uses CSS classes instead of a Syntect theme.
pub fn css(mut self) -> Self {
self.theme = None;
self
}
/// Uses CSS classes with the specified prefix instead of a Syntect theme.
pub fn css_with_class_prefix(self, prefix: &'static str) -> Self {
let mut builder = self.css();
builder.css_class_prefix = Some(prefix);
builder
}
/// Set the syntax set.
pub fn syntax_set(mut self, s: SyntaxSet) -> Self {
self.syntax_set.replace(s);
self
}
/// Set the theme set.
pub fn theme_set(mut self, s: ThemeSet) -> Self {
self.theme_set.replace(s);
self
}
/// Builds the [`SyntectAdapter`]. Default values:
/// - `theme`: `None` (uses CSS classes)
/// - `syntax_set`: [`SyntaxSet::load_defaults_newlines()`]
/// - `theme_set`: [`ThemeSet::load_defaults()`]
pub fn build(self) -> SyntectAdapter {
SyntectAdapter {
theme: self.theme,
syntax_set: self
.syntax_set
.unwrap_or_else(SyntaxSet::load_defaults_newlines),
theme_set: self.theme_set.unwrap_or_else(ThemeSet::load_defaults),
css_class_prefix: self.css_class_prefix,
}
}
}
```
--------------------------------
### tasklist_in_table option example
Source: https://docs.rs/comrak/latest/comrak/options/struct.Parse.html
Shows how enabling `options.parse.tasklist_in_table` allows tasklist items to be parsed in table cells, converting `[ ]` to a checkbox.
```rust
let mut options = Options::default();
options.extension.table = true;
options.extension.tasklist = true;
assert_eq!(markdown_to_html("| val |\n| - |\n| [ ] |\n", &options),
"\n\n\nval \n \n\n\n\n[ ] \n \n\n
\n");
options.parse.tasklist_in_table = true;
assert_eq!(markdown_to_html("| val |\n| - |\n| [ ] |\n", &options),
"\n\n\nval \n \n\n\n\n\n \n \n\n
\n");
```
--------------------------------
### render_description_list function
Source: https://docs.rs/comrak/latest/src/comrak/html.rs.html
Begins the rendering of a description list using the tag.
```rust
fn render_description_list(
context: &mut Context,
node: Node<'_>,
entering: bool,
) -> Result {
if entering {
context.cr()?;
context.write_str(" PluginsBuilder<'p>`
### Parameters
None.
### Returns
- `PluginsBuilder<'p>` - A builder for constructing a `Plugins` instance.
### Example
```rust
let plugins = Plugins::builder().build();
```
```
--------------------------------
### Anchorizer uniqueness example
Source: https://docs.rs/comrak/latest/comrak/struct.Anchorizer.html
Demonstrates how Anchorizer handles duplicate header strings by appending a numeric suffix to ensure uniqueness.
```rust
let mut anchorizer = Anchorizer::new();
// First "stuff" is unsuffixed.
assert_eq!("stuff", anchorizer.anchorize("Stuff"));
// Second "stuff" has "-1" appended to make it unique.
assert_eq!("stuff-1", anchorizer.anchorize("Stuff"));
```
--------------------------------
### Enable GitHub-style pre lang for code blocks
Source: https://docs.rs/comrak/latest/comrak/options/struct.Render.html
Demonstrates the default output for fenced code blocks with an info string and the effect of setting `options.render.github_pre_lang = true`, which changes the `` tag to include a `lang` attribute.
```rust
let mut options = Options::default();
assert_eq!(markdown_to_html("``` rust\nfn hello();\n```\n", &options),
"fn hello();\n
\n");
options.render.github_pre_lang = true;
assert_eq!(markdown_to_html("``` rust\nfn hello();\n```\n", &options),
"fn hello();\n
\n");
```
--------------------------------
### find_matching_brace fallback
Source: https://docs.rs/comrak/latest/src/comrak/strings.rs.html
Returns None when no matching brace is found, otherwise recursively calls find_matching_brace with the starting index 1.
```rust
return None;
}
find_matching_brace(s, 1)
}
```
--------------------------------
### Enable underline option
Source: https://docs.rs/comrak/latest/comrak/options/struct.Extension.html
Enables underlines using double underscores. The example shows the markdown input and the expected HTML output.
```markdown
__underlined text__
```
```rust
let mut options = Options::default();
options.extension.underline = true;
assert_eq!(markdown_to_html("__underlined text__", &options),
"underlined text
\n");
```
--------------------------------
### Initialize special character and emphasis delimiter bytes
Source: https://docs.rs/comrak/latest/src/comrak/parser/inlines.rs.html
Sets up special_char_bytes and emph_delim_bytes based on enabled extensions. Enables underscore as special, pipe for spoiler, braces and angle brackets for phoenix_heex, and asterisk/underscore as emphasis delimiters.
```rust
s.special_char_bytes[b'_' as usize] = true;
}
if options.extension.spoiler {
s.special_char_bytes[b'|' as usize] = true;
s.emph_delim_bytes[b'|' as usize] = true;
}
#[cfg(feature = "phoenix_heex")]
if options.extension.phoenix_heex {
s.special_char_bytes[b'{' as usize] = true;
s.special_char_bytes[b'<' as usize] = true;
}
for &b in b"*_" {
s.emph_delim_bytes[b as usize] = true;
}
s
```
--------------------------------
### Enable math_code extension with Rust
Source: https://docs.rs/comrak/latest/comrak/options/struct.ExtensionBuilder.html
Shows the markdown input and Rust code to enable the math_code extension. The Rust code sets options.extension.math_code to true and asserts the expected HTML output for inline and display math.
```markdown
Inline math $`1 + 2`$
```math
x^2
```
```
```rust
let mut options = Options::default();
options.extension.math_code = true;
assert_eq!(markdown_to_html("$`1 + 2`$", &options),
"1 + 2
\n");
assert_eq!(markdown_to_html("```math\nx^2\n```\n", &options),
"x^2\n
\n");
```
--------------------------------
### GitHub Pre-language Option
Source: https://docs.rs/comrak/latest/src/comrak/parser/options.rs.html
Demonstrates the default behavior of code block language rendering.
```rust
assert_eq!(markdown_to_html("``` rust\nfn hello();\n```\n", &options),
"fn hello();\n
\n");
```