Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions script/cibuild
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

set -evx

sudo apt-get install python3
if command -v apt-get &>/dev/null; then
sudo apt-get install python3
fi

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
Expand Down
16 changes: 11 additions & 5 deletions src/cm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions src/lexer.pest
Original file line number Diff line number Diff line change
@@ -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,} }
Expand Down
2 changes: 1 addition & 1 deletion vendor/CommonMark
2 changes: 1 addition & 1 deletion vendor/cmark-gfm