aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/compiler.rs9
-rw-r--r--tests/commonmark.rs103
2 files changed, 58 insertions, 54 deletions
diff --git a/src/compiler.rs b/src/compiler.rs
index c4178d4..07f0d6b 100644
--- a/src/compiler.rs
+++ b/src/compiler.rs
@@ -451,6 +451,7 @@ pub fn compile(events: &[Event], codes: &[Code], options: &Options) -> String {
let mut exit_map: Map = HashMap::new();
exit_map.insert(Token::AutolinkEmail, on_exit_autolink_email);
exit_map.insert(Token::AutolinkProtocol, on_exit_autolink_protocol);
+ exit_map.insert(Token::BlankLineEnding, on_exit_blank_line_ending);
exit_map.insert(Token::BlockQuote, on_exit_block_quote);
exit_map.insert(Token::CharacterEscapeValue, on_exit_data);
exit_map.insert(
@@ -857,10 +858,18 @@ fn on_exit_break(context: &mut CompileContext) {
context.tag("<br />".to_string());
}
+/// Handle [`Exit`][EventType::Exit]:[`BlankLineEnding`][Token::BlankLineEnding].
+fn on_exit_blank_line_ending(context: &mut CompileContext) {
+ if context.index == context.events.len() - 1 {
+ context.line_ending_if_needed();
+ }
+}
+
/// Handle [`Exit`][EventType::Exit]:[`BlockQuote`][Token::BlockQuote].
fn on_exit_block_quote(context: &mut CompileContext) {
context.tight_stack.pop();
context.line_ending_if_needed();
+ context.slurp_one_line_ending = false;
context.tag("</blockquote>".to_string());
}
diff --git a/tests/commonmark.rs b/tests/commonmark.rs
index cec6116..1843a51 100644
--- a/tests/commonmark.rs
+++ b/tests/commonmark.rs
@@ -2623,18 +2623,17 @@ bar
r###"Link reference definitions (216)"###
);
- // To do: eol after definition in otherwise empty block quote.
-// assert_eq!(
-// micromark_with_options(r###"[foo]
+ assert_eq!(
+ micromark_with_options(r###"[foo]
-// > [foo]: /url
-// "###, DANGER),
-// r###"<p><a href="/url">foo</a></p>
-// <blockquote>
-// </blockquote>
-// "###,
-// r###"Link reference definitions (217)"###
-// );
+> [foo]: /url
+"###, DANGER),
+ r###"<p><a href="/url">foo</a></p>
+<blockquote>
+</blockquote>
+"###,
+ r###"Link reference definitions (217)"###
+);
assert_eq!(
micromark_with_options(r###"aaa
@@ -2896,40 +2895,37 @@ foo
// r###"Block quotes (237)"###
// );
- // To do: some eol in empty block quote bug.
- // assert_eq!(
- // micromark_with_options(r###">
- // "###, DANGER),
- // r###"<blockquote>
- // </blockquote>
- // "###,
- // r###"Block quotes (238)"###
- // );
+ assert_eq!(
+ micromark_with_options(r###">
+"###, DANGER),
+ r###"<blockquote>
+</blockquote>
+"###,
+ r###"Block quotes (238)"###
+);
- // To do: some eol in empty block quote bug.
- // assert_eq!(
- // micromark_with_options(r###">
- // >
- // >
- // "###, DANGER),
- // r###"<blockquote>
- // </blockquote>
- // "###,
- // r###"Block quotes (239)"###
- // );
+ assert_eq!(
+ micromark_with_options(r###">
+>
+>
+"###, DANGER),
+ r###"<blockquote>
+</blockquote>
+"###,
+ r###"Block quotes (239)"###
+);
- // To do: some eol in empty block quote bug.
- // assert_eq!(
- // micromark_with_options(r###">
- // > foo
- // >
- // "###, DANGER),
- // r###"<blockquote>
- // <p>foo</p>
- // </blockquote>
- // "###,
- // r###"Block quotes (240)"###
- // );
+ assert_eq!(
+ micromark_with_options(r###">
+> foo
+>
+"###, DANGER),
+ r###"<blockquote>
+<p>foo</p>
+</blockquote>
+"###,
+ r###"Block quotes (240)"###
+);
assert_eq!(
micromark_with_options(r###"> foo
@@ -2999,7 +2995,7 @@ bar</p>
r###"Block quotes (245)"###
);
- // To do: some eol in empty block quote bug.
+ // To do: some lazy bug.
// assert_eq!(
// micromark_with_options(r###"> bar
// baz
@@ -3564,16 +3560,15 @@ bar
r###"List items (282)"###
);
- // To do: some bug w/ line endings and empty items.
- // assert_eq!(
- // micromark_with_options(r###"*
- // "###, DANGER),
- // r###"<ul>
- // <li></li>
- // </ul>
- // "###,
- // r###"List items (283)"###
- // );
+ assert_eq!(
+ micromark_with_options(r###"*
+"###, DANGER),
+ r###"<ul>
+<li></li>
+</ul>
+"###,
+ r###"List items (283)"###
+);
assert_eq!(
micromark_with_options(r###"foo