Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
8 changes: 4 additions & 4 deletions examples/update-readme.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Update the "comrak --help" text in Comrak's own README.
// Update the "comrak --help" text in 's own README.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A reminder to me to fix this up pre-merge and do another once-over.

Suggested change
// Update the "comrak --help" text in 's own README.
// Update the "comrak --help" text in Comrak's own README.


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
16 changes: 8 additions & 8 deletions src/cm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ use crate::nodes::{
};
#[cfg(feature = "shortcodes")]
use crate::parser::shortcodes::NodeShortCode;
use crate::parser::ComrakOptions;
use crate::parser::Options;
use crate::scanners;
use crate::strings::trim_start_match;
use crate::{nodes, ComrakPlugins};
use crate::{nodes, Plugins};

use std::cmp::max;
use std::io::{self, Write};

/// Formats an AST as CommonMark, modified by the given options.
pub fn format_document<'a>(
root: &'a AstNode<'a>,
options: &ComrakOptions,
options: &Options,
output: &mut dyn Write,
) -> io::Result<()> {
format_document_with_plugins(root, options, output, &ComrakPlugins::default())
format_document_with_plugins(root, options, output, &Plugins::default())
}

/// Formats an AST as CommonMark, modified by the given options. Accepts custom plugins.
pub fn format_document_with_plugins<'a>(
root: &'a AstNode<'a>,
options: &ComrakOptions,
options: &Options,
output: &mut dyn Write,
_plugins: &ComrakPlugins,
_plugins: &Plugins,
) -> io::Result<()> {
let mut f = CommonMarkFormatter::new(root, options);
f.format(root);
Expand All @@ -41,7 +41,7 @@ pub fn format_document_with_plugins<'a>(

struct CommonMarkFormatter<'a, 'o> {
node: &'a AstNode<'a>,
options: &'o ComrakOptions,
options: &'o Options,
v: Vec<u8>,
prefix: Vec<u8>,
column: usize,
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<'a, 'o> Write for CommonMarkFormatter<'a, 'o> {
}

impl<'a, 'o> CommonMarkFormatter<'a, 'o> {
fn new(node: &'a AstNode<'a>, options: &'o ComrakOptions) -> Self {
fn new(node: &'a AstNode<'a>, options: &'o Options) -> Self {
CommonMarkFormatter {
node,
options,
Expand Down
20 changes: 8 additions & 12 deletions src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::ctype::isspace;
use crate::nodes::{
AstNode, ListType, NodeCode, NodeFootnoteDefinition, NodeValue, TableAlignment,
};
use crate::parser::{ComrakOptions, ComrakPlugins};
use crate::parser::{Options, Plugins};
use crate::scanners;
use once_cell::sync::Lazy;
use regex::Regex;
Expand All @@ -18,18 +18,18 @@ use crate::adapters::HeadingMeta;
/// Formats an AST as HTML, modified by the given options.
pub fn format_document<'a>(
root: &'a AstNode<'a>,
options: &ComrakOptions,
options: &Options,
output: &mut dyn Write,
) -> io::Result<()> {
format_document_with_plugins(root, options, output, &ComrakPlugins::default())
format_document_with_plugins(root, options, output, &Plugins::default())
}

/// Formats an AST as HTML, modified by the given options. Accepts custom plugins.
pub fn format_document_with_plugins<'a>(
root: &'a AstNode<'a>,
options: &ComrakOptions,
options: &Options,
output: &mut dyn Write,
plugins: &ComrakPlugins,
plugins: &Plugins,
) -> io::Result<()> {
let mut writer = WriteWithLast {
output,
Expand Down Expand Up @@ -131,11 +131,11 @@ impl Anchorizer {

struct HtmlFormatter<'o> {
output: &'o mut WriteWithLast<'o>,
options: &'o ComrakOptions,
options: &'o Options,
anchorizer: Anchorizer,
footnote_ix: u32,
written_footnote_ix: u32,
plugins: &'o ComrakPlugins<'o>,
plugins: &'o Plugins<'o>,
}

#[rustfmt::skip]
Expand Down Expand Up @@ -365,11 +365,7 @@ where
}

impl<'o> HtmlFormatter<'o> {
fn new(
options: &'o ComrakOptions,
output: &'o mut WriteWithLast<'o>,
plugins: &'o ComrakPlugins,
) -> Self {
fn new(options: &'o Options, output: &'o mut WriteWithLast<'o>, plugins: &'o Plugins) -> Self {
HtmlFormatter {
options,
output,
Expand Down
Loading