diff -Nru rust-comrak-0.18.0/.cargo_vcs_info.json rust-comrak-0.20.0/.cargo_vcs_info.json
--- rust-comrak-0.18.0/.cargo_vcs_info.json 1970-01-01 00:00:01.000000000 +0000
+++ rust-comrak-0.20.0/.cargo_vcs_info.json 1970-01-01 00:00:01.000000000 +0000
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "8fc0bee486370f5a8512382745bb29b3ba713e97"
+ "sha1": "4c909b654cfd3600ab3e96c7186228ba7c8f79cd"
},
"path_in_vcs": ""
}
\ No newline at end of file
diff -Nru rust-comrak-0.18.0/.github/workflows/benchmarks.yml rust-comrak-0.20.0/.github/workflows/benchmarks.yml
--- rust-comrak-0.18.0/.github/workflows/benchmarks.yml 1970-01-01 00:00:00.000000000 +0000
+++ rust-comrak-0.20.0/.github/workflows/benchmarks.yml 2006-07-24 01:21:28.000000000 +0000
@@ -0,0 +1,36 @@
+name: benchmarks
+
+on:
+ pull_request:
+ types:
+ - opened
+ - reopened
+ issue_comment:
+ types:
+ - created
+
+jobs:
+ run_benchmarks:
+ runs-on: ubuntu-latest
+ permissions:
+ pull-requests: write
+ # run either when pull request is opened or when comment body (only on pr) is /run-bench
+ if: (github.event_name == 'pull_request') || ((github.event.issue.pull_request != null) && github.event.comment.body == '/run-bench')
+ steps:
+ - uses: actions/checkout@v3
+ with:
+ submodules: true
+ - name: Setup Rust toolchain
+ uses: dtolnay/rust-toolchain@stable
+ - name: Install hyperfine
+ run: cargo install hyperfine
+ - name: Install cmake
+ run: sudo apt-get update && sudo apt-get install cmake -y
+ - name: Build Binaries
+ run: make binaries
+ - name: Run Benchmarks
+ run: make bench-all
+ - name: Post result comment
+ uses: mshick/add-pr-comment@v2
+ with:
+ message-path: bench-output.md
\ No newline at end of file
diff -Nru rust-comrak-0.18.0/.github/workflows/rust.yml rust-comrak-0.20.0/.github/workflows/rust.yml
--- rust-comrak-0.18.0/.github/workflows/rust.yml 2006-07-24 01:21:28.000000000 +0000
+++ rust-comrak-0.20.0/.github/workflows/rust.yml 2006-07-24 01:21:28.000000000 +0000
@@ -79,17 +79,16 @@
run: cargo +stable build --locked --release --all-features
clippy_format:
runs-on: ubuntu-latest
- strategy:
- matrix:
- rust:
- - stable
steps:
- - uses: actions/checkout@v1
+ - uses: actions/checkout@v3
with:
submodules: true
- - name: Obtain Rust
- run: rustup override set ${{ matrix.rust }}
+ - uses: actions/checkout@v3
+ - name: Install Nix
+ uses: DeterminateSystems/nix-installer-action@v4
+ - name: Run the Magic Nix Cache
+ uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Check clippy
- run: rustup component add clippy && cargo clippy
+ run: nix build .#checks.x86_64-linux.comrak-clippy -L
- name: Check formatting
- run: rustup component add rustfmt && cargo fmt -- --check
+ run: nix build .#checks.x86_64-linux.comrak-fmt -L
diff -Nru rust-comrak-0.18.0/.gitignore rust-comrak-0.20.0/.gitignore
--- rust-comrak-0.18.0/.gitignore 2006-07-24 01:21:28.000000000 +0000
+++ rust-comrak-0.20.0/.gitignore 2006-07-24 01:21:28.000000000 +0000
@@ -1,3 +1,11 @@
target
comrak-*
.vscode
+.idea
+vendor/comrak
+vendor/progit
+benches/cmark-gfm
+benches/comrak-*
+benches/pulldown-cmark
+benches/markdown-it
+/result*
diff -Nru rust-comrak-0.18.0/.gitmodules rust-comrak-0.20.0/.gitmodules
--- rust-comrak-0.18.0/.gitmodules 2006-07-24 01:21:28.000000000 +0000
+++ rust-comrak-0.20.0/.gitmodules 2006-07-24 01:21:28.000000000 +0000
@@ -1,3 +1,9 @@
[submodule "vendor/cmark-gfm"]
path = vendor/cmark-gfm
- url = https://github.com/kivikakk/cmark-gfm.git
+ url = https://github.com/github/cmark-gfm.git
+[submodule "vendor/pulldown-cmark"]
+ path = vendor/pulldown-cmark
+ url = https://github.com/raphlinus/pulldown-cmark.git
+[submodule "vendor/markdown-it"]
+ path = vendor/markdown-it
+ url = https://github.com/rlidwka/markdown-it.rs.git
diff -Nru rust-comrak-0.18.0/Cargo.lock rust-comrak-0.20.0/Cargo.lock
--- rust-comrak-0.18.0/Cargo.lock 1970-01-01 00:00:01.000000000 +0000
+++ rust-comrak-0.20.0/Cargo.lock 1970-01-01 00:00:01.000000000 +0000
@@ -126,10 +126,11 @@
[[package]]
name = "comrak"
-version = "0.18.0"
+version = "0.20.0"
dependencies = [
"arbitrary",
"clap",
+ "derive_builder",
"emojis",
"entities",
"memchr",
@@ -155,6 +156,41 @@
]
[[package]]
+name = "darling"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850"
+dependencies = [
+ "darling_core",
+ "darling_macro",
+]
+
+[[package]]
+name = "darling_core"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0"
+dependencies = [
+ "fnv",
+ "ident_case",
+ "proc-macro2",
+ "quote",
+ "strsim",
+ "syn",
+]
+
+[[package]]
+name = "darling_macro"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
+dependencies = [
+ "darling_core",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "derive_arbitrary"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -166,6 +202,37 @@
]
[[package]]
+name = "derive_builder"
+version = "0.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8"
+dependencies = [
+ "derive_builder_macro",
+]
+
+[[package]]
+name = "derive_builder_core"
+version = "0.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f"
+dependencies = [
+ "darling",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "derive_builder_macro"
+version = "0.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e"
+dependencies = [
+ "derive_builder_core",
+ "syn",
+]
+
+[[package]]
name = "deunicode"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -306,6 +373,12 @@
]
[[package]]
+name = "ident_case"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
+
+[[package]]
name = "indexmap"
version = "1.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -557,9 +630,9 @@
[[package]]
name = "proc-macro2"
-version = "1.0.49"
+version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
+checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da"
dependencies = [
"unicode-ident",
]
@@ -1087,9 +1160,9 @@
[[package]]
name = "xml-rs"
-version = "0.8.4"
+version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3"
+checksum = "52839dc911083a8ef63efa4d039d1f58b5e409f923e44c80828f206f66e5541c"
[[package]]
name = "yaml-rust"
diff -Nru rust-comrak-0.18.0/Cargo.toml rust-comrak-0.20.0/Cargo.toml
--- rust-comrak-0.18.0/Cargo.toml 1970-01-01 00:00:01.000000000 +0000
+++ rust-comrak-0.20.0/Cargo.toml 1970-01-01 00:00:01.000000000 +0000
@@ -12,7 +12,7 @@
[package]
edition = "2018"
name = "comrak"
-version = "0.18.0"
+version = "0.20.0"
authors = ["Asherah Connor Hello, 世界! Hello, 世界!
Hello, 世界!
\n"); //! ``` //! @@ -16,7 +16,7 @@ //! formatter: //! //! ``` -//! use comrak::{Arena, parse_document, format_html, ComrakOptions}; +//! use comrak::{Arena, parse_document, format_html, Options}; //! use comrak::nodes::{AstNode, NodeValue}; //! //! # fn main() { @@ -26,7 +26,7 @@ //! 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>) { @@ -47,7 +47,7 @@ //! }); //! //! 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(), @@ -59,6 +59,7 @@ //! # } //! ``` +#![cfg_attr(docsrs, feature(doc_cfg))] #![deny( missing_docs, missing_debug_implementations, @@ -99,29 +100,38 @@ pub use html::format_document_with_plugins as format_html_with_plugins; pub use html::Anchorizer; pub use parser::{ - parse_document, parse_document_with_broken_link_callback, ComrakExtensionOptions, - ComrakOptions, ComrakParseOptions, ComrakPlugins, ComrakRenderOptions, ComrakRenderPlugins, - ListStyleType, + parse_document, parse_document_with_broken_link_callback, ExtensionOptions, + ExtensionOptionsBuilder, ListStyleType, Options, ParseOptions, ParseOptionsBuilder, Plugins, + PluginsBuilder, RenderOptions, RenderOptionsBuilder, RenderPlugins, RenderPluginsBuilder, }; pub use typed_arena::Arena; pub use xml::format_document as format_xml; pub use xml::format_document_with_plugins as format_xml_with_plugins; +/// Legacy naming of [`ExtensionOptions`] +pub type ComrakExtensionOptions = ExtensionOptions; +/// Legacy naming of [`Options`] +pub type ComrakOptions = Options; +/// Legacy naming of [`ParseOptions`] +pub type ComrakParseOptions = ParseOptions; +/// Legacy naming of [`Plugins`] +pub type ComrakPlugins<'a> = Plugins<'a>; +/// Legacy naming of [`RenderOptions`] +pub type ComrakRenderOptions = RenderOptions; +/// Legacy naming of [`RenderPlugins`] +pub type ComrakRenderPlugins<'a> = RenderPlugins<'a>; + /// Render Markdown to HTML. /// /// See the documentation of the crate root for an example. -pub fn markdown_to_html(md: &str, options: &ComrakOptions) -> String { - markdown_to_html_with_plugins(md, options, &ComrakPlugins::default()) +pub fn markdown_to_html(md: &str, options: &Options) -> String { + markdown_to_html_with_plugins(md, options, &Plugins::default()) } /// Render Markdown to HTML using plugins. /// /// See the documentation of the crate root for an example. -pub fn markdown_to_html_with_plugins( - md: &str, - options: &ComrakOptions, - plugins: &ComrakPlugins, -) -> String { +pub fn markdown_to_html_with_plugins(md: &str, options: &Options, plugins: &Plugins) -> String { let arena = Arena::new(); let root = parse_document(&arena, md, options); let mut bw = BufWriter::new(Vec::new()); @@ -135,7 +145,7 @@ } /// Render Markdown back to CommonMark. -pub fn markdown_to_commonmark(md: &str, options: &ComrakOptions) -> String { +pub fn markdown_to_commonmark(md: &str, options: &Options) -> String { let arena = Arena::new(); let root = parse_document(&arena, md, options); let mut bw = BufWriter::new(Vec::new()); @@ -145,16 +155,16 @@ /// Render Markdown to CommonMark XML. /// See https://github.com/commonmark/commonmark-spec/blob/master/CommonMark.dtd. -pub fn markdown_to_commonmark_xml(md: &str, options: &ComrakOptions) -> String { - markdown_to_commonmark_xml_with_plugins(md, options, &ComrakPlugins::default()) +pub fn markdown_to_commonmark_xml(md: &str, options: &Options) -> String { + markdown_to_commonmark_xml_with_plugins(md, options, &Plugins::default()) } /// Render Markdown to CommonMark XML using plugins. /// See https://github.com/commonmark/commonmark-spec/blob/master/CommonMark.dtd. pub fn markdown_to_commonmark_xml_with_plugins( md: &str, - options: &ComrakOptions, - plugins: &ComrakPlugins, + options: &Options, + plugins: &Plugins, ) -> String { let arena = Arena::new(); let root = parse_document(&arena, md, options); diff -Nru rust-comrak-0.18.0/src/main.rs rust-comrak-0.20.0/src/main.rs --- rust-comrak-0.18.0/src/main.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-comrak-0.20.0/src/main.rs 2006-07-24 01:21:28.000000000 +0000 @@ -2,8 +2,8 @@ use comrak::{ adapters::SyntaxHighlighterAdapter, plugins::syntect::SyntectAdapter, Arena, - ComrakExtensionOptions, ComrakOptions, ComrakParseOptions, ComrakPlugins, ComrakRenderOptions, - ListStyleType, + ExtensionOptionsBuilder, ListStyleType, Options, ParseOptionsBuilder, Plugins, + RenderOptionsBuilder, }; use std::boxed::Box; use std::env; @@ -60,6 +60,10 @@ #[arg(long)] relaxed_tasklist_character: bool, + /// Enable relaxing of autolink parsing, allowing links to be recognized when in brackets + #[arg(long)] + relaxed_autolinks: bool, + /// Default value for fenced code block's info strings if none is given #[arg(long, value_name = "INFO")] default_info_string: OptionWow look at this cool \
/// link. \
@@ -93,7 +100,7 @@
pub fn parse_document_with_broken_link_callback<'a, 'c>(
arena: &'a Arena Hello Hello www.github.com. e = mc2. Hi1. A greeting. ↩ Hi1. A greeting. ↩ Definition Happy Friday! :smile: 'Hello,' "world" ... [https://foo.com] Hello.\nWorld. [https://foo.com] [[https://foo.com]] [[Foo|https://foo.com]] [[https://foo.com]] [[Foo|https://foo.com]] Where are you going? Here is a[^nowhere] footnote reference,1 and another.2 This is another note.3 This is another note.3 And footnote2 is referenced again. This is regular content. Here is the footnote. ↩ Here's one with multiple blocks. Subsequent paragraphs are indented. Hi. ↩ Hi. ↩ Here's my footnote!1 Here's my footnote!1 Here is a footnote reference.1 Here is a longer footnote reference.2 Here is a longer footnote reference.2 e = mc2. Here is a footnote reference.1 Here is a footnote reference.1 and 1 Foo.1 Here is the footnote. ↩ Foo.[^] [^]: Here is the footnote. Foo.[^one two] [^one two]: Here is the footnote. Foo1 bar ↩ {}", input);
+ // Right-most space is trimmed in output.
+ exp.pop();
+ exp += " {} {}", s);
- // Right-most space is trimmed in output.
- exp.pop();
- exp += "world there.\n\n
\n \n\n\
@@ -198,8 +207,8 @@
/// from the GFM spec.
///
/// ```
- /// # use comrak::{markdown_to_html, ComrakOptions};
- /// let mut options = ComrakOptions::default();
+ /// # use comrak::{markdown_to_html, Options};
+ /// let mut options = Options::default();
/// options.extension.autolink = true;
/// assert_eq!(markdown_to_html("Hello www.github.com.\n", &options),
/// "a \nb \n\n
\n
\n");
/// ```
pub tasklist: bool,
@@ -227,8 +236,8 @@
/// Enables the superscript Comrak extension.
///
/// ```
- /// # use comrak::{markdown_to_html, ComrakOptions};
- /// let mut options = ComrakOptions::default();
+ /// # use comrak::{markdown_to_html, Options};
+ /// let mut options = Options::default();
/// options.extension.superscript = true;
/// assert_eq!(markdown_to_html("e = mc^2^.\n", &options),
/// "README
\n");
@@ -252,11 +261,11 @@
/// [Kramdown](https://kramdown.gettalong.org/syntax.html#footnotes).
///
/// ```
- /// # use comrak::{markdown_to_html, ComrakOptions};
- /// let mut options = ComrakOptions::default();
+ /// # use comrak::{markdown_to_html, Options};
+ /// let mut options = Options::default();
/// options.extension.footnotes = true;
/// assert_eq!(markdown_to_html("Hi[^x].\n\n[^x]: A greeting.\n", &options),
- /// "\n
\n\n
\n
\n");
@@ -306,18 +315,18 @@
/// ```
///
/// ```
- /// # use comrak::{markdown_to_html, ComrakOptions};
- /// let mut options = ComrakOptions::default();
+ /// # use comrak::{markdown_to_html, Options};
+ /// let mut options = Options::default();
/// options.extension.front_matter_delimiter = Some("---".to_owned());
/// assert_eq!(
/// markdown_to_html("---\nlayout: post\n---\nText\n", &options),
- /// markdown_to_html("Text\n", &ComrakOptions::default()));
+ /// markdown_to_html("Text\n", &Options::default()));
/// ```
///
/// ```
- /// # use comrak::{format_commonmark, Arena, ComrakOptions};
+ /// # use comrak::{format_commonmark, Arena, Options};
/// use comrak::parse_document;
- /// let mut options = ComrakOptions::default();
+ /// let mut options = Options::default();
/// options.extension.front_matter_delimiter = Some("---".to_owned());
/// let arena = Arena::new();
/// let input ="---\nlayout: post\n---\nText\n";
@@ -329,12 +338,12 @@
pub front_matter_delimiter: Option
\n");
///
@@ -379,18 +390,35 @@
/// Whether or not a simple `x` or `X` is used for tasklist or any other symbol is allowed.
pub relaxed_tasklist_matching: bool,
+
+ /// Relax parsing of autolinks, allowing links to be detected inside brackets.
+ ///
+ /// ```
+ /// # use comrak::{markdown_to_html, Options};
+ /// let mut options = Options::default();
+ /// options.extension.autolink = true;
+ /// assert_eq!(markdown_to_html("[https://foo.com]", &options),
+ /// "fn hello();\n
` is used for fenced code blocks with info tags.
///
/// ```
- /// # use comrak::{markdown_to_html, ComrakOptions};
- /// let mut options = ComrakOptions::default();
+ /// # use comrak::{markdown_to_html, Options};
+ /// let mut options = Options::default();
/// assert_eq!(markdown_to_html("``` rust\nfn hello();\n```\n", &options),
/// "
\n");
///
@@ -417,8 +445,8 @@
/// Enable full info strings for code blocks
///
/// ```
- /// # use comrak::{markdown_to_html, ComrakOptions};
- /// let mut options = ComrakOptions::default();
+ /// # use comrak::{markdown_to_html, Options};
+ /// let mut options = Options::default();
/// assert_eq!(markdown_to_html("``` rust extra info\nfn hello();\n```\n", &options),
/// "fn hello();\n
\n");
///
@@ -432,10 +460,10 @@
/// The wrap column when outputting CommonMark.
///
/// ```
- /// # use comrak::{parse_document, ComrakOptions, format_commonmark};
+ /// # use comrak::{parse_document, Options, format_commonmark};
/// # fn main() {
/// # let arena = typed_arena::Arena::new();
- /// let mut options = ComrakOptions::default();
+ /// let mut options = Options::default();
/// let node = parse_document(&arena, "hello hello hello hello hello hello", &options);
/// let mut output = vec![];
/// format_commonmark(node, &options, &mut output).unwrap();
@@ -454,8 +482,8 @@
/// Allow rendering of raw HTML and potentially dangerous links.
///
/// ```
- /// # use comrak::{markdown_to_html, ComrakOptions};
- /// let mut options = ComrakOptions::default();
+ /// # use comrak::{markdown_to_html, Options};
+ /// let mut options = Options::default();
/// let input = "\n\n\
/// Possibly .\n\n\
/// [Dangerous](javascript:alert(document.cookie)).\n\n\
@@ -478,8 +506,8 @@
/// Escape raw HTML instead of clobbering it.
/// ```
- /// # use comrak::{markdown_to_html, ComrakOptions};
- /// let mut options = ComrakOptions::default();
+ /// # use comrak::{markdown_to_html, Options};
+ /// let mut options = Options::default();
/// let input = "italic text";
///
/// assert_eq!(markdown_to_html(input, &options),
@@ -498,8 +526,8 @@
/// * `ListStyleType::Star` to use `*`
///
/// ```rust
- /// # use comrak::{markdown_to_commonmark, ComrakOptions, ListStyleType};
- /// let mut options = ComrakOptions::default();
+ /// # use comrak::{markdown_to_commonmark, Options, ListStyleType};
+ /// let mut options = Options::default();
/// let input = "- one\n- two\n- three";
/// assert_eq!(markdown_to_commonmark(input, &options),
/// "- one\n- two\n- three\n"); // default is Dash
@@ -519,8 +547,8 @@
/// Not yet compatible with extension.description_lists.
///
/// ```rust
- /// # use comrak::{markdown_to_commonmark_xml, ComrakOptions};
- /// let mut options = ComrakOptions::default();
+ /// # use comrak::{markdown_to_commonmark_xml, Options};
+ /// let mut options = Options::default();
/// options.render.sourcepos = true;
/// let input = "Hello *world*!";
/// let xml = markdown_to_commonmark_xml(input, &options);
@@ -529,25 +557,29 @@
pub sourcepos: bool,
}
-#[derive(Default, Debug)]
+#[non_exhaustive]
+#[derive(Default, Debug, Clone, Builder)]
+#[builder(default)]
/// Umbrella plugins struct.
-pub struct ComrakPlugins<'p> {
+pub struct Plugins<'p> {
/// Configure render-time plugins.
- pub render: ComrakRenderPlugins<'p>,
+ pub render: RenderPlugins<'p>,
}
-#[derive(Default)]
+#[non_exhaustive]
+#[derive(Default, Clone, Builder)]
+#[builder(default)]
/// Plugins for alternative rendering.
-pub struct ComrakRenderPlugins<'p> {
+pub struct RenderPlugins<'p> {
/// Provide a syntax highlighter adapter implementation for syntax
/// highlighting of codefence blocks.
/// ```
- /// # use comrak::{markdown_to_html, ComrakOptions, ComrakPlugins, markdown_to_html_with_plugins};
+ /// # use comrak::{markdown_to_html, Options, Plugins, markdown_to_html_with_plugins};
/// # use comrak::adapters::SyntaxHighlighterAdapter;
/// use std::collections::HashMap;
/// use std::io::{self, Write};
- /// let options = ComrakOptions::default();
- /// let mut plugins = ComrakPlugins::default();
+ /// 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),
@@ -580,9 +612,9 @@
pub heading_adapter: Option<&'p dyn HeadingAdapter>,
}
-impl Debug for ComrakRenderPlugins<'_> {
+impl Debug for RenderPlugins<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
- f.debug_struct("ComrakRenderPlugins")
+ f.debug_struct("RenderPlugins")
.field(
"codefence_syntax_highlighter",
&"impl SyntaxHighlighterAdapter",
@@ -600,13 +632,15 @@
struct FootnoteDefinition<'a> {
ix: Optionfn hello();\n
.
- let theme = &self.theme_set.themes[&self.theme];
- let mut highlighter = HighlightLines::new(syntax, theme);
- let mut output = String::new();
- let bg = theme.settings.background.unwrap_or(Color::WHITE);
-
- for line in LinesWithEndings::from(code) {
- let regions = highlighter.highlight_line(line, &self.syntax_set)?;
- append_highlighted_html_for_styled_line(
- ®ions[..],
- IncludeBackground::IfDifferent(bg),
- &mut output,
- )?;
+ match &self.theme {
+ Some(theme) => {
+ // syntect::html::highlighted_html_for_string, without the opening/closing
\n"
);
- let mut plugins = ComrakPlugins::default();
+ let mut plugins = Plugins::default();
+ plugins.render.codefence_syntax_highlighter = Some(&adapter);
+
+ html_plugins(input, expected, &plugins);
+}
+
+#[test]
+#[cfg(feature = "syntect")]
+fn syntect_plugin_with_css_classes() {
+ let adapter = crate::plugins::syntect::SyntectAdapter::new(None);
+
+ let input = concat!("```rust\n", "fn main<'a>();\n", "```\n");
+ let expected = concat!(
+ ".
+ let theme = &self.theme_set.themes[theme];
+ let mut highlighter = HighlightLines::new(syntax, theme);
+
+ let bg = theme.settings.background.unwrap_or(Color::WHITE);
+
+ let mut output = String::new();
+ for line in LinesWithEndings::from(code) {
+ let regions = highlighter.highlight_line(line, &self.syntax_set)?;
+ append_highlighted_html_for_styled_line(
+ ®ions[..],
+ IncludeBackground::IfDifferent(bg),
+ &mut output,
+ )?;
+ }
+ Ok(output)
+ }
+ None => {
+ // fall back to HTML classes.
+ let mut html_generator = ClassedHTMLGenerator::new_with_class_style(
+ syntax,
+ &self.syntax_set,
+ ClassStyle::Spaced,
+ );
+ for line in LinesWithEndings::from(code) {
+ html_generator.parse_html_for_line_which_includes_newline(line)?;
+ }
+ Ok(html_generator.finalize())
+ }
}
- Ok(output)
}
}
@@ -82,16 +102,25 @@
output: &mut dyn Write,
attributes: HashMap
\n"
);
- let mut plugins = ComrakPlugins::default();
+ let mut plugins = Plugins::default();
let adapter = MockAdapter {};
plugins.render.codefence_syntax_highlighter = Some(&adapter);
@@ -68,7 +68,7 @@
}
}
- let mut plugins = ComrakPlugins::default();
+ let mut plugins = Plugins::default();
let adapter = MockAdapter {};
plugins.render.heading_adapter = Some(&adapter);
@@ -88,8 +88,8 @@
#[test]
#[cfg(feature = "syntect")]
-fn syntect_plugin() {
- let adapter = crate::plugins::syntect::SyntectAdapter::new("base16-ocean.dark");
+fn syntect_plugin_with_base16_ocean_dark_theme() {
+ let adapter = crate::plugins::syntect::SyntectAdapter::new(Some("base16-ocean.dark"));
let input = concat!("```rust\n", "fn main<'a>();\n", "```\n");
let expected = concat!(
@@ -99,7 +99,27 @@
"\n",
"
\n",
"
\n",
- "↩\n",
+ "↩ \
+ ↩2\n",
"code\n",
"
\n",
- " \n",
"\n",
@@ -103,7 +104,7 @@
"foot 1 \n",
+ "foot 1 \n",
"note \n",
"\n",
+ "
\n",
+ "\n",
+ "
\n",
"\n
\n",
+ "\n
\n",
);
}
diff -Nru rust-comrak-0.18.0/src/tests/options.rs rust-comrak-0.20.0/src/tests/options.rs
--- rust-comrak-0.18.0/src/tests/options.rs 2006-07-24 01:21:28.000000000 +0000
+++ rust-comrak-0.20.0/src/tests/options.rs 2006-07-24 01:21:28.000000000 +0000
@@ -5,11 +5,11 @@
let dash = concat!("- a\n");
let plus = concat!("+ a\n");
let star = concat!("* a\n");
- let mut dash_opts = ComrakOptions::default();
+ let mut dash_opts = Options::default();
dash_opts.render.list_style = ListStyleType::Dash;
- let mut plus_opts = ComrakOptions::default();
+ let mut plus_opts = Options::default();
plus_opts.render.list_style = ListStyleType::Plus;
- let mut star_opts = ComrakOptions::default();
+ let mut star_opts = Options::default();
star_opts.render.list_style = ListStyleType::Star;
commonmark(dash, dash, Some(&dash_opts));
@@ -27,7 +27,7 @@
#[test]
fn width_breaks() {
- let mut options = ComrakOptions::default();
+ let mut options = Options::default();
options.render.width = 72;
let input = concat!(
"this should break because it has breakable characters. break right here newline\n",
diff -Nru rust-comrak-0.18.0/src/tests/pathological.rs rust-comrak-0.20.0/src/tests/pathological.rs
--- rust-comrak-0.18.0/src/tests/pathological.rs 1970-01-01 00:00:00.000000000 +0000
+++ rust-comrak-0.20.0/src/tests/pathological.rs 2006-07-24 01:21:28.000000000 +0000
@@ -0,0 +1,67 @@
+use super::*;
+use ntest::timeout;
+
+// input: python3 -c 'n = 50000; print("*a_ " * n)'
+#[test]
+#[timeout(4000)]
+fn pathological_emphases() {
+ let n = 50_000;
+ let input = format!("{}", "*a_ ".repeat(n));
+ let mut exp = format!("
\n",
+ );
+
+ let mut plugins = Plugins::default();
plugins.render.codefence_syntax_highlighter = Some(&adapter);
html_plugins(input, expected, &plugins);
diff -Nru rust-comrak-0.18.0/src/tests/propfuzz.rs rust-comrak-0.20.0/src/tests/propfuzz.rs
--- rust-comrak-0.18.0/src/tests/propfuzz.rs 2006-07-24 01:21:28.000000000 +0000
+++ rust-comrak-0.20.0/src/tests/propfuzz.rs 2006-07-24 01:21:28.000000000 +0000
@@ -6,8 +6,8 @@
#[cfg(not(target_arch = "wasm32"))]
#[propfuzz]
fn propfuzz_doesnt_crash(md: String) {
- let options = ComrakOptions {
- extension: ComrakExtensionOptions {
+ let options = Options {
+ extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
@@ -21,12 +21,13 @@
#[cfg(feature = "shortcodes")]
shortcodes: true,
},
- parse: ComrakParseOptions {
+ parse: ParseOptions {
smart: true,
default_info_string: Some("Rust".to_string()),
relaxed_tasklist_matching: true,
+ relaxed_autolinks: true,
},
- render: ComrakRenderOptions {
+ render: RenderOptions {
hardbreaks: true,
github_pre_lang: true,
full_info_string: true,
diff -Nru rust-comrak-0.18.0/src/tests/regressions.rs rust-comrak-0.20.0/src/tests/regressions.rs
--- rust-comrak-0.18.0/src/tests/regressions.rs 2006-07-24 01:21:28.000000000 +0000
+++ rust-comrak-0.20.0/src/tests/regressions.rs 2006-07-24 01:21:28.000000000 +0000
@@ -1,5 +1,4 @@
use super::*;
-use ntest::timeout;
#[test]
fn pointy_brace() {
@@ -57,22 +56,6 @@
}
#[test]
-#[timeout(4000)]
-fn pathological_emphases() {
- let mut s = String::with_capacity(50000 * 4);
- for _ in 0..50000 {
- s.push_str("*a_ ");
- }
-
- let mut exp = format!("",
+ ";\n",
+ "
\n",
"
\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"
\n",
- "
\n",
"
\n",
@@ -58,7 +58,7 @@
"* [!] Red\n",
concat!(
"\n",
- "
\n"
),
);
@@ -74,7 +74,7 @@
"* [!] Red\n",
concat!(
"\n",
- "
\n"
),
);
@@ -93,7 +93,7 @@
"\n",
"
\n"
),
);
diff -Nru rust-comrak-0.18.0/src/tests.rs rust-comrak-0.20.0/src/tests.rs
--- rust-comrak-0.18.0/src/tests.rs 2006-07-24 01:21:28.000000000 +0000
+++ rust-comrak-0.20.0/src/tests.rs 2006-07-24 01:21:28.000000000 +0000
@@ -6,12 +6,14 @@
mod api;
mod autolink;
+mod commonmark;
mod core;
mod description_lists;
mod footnotes;
mod fuzz;
mod header_ids;
mod options;
+mod pathological;
mod plugins;
mod propfuzz;
mod regressions;
@@ -42,9 +44,9 @@
}
#[track_caller]
-fn commonmark(input: &str, expected: &str, opts: Option<&ComrakOptions>) {
+fn commonmark(input: &str, expected: &str, opts: Option<&Options>) {
let arena = Arena::new();
- let defaults = ComrakOptions::default();
+ let defaults = Options::default();
let options = opts.unwrap_or(&defaults);
let root = parse_document(&arena, input, options);
@@ -61,16 +63,16 @@
#[track_caller]
fn html_opts_icode
herecode
here