From 1d92666865b35341e076efbefddf6e73b5e1542e Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 7 Sep 2022 15:53:06 +0200 Subject: Add support for recoverable syntax errors --- src/lib.rs | 103 ++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 74 insertions(+), 29 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 7fd705b..e0b6da2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -406,6 +406,7 @@ pub struct Options { /// /// ``` /// use micromark::{micromark, micromark_with_options, Options}; + /// # fn main() -> Result<(), String> { /// /// // micromark is safe by default: /// assert_eq!( @@ -421,9 +422,11 @@ pub struct Options { /// allow_dangerous_html: true, /// ..Options::default() /// } - /// ), + /// )?, /// "

Hi, venus!

" /// ); + /// # Ok(()) + /// # } /// ``` pub allow_dangerous_html: bool, @@ -435,6 +438,7 @@ pub struct Options { /// /// ``` /// use micromark::{micromark, micromark_with_options, Options}; + /// # fn main() -> Result<(), String> { /// /// // micromark is safe by default: /// assert_eq!( @@ -450,9 +454,11 @@ pub struct Options { /// allow_dangerous_protocol: true, /// ..Options::default() /// } - /// ), + /// )?, /// "

javascript:alert(1)

" /// ); + /// # Ok(()) + /// # } /// ``` pub allow_dangerous_protocol: bool, @@ -463,6 +469,7 @@ pub struct Options { /// /// ``` /// use micromark::{micromark, micromark_with_options, Options, Constructs}; + /// # fn main() -> Result<(), String> { /// /// // micromark follows CommonMark by default: /// assert_eq!( @@ -481,9 +488,11 @@ pub struct Options { /// }, /// ..Options::default() /// } - /// ), + /// )?, /// "

indented code?

" /// ); + /// # Ok(()) + /// # } /// ``` pub constructs: Constructs, @@ -503,6 +512,7 @@ pub struct Options { /// /// ``` /// use micromark::{micromark, micromark_with_options, Options, LineEnding}; + /// # fn main() -> Result<(), String> { /// /// // micromark uses `\n` by default: /// assert_eq!( @@ -518,9 +528,11 @@ pub struct Options { /// default_line_ending: LineEnding::CarriageReturnLineFeed, /// ..Options::default() /// } - /// ), + /// )?, /// "
\r\n

a

\r\n
" /// ); + /// # Ok(()) + /// # } /// ``` pub default_line_ending: LineEnding, @@ -534,6 +546,7 @@ pub struct Options { /// /// ``` /// use micromark::{micromark, micromark_with_options, Options, Constructs}; + /// # fn main() -> Result<(), String> { /// /// // `"Footnotes"` is used by default: /// assert_eq!( @@ -543,7 +556,7 @@ pub struct Options { /// constructs: Constructs::gfm(), /// ..Options::default() /// } - /// ), + /// )?, /// "

1

\n

Footnotes

\n
    \n
  1. \n

    b

    \n
  2. \n
\n
\n" /// ); /// @@ -556,9 +569,11 @@ pub struct Options { /// gfm_footnote_label: Some("Notes de bas de page".to_string()), /// ..Options::default() /// } - /// ), + /// )?, /// "

1

\n

Notes de bas de page

\n
    \n
  1. \n

    b

    \n
  2. \n
\n
\n" /// ); + /// # Ok(()) + /// # } /// ``` pub gfm_footnote_label: Option, @@ -570,6 +585,7 @@ pub struct Options { /// /// ``` /// use micromark::{micromark, micromark_with_options, Options, Constructs}; + /// # fn main() -> Result<(), String> { /// /// // `"h2"` is used by default: /// assert_eq!( @@ -579,7 +595,7 @@ pub struct Options { /// constructs: Constructs::gfm(), /// ..Options::default() /// } - /// ), + /// )?, /// "

1

\n

Footnotes

\n
    \n
  1. \n

    b

    \n
  2. \n
\n
\n" /// ); /// @@ -592,9 +608,11 @@ pub struct Options { /// gfm_footnote_label_tag_name: Some("h1".to_string()), /// ..Options::default() /// } - /// ), + /// )?, /// "

1

\n

Footnotes

\n
    \n
  1. \n

    b

    \n
  2. \n
\n
\n" /// ); + /// # Ok(()) + /// # } /// ``` pub gfm_footnote_label_tag_name: Option, @@ -612,6 +630,7 @@ pub struct Options { /// /// ``` /// use micromark::{micromark, micromark_with_options, Options, Constructs}; + /// # fn main() -> Result<(), String> { /// /// // `"class=\"sr-only\""` is used by default: /// assert_eq!( @@ -621,7 +640,7 @@ pub struct Options { /// constructs: Constructs::gfm(), /// ..Options::default() /// } - /// ), + /// )?, /// "

1

\n

Footnotes

\n
    \n
  1. \n

    b

    \n
  2. \n
\n
\n" /// ); /// @@ -634,9 +653,11 @@ pub struct Options { /// gfm_footnote_label_attributes: Some("class=\"footnote-heading\"".to_string()), /// ..Options::default() /// } - /// ), + /// )?, /// "

1

\n

Footnotes

\n
    \n
  1. \n

    b

    \n
  2. \n
\n
\n" /// ); + /// # Ok(()) + /// # } /// ``` pub gfm_footnote_label_attributes: Option, @@ -649,6 +670,7 @@ pub struct Options { /// /// ``` /// use micromark::{micromark, micromark_with_options, Options, Constructs}; + /// # fn main() -> Result<(), String> { /// /// // `"Back to content"` is used by default: /// assert_eq!( @@ -658,7 +680,7 @@ pub struct Options { /// constructs: Constructs::gfm(), /// ..Options::default() /// } - /// ), + /// )?, /// "

1

\n

Footnotes

\n
    \n
  1. \n

    b

    \n
  2. \n
\n
\n" /// ); /// @@ -671,9 +693,11 @@ pub struct Options { /// gfm_footnote_back_label: Some("Arrière".to_string()), /// ..Options::default() /// } - /// ), + /// )?, /// "

1

\n

Footnotes

\n
    \n
  1. \n

    b

    \n
  2. \n
\n
\n" /// ); + /// # Ok(()) + /// # } /// ``` pub gfm_footnote_back_label: Option, @@ -696,6 +720,7 @@ pub struct Options { /// /// ``` /// use micromark::{micromark, micromark_with_options, Options, Constructs}; + /// # fn main() -> Result<(), String> { /// /// // `"user-content-"` is used by default: /// assert_eq!( @@ -705,7 +730,7 @@ pub struct Options { /// constructs: Constructs::gfm(), /// ..Options::default() /// } - /// ), + /// )?, /// "

1

\n

Footnotes

\n
    \n
  1. \n

    b

    \n
  2. \n
\n
\n" /// ); /// @@ -718,9 +743,11 @@ pub struct Options { /// gfm_footnote_clobber_prefix: Some("".to_string()), /// ..Options::default() /// } - /// ), + /// )?, /// "

1

\n

Footnotes

\n
    \n
  1. \n

    b

    \n
  2. \n
\n
\n" /// ); + /// # Ok(()) + /// # } /// ``` pub gfm_footnote_clobber_prefix: Option, @@ -733,6 +760,7 @@ pub struct Options { /// /// ``` /// use micromark::{micromark, micromark_with_options, Options, Constructs}; + /// # fn main() -> Result<(), String> { /// /// // micromark supports single tildes by default: /// assert_eq!( @@ -742,7 +770,7 @@ pub struct Options { /// constructs: Constructs::gfm(), /// ..Options::default() /// } - /// ), + /// )?, /// "

a

" /// ); /// @@ -755,9 +783,11 @@ pub struct Options { /// gfm_strikethrough_single_tilde: false, /// ..Options::default() /// } - /// ), + /// )?, /// "

~a~

" /// ); + /// # Ok(()) + /// # } /// ``` pub gfm_strikethrough_single_tilde: bool, @@ -772,6 +802,7 @@ pub struct Options { /// /// ``` /// use micromark::{micromark_with_options, Options, Constructs}; + /// # fn main() -> Result<(), String> { /// /// // With `allow_dangerous_html`, micromark passes HTML through untouched: /// assert_eq!( @@ -782,7 +813,7 @@ pub struct Options { /// constructs: Constructs::gfm(), /// ..Options::default() /// } - /// ), + /// )?, /// "