From be62b2e29a61774100f676cfdd9b100cadf1905f Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 30 Jun 2022 16:35:13 +0200 Subject: Add support for trimming whitespace around string, text This commit introduces trimming initial and final whitespace around the whole string or text, or around line endings inside that string or text. * Add `register_resolver_before`, to run resolvers earlier than others, used for labels * Add resolver to merge `data` events, which are the most frequent token that occurs, and can happen adjacently. In `micromark-js` this sped up parsing a lot * Fix a bug where a virtual space was not seen as an okay event * Refactor to enable all turned off whitespace tests --- tests/hard_break_trailing.rs | 74 ++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 40 deletions(-) (limited to 'tests/hard_break_trailing.rs') diff --git a/tests/hard_break_trailing.rs b/tests/hard_break_trailing.rs index 6c29020..0dbbbdb 100644 --- a/tests/hard_break_trailing.rs +++ b/tests/hard_break_trailing.rs @@ -15,12 +15,11 @@ fn hard_break_trailing() { "should support multiple trailing spaces" ); - // To do: trimming whitespace in paragraphs. - // assert_eq!( - // micromark("foo \n bar"), - // "

foo
\nbar

", - // "should support leading spaces after a trailing hard break" - // ); + assert_eq!( + micromark("foo \n bar"), + "

foo
\nbar

", + "should support leading spaces after a trailing hard break" + ); // To do: attention. // assert_eq!( @@ -42,12 +41,11 @@ fn hard_break_trailing() { "should not support trailing hard breaks in code" ); - // To do: trimming whitespace in paragraphs. - // assert_eq!( - // micromark("foo "), - // "

foo

", - // "should not support trailing hard breaks at the end of a paragraph" - // ); + assert_eq!( + micromark("foo "), + "

foo

", + "should not support trailing hard breaks at the end of a paragraph" + ); assert_eq!( micromark("### foo "), @@ -55,26 +53,23 @@ fn hard_break_trailing() { "should not support trailing hard breaks at the end of a heading" ); - // To do: trimming whitespace in paragraphs. - // assert_eq!( - // micromark("aaa \t\nbb"), - // "

aaa\nbb

", - // "should support a mixed line suffix (1)" - // ); + assert_eq!( + micromark("aaa \t\nbb"), + "

aaa\nbb

", + "should support a mixed line suffix (1)" + ); - // To do: trimming whitespace in paragraphs. - // assert_eq!( - // micromark("aaa\t \nbb"), - // "

aaa\nbb

", - // "should support a mixed line suffix (2)" - // ); + assert_eq!( + micromark("aaa\t \nbb"), + "

aaa\nbb

", + "should support a mixed line suffix (2)" + ); - // To do: trimming whitespace in paragraphs. - // assert_eq!( - // micromark("aaa \t \nbb"), - // "

aaa\nbb

", - // "should support a mixed line suffix (3)" - // ); + assert_eq!( + micromark("aaa \t \nbb"), + "

aaa\nbb

", + "should support a mixed line suffix (3)" + ); assert_eq!( micromark("aaa\0 \nbb"), @@ -82,12 +77,11 @@ fn hard_break_trailing() { "should support a hard break after a replacement character" ); - // To do: trimming whitespace in paragraphs. - // assert_eq!( - // micromark("aaa\0\t\nbb"), - // "

aaa�\nbb

", - // "should support a line suffix after a replacement character" - // ); + assert_eq!( + micromark("aaa\0\t\nbb"), + "

aaa�\nbb

", + "should support a line suffix after a replacement character" + ); // To do: attention. // assert_eq!( @@ -96,28 +90,28 @@ fn hard_break_trailing() { // "should support a hard break after a span" // ); - // To do: attention, trimming whitespace in paragraphs. + // To do: attention. // assert_eq!( // micromark("*a*\t\nbb"), // "

a\nbb

", // "should support a line suffix after a span" // ); - // To do: attention, trimming whitespace in paragraphs. + // To do: attention. // assert_eq!( // micromark("*a* \t\nbb"), // "

a\nbb

", // "should support a mixed line suffix after a span (1)" // ); - // To do: attention, trimming whitespace in paragraphs. + // To do: attention. // assert_eq!( // micromark("*a*\t \nbb"), // "

a\nbb

", // "should support a mixed line suffix after a span (2)" // ); - // To do: attention, trimming whitespace in paragraphs. + // To do: attention. // assert_eq!( // micromark("*a* \t \nbb"), // "

a\nbb

", -- cgit