From b7809264680d5302171935238d7a11824e915c93 Mon Sep 17 00:00:00 2001 From: Ashe Connor Date: Tue, 12 Feb 2019 11:01:01 +1100 Subject: [PATCH 1/4] vendor latest spec, cmark-gfm --- script/cibuild | 5 ++++- vendor/CommonMark | 2 +- vendor/cmark-gfm | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/script/cibuild b/script/cibuild index 16f8f53c..589ca9f1 100755 --- a/script/cibuild +++ b/script/cibuild @@ -2,7 +2,10 @@ set -evx -sudo apt-get install python3 +if which apt-get &>/dev/null; then + sudo apt-get install python3 +fi + cargo build --verbose if [ x"$SPEC" = "xtrue" ]; then diff --git a/vendor/CommonMark b/vendor/CommonMark index 542446ab..780b9816 160000 --- a/vendor/CommonMark +++ b/vendor/CommonMark @@ -1 +1 @@ -Subproject commit 542446ab42d323a81f4d7d1e5421359aa42b8357 +Subproject commit 780b981654dfdb070d82aa984c9e18f276ff48b3 diff --git a/vendor/cmark-gfm b/vendor/cmark-gfm index 9bdf783a..90048f92 160000 --- a/vendor/cmark-gfm +++ b/vendor/cmark-gfm @@ -1 +1 @@ -Subproject commit 9bdf783a11550cd5109d42f0a9b36e16d586e7c2 +Subproject commit 90048f92149657d572f63013ea099a0d7fef8f71 From 6a8ca190696f0de929488ea281e9329643d917a2 Mon Sep 17 00:00:00 2001 From: Ashe Connor Date: Tue, 12 Feb 2019 11:15:07 +1100 Subject: [PATCH 2/4] spec compliance: allow backtick after tilde fence --- src/lexer.pest | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lexer.pest b/src/lexer.pest index 55c7ff29..37919e30 100644 --- a/src/lexer.pest +++ b/src/lexer.pest @@ -1,7 +1,10 @@ atx_heading_start = { "#"{1, 6} ~ (" " | "\t" | "\r" | "\n") } -open_code_fence = _{ open_code_fence_match ~ (!("`" | "\r" | "\n" | "\x00") ~ ANY)* ~ ("\r" | "\n") } -open_code_fence_match = { "`"{3,} | "~"{3,} } +open_code_fence_backtick = _{ open_code_fence_backtick_match ~ (!("`" | "\r" | "\n" | "\x00") ~ ANY)* } +open_code_fence_backtick_match = { "`"{3,} } +open_code_fence_tilde = _{ open_code_fence_tilde_match ~ (!("\r" | "\n" | "\x00") ~ ANY)* } +open_code_fence_tilde_match = { "~"{3,} } +open_code_fence = _{ (open_code_fence_backtick | open_code_fence_tilde) ~ ("\r" | "\n") } close_code_fence = _{ close_code_fence_match ~ ("\t" | " ")* ~ ("\r" | "\n") } close_code_fence_match = { "`"{3,} | "~"{3,} } From 7e0f08a1eaa64cdcd2abf4b0bddbe41bc10b223e Mon Sep 17 00:00:00 2001 From: Ashe Connor Date: Tue, 12 Feb 2019 11:20:26 +1100 Subject: [PATCH 3/4] correct tasklist spec tests --- script/cibuild | 2 +- vendor/cmark-gfm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/script/cibuild b/script/cibuild index 589ca9f1..1863f6a0 100755 --- a/script/cibuild +++ b/script/cibuild @@ -11,7 +11,7 @@ cargo build --verbose if [ x"$SPEC" = "xtrue" ]; then cd vendor/cmark-gfm/test python3 spec_tests.py --program=../../../target/debug/comrak - python3 spec_tests.py --spec extensions.txt --program=../../../target/debug/comrak --extensions "table strikethrough autolink tagfilter footnotes" + python3 spec_tests.py --spec extensions.txt --program=../../../target/debug/comrak --extensions "table strikethrough autolink tagfilter footnotes tasklist" python3 roundtrip_tests.py --program=../../../target/debug/comrak python3 spec_tests.py --no-normalize --spec regression.txt --program=../../../target/debug/comrak python3 entity_tests.py --program=../../../target/debug/comrak diff --git a/vendor/cmark-gfm b/vendor/cmark-gfm index 90048f92..4b9523d3 160000 --- a/vendor/cmark-gfm +++ b/vendor/cmark-gfm @@ -1 +1 @@ -Subproject commit 90048f92149657d572f63013ea099a0d7fef8f71 +Subproject commit 4b9523d302aad37e201ead6bbcc1c48a7fcd3016 From cfd0723ce7b4802a1e72bd7f44de8b1082b07fef Mon Sep 17 00:00:00 2001 From: Ashe Connor Date: Tue, 12 Feb 2019 11:26:50 +1100 Subject: [PATCH 4/4] fix fence roundtrip with embedded backtick --- script/cibuild | 2 +- src/cm.rs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/script/cibuild b/script/cibuild index 1863f6a0..b1de4398 100755 --- a/script/cibuild +++ b/script/cibuild @@ -2,7 +2,7 @@ set -evx -if which apt-get &>/dev/null; then +if command -v apt-get &>/dev/null; then sudo apt-get install python3 fi diff --git a/src/cm.rs b/src/cm.rs index 67879da0..4b3ada9a 100644 --- a/src/cm.rs +++ b/src/cm.rs @@ -397,9 +397,15 @@ impl<'a, 'o> CommonMarkFormatter<'a, 'o> { let new_len = self.prefix.len() - 4; self.prefix.truncate(new_len); } else { - let numticks = max(3, longest_backtick_sequence(&ncb.literal) + 1); + let fence_char = + if ncb.info.contains(&b'`') { + b'~' + } else { + b'`' + }; + let numticks = max(3, longest_char_sequence(&ncb.literal, fence_char) + 1); for _ in 0..numticks { - write!(self, "`").unwrap(); + write!(self, "{}", fence_char as char).unwrap(); } if !ncb.info.is_empty() { write!(self, " ").unwrap(); @@ -409,7 +415,7 @@ impl<'a, 'o> CommonMarkFormatter<'a, 'o> { self.write_all(&ncb.literal).unwrap(); self.cr(); for _ in 0..numticks { - write!(self, "`").unwrap(); + write!(self, "{}", fence_char as char).unwrap(); } } self.blankline(); @@ -598,11 +604,11 @@ impl<'a, 'o> CommonMarkFormatter<'a, 'o> { } } -fn longest_backtick_sequence(literal: &[u8]) -> usize { +fn longest_char_sequence(literal: &[u8], ch: u8) -> usize { let mut longest = 0; let mut current = 0; for c in literal { - if *c == b'`' { + if *c == ch { current += 1; } else { if current > longest {