Skip to content

Commit

Permalink
Fix strikethrough, attention interplay
Browse files Browse the repository at this point in the history
Closes GH-84.
Closes GH-88.

Co-authored-by: awilder <rawilder0506@gmail.com>
  • Loading branch information
wooorm and rawilder committed Dec 5, 2023
1 parent 137a299 commit f2c94af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
24 changes: 14 additions & 10 deletions src/construct/attention.rs
Expand Up @@ -239,18 +239,22 @@ fn get_sequences(tokenizer: &mut Tokenizer) -> Vec<Sequence> {
let exit = &tokenizer.events[end];

let marker = tokenizer.parse_state.bytes[enter.point.index];
let before = classify_opt(char_before_index(
tokenizer.parse_state.bytes,
enter.point.index,
));
let after = classify_opt(char_after_index(
tokenizer.parse_state.bytes,
exit.point.index,
));
let before_char = char_before_index(tokenizer.parse_state.bytes, enter.point.index);
let before = classify_opt(before_char);
let after_char = char_after_index(tokenizer.parse_state.bytes, exit.point.index);
let after = classify_opt(after_char);
let open = after == CharacterKind::Other
|| (after == CharacterKind::Punctuation && before != CharacterKind::Other);
|| (after == CharacterKind::Punctuation && before != CharacterKind::Other)
// For regular attention markers (not strikethrough), the
// other attention markers can be used around them
|| (marker != b'~' && matches!(after_char, Some('*' | '_')))
|| (marker != b'~' && tokenizer.parse_state.options.constructs.gfm_strikethrough && matches!(after_char, Some('~')));
let close = before == CharacterKind::Other
|| (before == CharacterKind::Punctuation && after != CharacterKind::Other);
|| (before == CharacterKind::Punctuation && after != CharacterKind::Other)
|| (marker != b'~' && matches!(before_char, Some('*' | '_')))
|| (marker != b'~'
&& tokenizer.parse_state.options.constructs.gfm_strikethrough
&& matches!(before_char, Some('~')));

sequences.push(Sequence {
index,
Expand Down
2 changes: 1 addition & 1 deletion src/util/char.rs
Expand Up @@ -93,7 +93,7 @@ pub fn classify(char: char) -> Kind {
Kind::Whitespace
}
// Unicode punctuation.
else if PUNCTUATION.contains(&char) {
else if char.is_ascii_punctuation() || PUNCTUATION.contains(&char) {
Kind::Punctuation
}
// Everything else.
Expand Down
12 changes: 12 additions & 0 deletions tests/gfm_strikethrough.rs
Expand Up @@ -363,6 +363,18 @@ u ~**xxx**~ zzz
"should handle interplay like GitHub"
);

assert_eq!(
to_html_with_options("a*~b~*c\n\na*.b.*c", &Options::gfm())?,
"<p>a<em><del>b</del></em>c</p>\n<p>a*.b.*c</p>",
"should handle interplay w/ other attention markers (GFM)"
);

assert_eq!(
to_html("a*~b~*c\n\na*.b.*c"),
"<p>a*~b~*c</p>\n<p>a*.b.*c</p>",
"should handle interplay w/ other attention markers (CM reference)"
);

assert_eq!(
to_html_with_options(
"a ~b~ ~~c~~ d",
Expand Down

0 comments on commit f2c94af

Please sign in to comment.