From cba78821ed13d5a92c74d092914fbad4c842f889 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 9 Jun 2022 14:03:04 +0200 Subject: Add temporary support for stripping whitespace --- readme.md | 1 + src/compiler.rs | 12 ++++++++---- tests/code_indented.rs | 11 +++++------ tests/heading_atx.rs | 11 +++++------ tests/html_flow.rs | 11 +++++------ tests/thematic_break.rs | 11 +++++------ 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/readme.md b/readme.md index 1dc9932..15edf87 100644 --- a/readme.md +++ b/readme.md @@ -70,6 +70,7 @@ cargo doc --document-private-items ### Small things +- [ ] (1) Parse initial and final whitespace of paragraphs (in text) - [ ] (3) Clean compiler - [ ] (1) Optionally remove dangerous protocols when compiling - [ ] (1) Use preferred line ending style in markdown diff --git a/src/compiler.rs b/src/compiler.rs index 4f362b8..3632d29 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -280,11 +280,15 @@ pub fn compile(events: &[Event], codes: &[Code], options: &CompileOptions) -> St } // To do: `ContentPhrasing` should be parsed as phrasing first. // This branch below currently acts as the resulting `data` tokens. - TokenType::ContentChunk + // To do: initial and final whitespace should be handled in `text`. + TokenType::ContentChunk => { + // last_was_tag = false; + buf_tail_mut(buffers).push(encode( + slice_serialize(codes, &get_span(events, index), false).trim(), + )); + } // To do: `ChunkString` does not belong here. Remove it when subtokenization is supported. - | TokenType::ChunkString - | TokenType::Data - | TokenType::CharacterEscapeValue => { + TokenType::ChunkString | TokenType::Data | TokenType::CharacterEscapeValue => { // last_was_tag = false; buf_tail_mut(buffers).push(encode(&slice_serialize( codes, diff --git a/tests/code_indented.rs b/tests/code_indented.rs index 80dae4b..5967cb3 100644 --- a/tests/code_indented.rs +++ b/tests/code_indented.rs @@ -40,12 +40,11 @@ fn code_indented() { "should support blank lines in indented code (3)" ); - // To do: strip whitespace. - // assert_eq!( - // micromark("Foo\n bar"), - // "

Foo\nbar

", - // "should not support interrupting paragraphs" - // ); + assert_eq!( + micromark("Foo\n bar"), + "

Foo\nbar

", + "should not support interrupting paragraphs" + ); assert_eq!( micromark(" foo\nbar"), diff --git a/tests/heading_atx.rs b/tests/heading_atx.rs index 7a830fe..defc77f 100644 --- a/tests/heading_atx.rs +++ b/tests/heading_atx.rs @@ -99,12 +99,11 @@ fn heading_atx() { "should not support four initial spaces" ); - // To do: strip whitespace. - // assert_eq!( - // micromark("foo\n # bar"), - // "

foo\n# bar

", - // "should not support four initial spaces when interrupting" - // ); + assert_eq!( + micromark("foo\n # bar"), + "

foo\n# bar

", + "should not support four initial spaces when interrupting" + ); assert_eq!( micromark("## foo ##"), diff --git a/tests/html_flow.rs b/tests/html_flow.rs index 18eff2d..0a5ec72 100644 --- a/tests/html_flow.rs +++ b/tests/html_flow.rs @@ -814,12 +814,11 @@ fn html_flow_7_complete() { "should not support a line ending directly after a tag name" ); - // To do: trim trailing whitespace. - // assert_eq!( - // micromark_with_options("<x

", - // "should not support an eof after a space directly after a tag name" - // ); + assert_eq!( + micromark_with_options("<x

", + "should not support an eof after a space directly after a tag name" + ); assert_eq!( micromark_with_options("Foo\n***

", - // "should not support thematic breaks w/ 4 spaces as paragraph continuation" - // ); + assert_eq!( + micromark("Foo\n ***"), + "

Foo\n***

", + "should not support thematic breaks w/ 4 spaces as paragraph continuation" + ); assert_eq!( micromark("_____________________________________"), -- cgit