diff --git a/Cargo.toml b/Cargo.toml index e9101dbe..4054d45f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ shell-words = { version = "1.0", optional = true } slug = "0.1.4" emojis = { version = "0.6.2", optional = true } arbitrary = { version = "1", optional = true, features = ["derive"] } -bon = "3" +bon = { version = "3", optional = true } caseless = "0.2.1" [dev-dependencies] @@ -51,9 +51,10 @@ ntest = "0.9" toml = "0.7.3" [features] -default = ["cli", "syntect"] +default = ["cli", "syntect", "bon"] cli = ["clap", "shell-words", "xdg"] shortcodes = ["emojis"] +bon = ["dep:bon"] [target.'cfg(all(not(windows), not(target_arch="wasm32")))'.dependencies] xdg = { version = "^2.5", optional = true } diff --git a/src/lib.rs b/src/lib.rs index f3eab8cd..7d4ff8b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,15 +90,19 @@ pub use html::Anchorizer; #[allow(deprecated)] pub use parser::parse_document_with_broken_link_callback; pub use parser::{ - parse_document, BrokenLinkCallback, BrokenLinkReference, ExtensionOptions, - ExtensionOptionsBuilder, ListStyleType, Options, ParseOptions, ParseOptionsBuilder, Plugins, - PluginsBuilder, RenderOptions, RenderOptionsBuilder, RenderPlugins, RenderPluginsBuilder, - ResolvedReference, URLRewriter, + parse_document, BrokenLinkCallback, BrokenLinkReference, ExtensionOptions, ListStyleType, + Options, ParseOptions, Plugins, RenderOptions, RenderPlugins, ResolvedReference, URLRewriter, }; 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; +#[cfg(feature = "bon")] +pub use parser::{ + ExtensionOptionsBuilder, ParseOptionsBuilder, PluginsBuilder, RenderOptionsBuilder, + RenderPluginsBuilder, +}; + /// Legacy naming of [`ExtensionOptions`] pub type ComrakExtensionOptions<'c> = ExtensionOptions<'c>; /// Legacy naming of [`Options`] diff --git a/src/parser/mod.rs b/src/parser/mod.rs index d3d11c1b..92372f84 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -18,7 +18,6 @@ use crate::nodes::{ }; use crate::scanners::{self, SetextChar}; use crate::strings::{self, split_off_front_matter, Case}; -use bon::Builder; use std::cell::RefCell; use std::cmp::min; use std::collections::HashMap; @@ -32,6 +31,9 @@ use typed_arena::Arena; use crate::adapters::HeadingAdapter; use crate::parser::multiline_block_quote::NodeMultilineBlockQuote; +#[cfg(feature = "bon")] +use bon::Builder; + use self::inlines::RefMap; const TAB_STOP: usize = 4; @@ -206,7 +208,8 @@ pub(crate) enum WikiLinksMode { } #[non_exhaustive] -#[derive(Default, Debug, Clone, Builder)] +#[derive(Default, Debug, Clone)] +#[cfg_attr(feature = "bon", derive(Builder))] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] /// Options to select extensions. pub struct ExtensionOptions<'c> { @@ -221,7 +224,7 @@ pub struct ExtensionOptions<'c> { /// assert_eq!(markdown_to_html("Hello ~world~ there.\n", &options), /// "
Hello world there.
Hello <xmp>.
\n<xmp>\n"); /// ``` - #[builder(default)] + #[cfg_attr(feature = "bon", builder(default))] pub tagfilter: bool, /// Enables the [table extension](https://github.github.com/gfm/#tables-extension-) @@ -250,7 +253,7 @@ pub struct ExtensionOptions<'c> { /// "a | \nb | \n
---|---|
c | \nd | \n
Hello www.github.com.
\n"); /// ``` - #[builder(default)] + #[cfg_attr(feature = "bon", builder(default))] pub autolink: bool, /// Enables the @@ -282,7 +285,7 @@ pub struct ExtensionOptions<'c> { /// "e = mc2.
\n"); /// ``` - #[builder(default)] + #[cfg_attr(feature = "bon", builder(default))] pub superscript: bool, /// Enables the header IDs Comrak extension. @@ -320,7 +323,7 @@ pub struct ExtensionOptions<'c> { /// assert_eq!(markdown_to_html("Hi[^x].\n\n[^x]: A greeting.\n", &options), /// "Hi1.
\nA greeting. ↩
\nDefinition
\n\n\n"); /// ``` - #[builder(default)] + #[cfg_attr(feature = "bon", builder(default))] pub multiline_block_quotes: bool, /// Enables math using dollar syntax. @@ -437,7 +440,7 @@ pub struct ExtensionOptions<'c> { /// assert_eq!(markdown_to_html("$$\nx^2\n$$\n", &options), /// "paragraph
\n
\nx^2\n
\n"); /// ``` - #[builder(default)] + #[cfg_attr(feature = "bon", builder(default))] pub math_dollars: bool, /// Enables math using code syntax. @@ -459,7 +462,7 @@ pub struct ExtensionOptions<'c> { /// assert_eq!(markdown_to_html("```math\nx^2\n```\n", &options), /// "x^2\n
\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub math_code: bool,
#[cfg(feature = "shortcodes")]
@@ -476,7 +479,7 @@ pub struct ExtensionOptions<'c> {
/// assert_eq!(markdown_to_html("Happy Friday! :smile:", &options),
/// "Happy Friday! 😄
\n"); /// ``` - #[builder(default)] + #[cfg_attr(feature = "bon", builder(default))] pub shortcodes: bool, /// Enables wikilinks using title after pipe syntax @@ -497,7 +500,7 @@ pub struct ExtensionOptions<'c> { /// assert_eq!(markdown_to_html("[[url|link label]]", &options), /// "\n"); /// ``` - #[builder(default)] + #[cfg_attr(feature = "bon", builder(default))] pub wikilinks_title_after_pipe: bool, /// Enables wikilinks using title before pipe syntax @@ -517,7 +520,7 @@ pub struct ExtensionOptions<'c> { /// assert_eq!(markdown_to_html("[[link label|url]]", &options), /// "\n"); /// ``` - #[builder(default)] + #[cfg_attr(feature = "bon", builder(default))] pub wikilinks_title_before_pipe: bool, /// Enables underlines using double underscores @@ -534,7 +537,7 @@ pub struct ExtensionOptions<'c> { /// assert_eq!(markdown_to_html("__underlined text__", &options), /// "underlined text
\n"); /// ``` - #[builder(default)] + #[cfg_attr(feature = "bon", builder(default))] pub underline: bool, /// Enables subscript text using single tildes. @@ -554,7 +557,7 @@ pub struct ExtensionOptions<'c> { /// assert_eq!(markdown_to_html("H~2~O", &options), /// "H2O
\n"); /// ``` - #[builder(default)] + #[cfg_attr(feature = "bon", builder(default))] pub subscript: bool, /// Enables spoilers using double vertical bars @@ -571,7 +574,7 @@ pub struct ExtensionOptions<'c> { /// assert_eq!(markdown_to_html("Darth Vader is ||Luke's father||", &options), /// "Darth Vader is Luke's father
\n"); /// ``` - #[builder(default)] + #[cfg_attr(feature = "bon", builder(default))] pub spoiler: bool, /// Requires at least one space after a `>` character to generate a blockquote, @@ -601,7 +604,7 @@ pub struct ExtensionOptions<'c> { /// "three
\n", /// "\n")); /// ``` - #[builder(default)] + #[cfg_attr(feature = "bon", builder(default))] pub greentext: bool, /// Wraps embedded image URLs using a function or custom trait object. @@ -653,7 +656,8 @@ impl<'c> ExtensionOptions<'c> { } #[non_exhaustive] -#[derive(Default, Clone, Debug, Builder)] +#[derive(Default, Clone, Debug)] +#[cfg_attr(feature = "bon", derive(Builder))] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] /// Options for parser functions. pub struct ParseOptions<'c> { @@ -669,7 +673,7 @@ pub struct ParseOptions<'c> { /// assert_eq!(markdown_to_html("'Hello,' \"world\" ...", &options), /// "‘Hello,’ “world” …
\n"); /// ``` - #[builder(default)] + #[cfg_attr(feature = "bon", builder(default))] pub smart: bool, /// The default info string for fenced code blocks. @@ -687,7 +691,7 @@ pub struct ParseOptions<'c> { pub default_info_string: OptionHello.
\nWorld.
` is used for fenced code blocks with info tags.
@@ -774,7 +779,7 @@ pub struct RenderOptions {
/// assert_eq!(markdown_to_html("``` rust\nfn hello();\n```\n", &options),
/// "fn hello();\n
\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub github_pre_lang: bool,
/// Enable full info strings for code blocks
@@ -789,7 +794,7 @@ pub struct RenderOptions {
/// let html = markdown_to_html("``` rust extra info\nfn hello();\n```\n", &options);
/// assert!(html.contains(r#"data-meta="extra info""#));
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub full_info_string: bool,
/// The wrap column when outputting CommonMark.
@@ -812,7 +817,7 @@ pub struct RenderOptions {
/// "hello hello hello\nhello hello hello\n");
/// # }
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub width: usize,
/// Allow rendering of raw HTML and potentially dangerous links.
@@ -838,7 +843,7 @@ pub struct RenderOptions {
/// \n\
/// Safe.
\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub unsafe_: bool,
/// Escape raw HTML instead of clobbering it.
@@ -854,7 +859,7 @@ pub struct RenderOptions {
/// assert_eq!(markdown_to_html(input, &options),
/// "<i>italic text</i>
\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub escape: bool,
/// Set the type of [bullet list marker](https://spec.commonmark.org/0.30/#bullet-list-marker) to use. Options are:
@@ -878,7 +883,7 @@ pub struct RenderOptions {
/// assert_eq!(markdown_to_commonmark(input, &options),
/// "* one\n* two\n* three\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub list_style: ListStyleType,
/// Include source position attributes in HTML and XML output.
@@ -901,7 +906,7 @@ pub struct RenderOptions {
/// ```
///
/// [`experimental_inline_sourcepos`]: crate::RenderOptionsBuilder::experimental_inline_sourcepos
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub sourcepos: bool,
/// Include inline sourcepos in HTML output, which is known to have issues.
@@ -917,7 +922,7 @@ pub struct RenderOptions {
/// assert_eq!(markdown_to_html(input, &options),
/// "Hello world!
\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub experimental_inline_sourcepos: bool,
/// Wrap escaped characters in a `` to allow any
@@ -935,7 +940,7 @@ pub struct RenderOptions {
/// assert_eq!(markdown_to_html(input, &options),
/// "Notify user @example
\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub escaped_char_spans: bool,
/// Ignore setext headings in input.
@@ -952,7 +957,7 @@ pub struct RenderOptions {
/// assert_eq!(markdown_to_html(input, &options),
/// "setext heading
\n
\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub ignore_setext: bool,
/// Ignore empty links in input.
@@ -968,7 +973,7 @@ pub struct RenderOptions {
/// options.render.ignore_empty_links = true;
/// assert_eq!(markdown_to_html(input, &options), "[]()
\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub ignore_empty_links: bool,
/// Enables GFM quirks in HTML output which break CommonMark compatibility.
@@ -985,7 +990,7 @@ pub struct RenderOptions {
/// assert_eq!(markdown_to_html(input, &options),
/// "abcd foo
\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub gfm_quirks: bool,
/// Prefer fenced code blocks when outputting CommonMark.
@@ -1007,7 +1012,7 @@ pub struct RenderOptions {
/// format_commonmark(&root, &options, &mut buf);
/// assert_eq!(str::from_utf8(&buf).unwrap(), "```\nhello\n```\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub prefer_fenced: bool,
/// Render the image as a figure element with the title as its caption.
@@ -1024,7 +1029,7 @@ pub struct RenderOptions {
/// assert_eq!(markdown_to_html(input, &options),
/// "![\"this \"image\"](\"https://example.com/image.png\")
this is an image
\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub figure_with_caption: bool,
/// Add classes to the output of the tasklist extension. This allows tasklists to be styled.
@@ -1042,7 +1047,7 @@ pub struct RenderOptions {
/// assert_eq!(markdown_to_html(input, &options),
/// "\n- Foo
\n
\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub tasklist_classes: bool,
/// Render ordered list with a minimum marker width.
@@ -1060,21 +1065,23 @@ pub struct RenderOptions {
/// assert_eq!(markdown_to_commonmark(input, &options),
/// "1. Something\n");
/// ```
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub ol_width: usize,
}
#[non_exhaustive]
-#[derive(Default, Debug, Clone, Builder)]
+#[derive(Default, Debug, Clone)]
+#[cfg_attr(feature = "bon", derive(Builder))]
/// Umbrella plugins struct.
pub struct Plugins<'p> {
/// Configure render-time plugins.
- #[builder(default)]
+ #[cfg_attr(feature = "bon", builder(default))]
pub render: RenderPlugins<'p>,
}
#[non_exhaustive]
-#[derive(Default, Clone, Builder)]
+#[derive(Default, Clone)]
+#[cfg_attr(feature = "bon", derive(Builder))]
/// Plugins for alternative rendering.
pub struct RenderPlugins<'p> {
/// Provide a syntax highlighter adapter implementation for syntax