diff options
| author | 2022-06-09 13:01:36 +0200 | |
|---|---|---|
| committer | 2022-06-09 13:01:36 +0200 | |
| commit | 10355a403f57c93a074716c785d588c76de5634c (patch) | |
| tree | 46408a8a1198c1bb632f22964a347c01023867bc | |
| parent | 433680ae0914da8921c4ee762fdc93e7b70cf9f1 (diff) | |
| download | markdown-rs-10355a403f57c93a074716c785d588c76de5634c.tar.gz markdown-rs-10355a403f57c93a074716c785d588c76de5634c.tar.bz2 markdown-rs-10355a403f57c93a074716c785d588c76de5634c.zip | |
Add support for indented lines in paragraphs
Diffstat (limited to '')
| -rw-r--r-- | src/content/flow.rs | 43 | ||||
| -rw-r--r-- | tests/code_indented.rs | 13 | ||||
| -rw-r--r-- | tests/heading_atx.rs | 2 | ||||
| -rw-r--r-- | tests/html_flow.rs | 74 | ||||
| -rw-r--r-- | tests/thematic_break.rs | 2 | 
5 files changed, 64 insertions, 70 deletions
| diff --git a/src/content/flow.rs b/src/content/flow.rs index 6c47a10..ac987e1 100644 --- a/src/content/flow.rs +++ b/src/content/flow.rs @@ -19,6 +19,7 @@  //!  //! <!-- To do: `setext` in content? Link to content. --> +use crate::constant::TAB_SIZE;  use crate::construct::{      blank_line::start as blank_line, code_fenced::start as code_fenced,      code_indented::start as code_indented, heading_atx::start as heading_atx, @@ -26,6 +27,7 @@ use crate::construct::{      thematic_break::start as thematic_break,  };  use crate::tokenizer::{Code, Event, State, StateFnResult, TokenType, Tokenizer}; +use crate::util::get_span;  /// Turn `codes` as the flow content type into events.  // To do: remove this `allow` when all the content types are glued together. @@ -237,34 +239,29 @@ fn continuation_construct_initial_before(tokenizer: &mut Tokenizer, code: Code)  }  fn continuation_construct_after_prefix(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { -    // let tail = tokenizer.events.last(); -    // let mut prefix = 0; +    let tail = tokenizer.events.last(); +    let mut prefix = 0; -    // if let Some(event) = tail { -    //     if event.token_type == TokenType::Whitespace { -    //         let span = get_span(&tokenizer.events, tokenizer.events.len() - 1); -    //         prefix = span.end_index - span.start_index; -    //     } -    // } +    if let Some(event) = tail { +        if event.token_type == TokenType::Whitespace { +            let span = get_span(&tokenizer.events, tokenizer.events.len() - 1); +            prefix = span.end_index - span.start_index; +        } +    }      match code {          // Blank lines are not allowed in content.          Code::None | Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => (State::Nok, None), -        // If code is disabled, indented lines are part of the content. -        // _ if prefix >= TAB_SIZE => { -        //     (State::Ok, None) -        // } -        _ => { -            println!("to do: check if flow interrupts, assuming it can’t"); -            tokenizer.attempt_2(heading_atx, thematic_break, |ok| { -                let result = if ok { -                    (State::Nok, None) -                } else { -                    (State::Ok, None) -                }; -                Box::new(|_t, _c| result) -            })(tokenizer, code) -        } +        // To do: If code is disabled, indented lines are part of the content. +        _ if prefix >= TAB_SIZE => (State::Ok, None), +        _ => tokenizer.attempt_2(heading_atx, thematic_break, |ok| { +            let result = if ok { +                (State::Nok, None) +            } else { +                (State::Ok, None) +            }; +            Box::new(|_t, _c| result) +        })(tokenizer, code),      }  } diff --git a/tests/code_indented.rs b/tests/code_indented.rs index f5926c0..80dae4b 100644 --- a/tests/code_indented.rs +++ b/tests/code_indented.rs @@ -40,19 +40,18 @@ fn code_indented() {          "should support blank lines in indented code (3)"      ); -    // To do: paragraphs. +    // To do: strip whitespace.      // assert_eq!(      //     micromark("Foo\n    bar"),      //     "<p>Foo\nbar</p>",      //     "should not support interrupting paragraphs"      // ); -    // To do: paragraphs. -    // assert_eq!( -    //     micromark("    foo\nbar"), -    //     "<pre><code>foo\n</code></pre>\n<p>bar</p>", -    //     "should support paragraphs directly after indented code" -    // ); +    assert_eq!( +        micromark("    foo\nbar"), +        "<pre><code>foo\n</code></pre>\n<p>bar</p>", +        "should support paragraphs directly after indented code" +    );      // To do: setext.      // assert_eq!( diff --git a/tests/heading_atx.rs b/tests/heading_atx.rs index b75d058..7a830fe 100644 --- a/tests/heading_atx.rs +++ b/tests/heading_atx.rs @@ -99,7 +99,7 @@ fn heading_atx() {          "should not support four initial spaces"      ); -    // To do: lazy. +    // To do: strip whitespace.      // assert_eq!(      //     micromark("foo\n    # bar"),      //     "<p>foo\n# bar</p>", diff --git a/tests/html_flow.rs b/tests/html_flow.rs index 51d1a2a..18eff2d 100644 --- a/tests/html_flow.rs +++ b/tests/html_flow.rs @@ -115,12 +115,11 @@ p {color:blue;}          "should support an eof directly after a raw tag name"      ); -    // To do: paragraphs. -    // assert_eq!( -    //     micromark_with_options("</script\nmore", DANGER), -    //     "<p></script\nmore</p>", -    //     "should not support a raw closing tag" -    // ); +    assert_eq!( +        micromark_with_options("</script\nmore", DANGER), +        "<p></script\nmore</p>", +        "should not support a raw closing tag" +    );      assert_eq!(          micromark_with_options("<script/", DANGER), @@ -466,29 +465,29 @@ fn html_flow_6_basic() {      // );      // To do: paragraphs. -    //     assert_eq!( -    //         micromark_with_options( -    //             "<table> -    //   <tr> -    //     <td> -    //            hi -    //     </td> -    //   </tr> -    // </table> - -    // okay.", -    //             DANGER -    //         ), -    //         "<table> -    //   <tr> -    //     <td> -    //            hi -    //     </td> -    //   </tr> -    // </table> -    // <p>okay.</p>", -    //         "should support html of type 6 (1)" -    //     ); +    assert_eq!( +        micromark_with_options( +            "<table> +  <tr> +    <td> +           hi +    </td> +  </tr> +</table> + +okay.", +            DANGER +        ), +        "<table> +  <tr> +    <td> +           hi +    </td> +  </tr> +</table> +<p>okay.</p>", +        "should support html of type 6 (1)" +    );      assert_eq!(          micromark_with_options(" <div>\n  *hello*\n         <foo><a>", DANGER), @@ -502,7 +501,7 @@ fn html_flow_6_basic() {          "should support html starting w/ a closing tag"      ); -    // To do: phrasing +    // To do: phrasing.      // assert_eq!(      //     micromark_with_options("<DIV CLASS=\"foo\">\n\n*Markdown*\n\n</DIV>", DANGER),      //     "<DIV CLASS=\"foo\">\n<p><em>Markdown</em></p>\n</DIV>", @@ -740,12 +739,11 @@ fn html_flow_6_basic() {  #[test]  fn html_flow_7_complete() { -    // To do: phrasing. -    // assert_eq!( -    //     micromark_with_options("<a href=\"foo\">\n*bar*\n</a>", DANGER), -    //     "<a href=\"foo\">\n*bar*\n</a>", -    //     "should support complete tags (type 7)" -    // ); +    assert_eq!( +        micromark_with_options("<a href=\"foo\">\n*bar*\n</a>", DANGER), +        "<a href=\"foo\">\n*bar*\n</a>", +        "should support complete tags (type 7)" +    );      assert_eq!(          micromark_with_options("<Warning>\n*bar*\n</Warning>", DANGER), @@ -791,7 +789,7 @@ fn html_flow_7_complete() {          "should support interleaving w/ whitespace-only blank lines"      ); -    // To do: interrupting. +    // To do: disallow html (complete) from interrupting.      // assert_eq!(      //     micromark_with_options("Foo\n<a href=\"bar\">\nbaz", DANGER),      //     "<p>Foo\n<a href=\"bar\">\nbaz</p>", @@ -816,7 +814,7 @@ fn html_flow_7_complete() {          "should not support a line ending directly after a tag name"      ); -    // To do: paragraphs (trailing whitespace). +    // To do: trim trailing whitespace.      // assert_eq!(      //     micromark_with_options("<x ", DANGER),      //     "<p><x</p>", diff --git a/tests/thematic_break.rs b/tests/thematic_break.rs index 833fa6f..1e3fb1e 100644 --- a/tests/thematic_break.rs +++ b/tests/thematic_break.rs @@ -63,7 +63,7 @@ fn thematic_break() {          "should not support thematic breaks w/ 4 spaces"      ); -    // To do: paragraphs. +    // To do: trim initial whitespace.      // assert_eq!(      //     micromark("Foo\n    ***"),      //     "<p>Foo\n***</p>", | 
