Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,16 @@ the file does not exist.
And there's a Rust interface. You can use `comrak::markdown_to_html` directly:

``` rust
use comrak::{markdown_to_html, ComrakOptions};
assert_eq!(markdown_to_html("Hello, **世界**!", &ComrakOptions::default()),
use comrak::{markdown_to_html, Options};
assert_eq!(markdown_to_html("Hello, **世界**!", &Options::default()),
"<p>Hello, <strong>世界</strong>!</p>\n");
```

Or you can parse the input into an AST yourself, manipulate it, and then use your desired formatter:

``` rust
extern crate comrak;
use comrak::{parse_document, format_html, Arena, ComrakOptions};
use comrak::{parse_document, format_html, Arena, Options};
use comrak::nodes::{AstNode, NodeValue};

// The returned nodes are created in the supplied Arena, and are bound by its lifetime.
Expand All @@ -162,7 +162,7 @@ let arena = Arena::new();
let root = parse_document(
&arena,
"This is my input.\n\n1. Also my input.\n2. Certainly my input.\n",
&ComrakOptions::default());
&Options::default());

fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &F)
where F : Fn(&'a AstNode<'a>) {
Expand All @@ -183,7 +183,7 @@ iter_nodes(root, &|node| {
});

let mut html = vec![];
format_html(root, &ComrakOptions::default(), &mut html).unwrap();
format_html(root, &Options::default(), &mut html).unwrap();

assert_eq!(
String::from_utf8(html).unwrap(),
Expand Down Expand Up @@ -224,7 +224,7 @@ Comrak additionally supports its own extensions, which are yet to be specced out
- Shortcodes

By default none are enabled; they are individually enabled with each parse by setting the appropriate values in the
[`ComrakOptions` struct](https://docs.rs/comrak/newest/comrak/struct.ComrakOptions.html).
[`Options` struct](https://docs.rs/comrak/newest/comrak/struct.Options.html).

## Plugins

Expand All @@ -233,7 +233,7 @@ By default none are enabled; they are individually enabled with each parse by se
At the moment syntax highlighting of codefence blocks is the only feature that can be enhanced with plugins.

Create an implementation of the `SyntaxHighlighterAdapter` trait, and then provide an instance of such adapter to
`ComrakPlugins.render.codefence_syntax_highlighter`. For formatting a markdown document with plugins, use the
`Plugins.render.codefence_syntax_highlighter`. For formatting a markdown document with plugins, use the
`markdown_to_html_with_plugins` function, which accepts your plugin as a parameter.

See the `syntax_highlighter.rs` and `syntect.rs` examples for more details.
Expand All @@ -242,7 +242,7 @@ See the `syntax_highlighter.rs` and `syntect.rs` examples for more details.

[`syntect`](https://github.com/trishume/syntect) is a syntax highlighting library for Rust. By default, `comrak` offers
a plugin for it. In order to utilize it, create an instance of `plugins::syntect::SyntectAdapter` and use it as your
`ComrakPlugins` option.
`Plugins` option.

## Related projects

Expand Down
6 changes: 3 additions & 3 deletions benches/progit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

extern crate test;

use comrak::{format_html, parse_document, Arena, ComrakOptions};
use comrak::{format_html, parse_document, Arena, Options};
use test::Bencher;

#[bench]
Expand All @@ -15,8 +15,8 @@ fn bench_progit(b: &mut Bencher) {
file.read_to_string(&mut s).unwrap();
b.iter(|| {
let arena = Arena::new();
let root = parse_document(&arena, &s, &ComrakOptions::default());
let root = parse_document(&arena, &s, &Options::default());
let mut output = vec![];
format_html(root, &ComrakOptions::default(), &mut output).unwrap()
format_html(root, &Options::default(), &mut output).unwrap()
});
}
8 changes: 4 additions & 4 deletions examples/custom_headings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use comrak::{
adapters::{HeadingAdapter, HeadingMeta},
markdown_to_html_with_plugins,
nodes::Sourcepos,
ComrakOptions, ComrakPlugins,
Options, Plugins,
};
use std::io::{self, Write};

fn main() {
let adapter = CustomHeadingAdapter;
let mut options = ComrakOptions::default();
let mut plugins = ComrakPlugins::default();
let mut options = Options::default();
let mut plugins = Plugins::default();
plugins.render.heading_adapter = Some(&adapter);

print_html(
Expand Down Expand Up @@ -62,7 +62,7 @@ impl HeadingAdapter for CustomHeadingAdapter {
}
}

fn print_html(document: &str, options: &ComrakOptions, plugins: &ComrakPlugins) {
fn print_html(document: &str, options: &Options, plugins: &Plugins) {
let html = markdown_to_html_with_plugins(document, options, plugins);
println!("{}", html);
}
4 changes: 2 additions & 2 deletions examples/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use comrak::{
nodes::{AstNode, NodeCode, NodeValue},
parse_document, Arena, ComrakOptions,
parse_document, Arena, Options,
};

fn main() {
Expand All @@ -13,7 +13,7 @@ fn main() {

fn get_document_title(document: &str) -> String {
let arena = Arena::new();
let root = parse_document(&arena, document, &ComrakOptions::default());
let root = parse_document(&arena, document, &Options::default());

for node in root.children() {
let header = match node.data.clone().into_inner().value {
Expand Down
10 changes: 5 additions & 5 deletions examples/s-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const INDENT: usize = 4;
const CLOSE_NEWLINE: bool = false;

use comrak::nodes::{AstNode, NodeValue};
use comrak::{parse_document, Arena, ComrakExtensionOptions, ComrakOptions};
use comrak::{parse_document, Arena, ExtensionOptions, Options};
use std::env;
use std::error::Error;
use std::fs::File;
Expand Down Expand Up @@ -74,8 +74,8 @@ fn iter_nodes<'a, W: Write>(
fn dump(source: &str) -> io::Result<()> {
let arena = Arena::new();

let opts = ComrakOptions {
extension: ComrakExtensionOptions {
let opts = Options {
extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
Expand All @@ -84,9 +84,9 @@ fn dump(source: &str) -> io::Result<()> {
superscript: true,
footnotes: true,
description_lists: true,
..ComrakExtensionOptions::default()
..ExtensionOptions::default()
},
..ComrakOptions::default()
..Options::default()
};

let doc = parse_document(&arena, source, &opts);
Expand Down
10 changes: 5 additions & 5 deletions examples/sample.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// Samples used in the README. Wanna make sure they work as advertised.

fn small() {
use comrak::{markdown_to_html, ComrakOptions};
use comrak::{markdown_to_html, Options};

assert_eq!(
markdown_to_html("Hello, **世界**!", &ComrakOptions::default()),
markdown_to_html("Hello, **世界**!", &Options::default()),
"<p>Hello, <strong>世界</strong>!</p>\n"
);
}

fn large() {
use comrak::nodes::{AstNode, NodeValue};
use comrak::{format_html, parse_document, Arena, ComrakOptions};
use comrak::{format_html, parse_document, Arena, Options};

// The returned nodes are created in the supplied Arena, and are bound by its lifetime.
let arena = Arena::new();

let root = parse_document(
&arena,
"This is my input.\n\n1. Also my input.\n2. Certainly my input.\n",
&ComrakOptions::default(),
&Options::default(),
);

fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &F)
Expand All @@ -40,7 +40,7 @@ fn large() {
});

let mut html = vec![];
format_html(root, &ComrakOptions::default(), &mut html).unwrap();
format_html(root, &Options::default(), &mut html).unwrap();

assert_eq!(
String::from_utf8(html).unwrap(),
Expand Down
6 changes: 3 additions & 3 deletions examples/syntax_highlighter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This example shows how to implement a syntax highlighter plugin.

use comrak::adapters::SyntaxHighlighterAdapter;
use comrak::{markdown_to_html_with_plugins, ComrakOptions, ComrakPlugins};
use comrak::{markdown_to_html_with_plugins, Options, Plugins};
use std::collections::HashMap;
use std::io::{self, Write};

Expand Down Expand Up @@ -59,8 +59,8 @@ impl SyntaxHighlighterAdapter for PotatoSyntaxAdapter {

fn main() {
let adapter = PotatoSyntaxAdapter::new(42);
let options = ComrakOptions::default();
let mut plugins = ComrakPlugins::default();
let options = Options::default();
let mut plugins = Plugins::default();

plugins.render.codefence_syntax_highlighter = Some(&adapter);

Expand Down
6 changes: 3 additions & 3 deletions examples/syntect.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! This example shows how to use the bundled syntect plugin.

use comrak::plugins::syntect::SyntectAdapter;
use comrak::{markdown_to_html_with_plugins, ComrakOptions, ComrakPlugins};
use comrak::{markdown_to_html_with_plugins, Options, Plugins};

fn main() {
let adapter = SyntectAdapter::new("base16-ocean.dark");
let options = ComrakOptions::default();
let mut plugins = ComrakPlugins::default();
let options = Options::default();
let mut plugins = Plugins::default();

plugins.render.codefence_syntax_highlighter = Some(&adapter);

Expand Down
6 changes: 3 additions & 3 deletions examples/update-readme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt::Write;
use std::str;

use comrak::nodes::{AstNode, NodeValue};
use comrak::{format_commonmark, parse_document, Arena, ComrakOptions};
use comrak::{format_commonmark, parse_document, Arena, Options};

const DEPENDENCIES: &str = "[dependencies]\ncomrak = ";
const HELP: &str = "$ comrak --help\n";
Expand All @@ -13,7 +13,7 @@ fn main() -> Result<(), Box<dyn std::error::Error + 'static>> {
let arena = Arena::new();

let readme = std::fs::read_to_string("README.md")?;
let doc = parse_document(&arena, &readme, &ComrakOptions::default());
let doc = parse_document(&arena, &readme, &Options::default());

fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &F)
where
Expand Down Expand Up @@ -56,7 +56,7 @@ fn main() -> Result<(), Box<dyn std::error::Error + 'static>> {
});

let mut out = vec![];
format_commonmark(doc, &ComrakOptions::default(), &mut out).unwrap();
format_commonmark(doc, &Options::default(), &mut out).unwrap();

std::fs::write("README.md", &out)?;

Expand Down
12 changes: 6 additions & 6 deletions fuzz/fuzz_targets/all_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
use libfuzzer_sys::fuzz_target;

use comrak::{
markdown_to_html, ComrakExtensionOptions, ComrakOptions, ComrakParseOptions,
ComrakRenderOptions, ListStyleType,
markdown_to_html, ExtensionOptions, Options, ParseOptions,
RenderOptions, ListStyleType,
};

fuzz_target!(|s: &str| {
markdown_to_html(
s,
&ComrakOptions {
extension: ComrakExtensionOptions {
&Options {
extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
Expand All @@ -24,12 +24,12 @@ fuzz_target!(|s: &str| {
front_matter_delimiter: Some("---".to_string()),
shortcodes: true,
},
parse: ComrakParseOptions {
parse: ParseOptions {
smart: true,
default_info_string: Some("rust".to_string()),
relaxed_tasklist_matching: true,
},
render: ComrakRenderOptions {
render: RenderOptions {
hardbreaks: true,
github_pre_lang: true,
full_info_string: true,
Expand Down
8 changes: 4 additions & 4 deletions fuzz/fuzz_targets/cli_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
use libfuzzer_sys::fuzz_target;

use comrak::{
markdown_to_html_with_plugins, plugins::syntect::SyntectAdapter, ComrakPlugins,
ComrakRenderPlugins,
markdown_to_html_with_plugins, plugins::syntect::SyntectAdapter, Plugins,
RenderPlugins,
};

// Note that we end up fuzzing Syntect here.

fuzz_target!(|s: &str| {
let adapter = SyntectAdapter::new("base16-ocean.dark");
let plugins = ComrakPlugins {
render: ComrakRenderPlugins {
let plugins = Plugins {
render: RenderPlugins {
codefence_syntax_highlighter: Some(&adapter),
..Default::default()
},
Expand Down
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/fuzz_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

use libfuzzer_sys::fuzz_target;

use comrak::{markdown_to_html, ComrakOptions};
use comrak::{markdown_to_html, Options};

#[derive(Debug, arbitrary::Arbitrary)]
struct FuzzInput<'s> {
s: &'s str,
opts: ComrakOptions,
opts: Options,
}

fuzz_target!(|i: FuzzInput| {
Expand Down
8 changes: 4 additions & 4 deletions fuzz/fuzz_targets/gfm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use libfuzzer_sys::fuzz_target;

use comrak::{markdown_to_html, ComrakExtensionOptions, ComrakOptions, ComrakRenderOptions};
use comrak::{markdown_to_html, ExtensionOptions, Options, RenderOptions};

// Note that what I'm targetting here isn't exactly the same
// as --gfm, but rather an approximation of what cmark-gfm
Expand All @@ -11,16 +11,16 @@ use comrak::{markdown_to_html, ComrakExtensionOptions, ComrakOptions, ComrakRend
fuzz_target!(|s: &str| {
markdown_to_html(
s,
&ComrakOptions {
extension: ComrakExtensionOptions {
&Options {
extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
autolink: true,
..Default::default()
},
parse: Default::default(),
render: ComrakRenderOptions {
render: RenderOptions {
hardbreaks: true,
github_pre_lang: true,
unsafe_: true,
Expand Down
8 changes: 4 additions & 4 deletions fuzz/fuzz_targets/gfm_footnotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use libfuzzer_sys::fuzz_target;

use comrak::{markdown_to_html, ComrakExtensionOptions, ComrakOptions, ComrakRenderOptions};
use comrak::{markdown_to_html, ExtensionOptions, Options, RenderOptions};

// Note that what I'm targetting here isn't exactly the same
// as --gfm, but rather an approximation of what cmark-gfm
Expand All @@ -11,8 +11,8 @@ use comrak::{markdown_to_html, ComrakExtensionOptions, ComrakOptions, ComrakRend
fuzz_target!(|s: &str| {
markdown_to_html(
s,
&ComrakOptions {
extension: ComrakExtensionOptions {
&Options {
extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
Expand All @@ -21,7 +21,7 @@ fuzz_target!(|s: &str| {
..Default::default()
},
parse: Default::default(),
render: ComrakRenderOptions {
render: RenderOptions {
hardbreaks: true,
github_pre_lang: true,
unsafe_: true,
Expand Down
Loading