Skip to content

Commit f2c94af

Browse files
wooormrawilder
andcommittedDec 5, 2023
Fix strikethrough, attention interplay
Closes GH-84. Closes GH-88. Co-authored-by: awilder <[email protected]>
1 parent 137a299 commit f2c94af

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed
 

‎src/construct/attention.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,22 @@ fn get_sequences(tokenizer: &mut Tokenizer) -> Vec<Sequence> {
239239
let exit = &tokenizer.events[end];
240240

241241
let marker = tokenizer.parse_state.bytes[enter.point.index];
242-
let before = classify_opt(char_before_index(
243-
tokenizer.parse_state.bytes,
244-
enter.point.index,
245-
));
246-
let after = classify_opt(char_after_index(
247-
tokenizer.parse_state.bytes,
248-
exit.point.index,
249-
));
242+
let before_char = char_before_index(tokenizer.parse_state.bytes, enter.point.index);
243+
let before = classify_opt(before_char);
244+
let after_char = char_after_index(tokenizer.parse_state.bytes, exit.point.index);
245+
let after = classify_opt(after_char);
250246
let open = after == CharacterKind::Other
251-
|| (after == CharacterKind::Punctuation && before != CharacterKind::Other);
247+
|| (after == CharacterKind::Punctuation && before != CharacterKind::Other)
248+
// For regular attention markers (not strikethrough), the
249+
// other attention markers can be used around them
250+
|| (marker != b'~' && matches!(after_char, Some('*' | '_')))
251+
|| (marker != b'~' && tokenizer.parse_state.options.constructs.gfm_strikethrough && matches!(after_char, Some('~')));
252252
let close = before == CharacterKind::Other
253-
|| (before == CharacterKind::Punctuation && after != CharacterKind::Other);
253+
|| (before == CharacterKind::Punctuation && after != CharacterKind::Other)
254+
|| (marker != b'~' && matches!(before_char, Some('*' | '_')))
255+
|| (marker != b'~'
256+
&& tokenizer.parse_state.options.constructs.gfm_strikethrough
257+
&& matches!(before_char, Some('~')));
254258

255259
sequences.push(Sequence {
256260
index,

‎src/util/char.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn classify(char: char) -> Kind {
9393
Kind::Whitespace
9494
}
9595
// Unicode punctuation.
96-
else if PUNCTUATION.contains(&char) {
96+
else if char.is_ascii_punctuation() || PUNCTUATION.contains(&char) {
9797
Kind::Punctuation
9898
}
9999
// Everything else.

‎tests/gfm_strikethrough.rs

+12
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,18 @@ u ~**xxx**~ zzz
363363
"should handle interplay like GitHub"
364364
);
365365

366+
assert_eq!(
367+
to_html_with_options("a*~b~*c\n\na*.b.*c", &Options::gfm())?,
368+
"<p>a<em><del>b</del></em>c</p>\n<p>a*.b.*c</p>",
369+
"should handle interplay w/ other attention markers (GFM)"
370+
);
371+
372+
assert_eq!(
373+
to_html("a*~b~*c\n\na*.b.*c"),
374+
"<p>a*~b~*c</p>\n<p>a*.b.*c</p>",
375+
"should handle interplay w/ other attention markers (CM reference)"
376+
);
377+
366378
assert_eq!(
367379
to_html_with_options(
368380
"a ~b~ ~~c~~ d",

0 commit comments

Comments
 (0)
Please sign in to comment.