Skip to content

Commit

Permalink
fix: strikethrough can be intra-word
Browse files Browse the repository at this point in the history
Fixes: #532
  • Loading branch information
Martin1887 committed May 21, 2023
1 parent 94cee9d commit e4d5305
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
11 changes: 1 addition & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions specs/regression.txt
Original file line number Diff line number Diff line change
Expand Up @@ -899,3 +899,18 @@ ISSUE 642
.
<p>[<code>]</code>]</p>
````````````````````````````````

ISSUE 532

```````````````````````````````` example
~~foo~~bar
.
<p><del>foo</del>bar</p>
````````````````````````````````

```````````````````````````````` example
foo~~bar~~
.
<p>foo<del>bar</del></p>
````````````````````````````````

8 changes: 5 additions & 3 deletions src/firstpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,8 @@ fn delim_run_can_open(s: &str, suffix: &str, run_len: usize, ix: usize) -> bool
return true;
}
let delim = suffix.chars().next().unwrap();
if delim == '*' && !is_punctuation(next_char) {
// `*` and `~~` can be intraword, `_` cannot
if (delim == '*' || delim == '~') && !is_punctuation(next_char) {
return true;
}

Expand All @@ -1506,7 +1507,7 @@ fn delim_run_can_open(s: &str, suffix: &str, run_len: usize, ix: usize) -> bool
}

/// Determines whether the delimiter run starting at given index is
/// left-flanking, as defined by the commonmark spec (and isn't intraword
/// right-flanking, as defined by the commonmark spec (and isn't intraword
/// for _ delims)
fn delim_run_can_close(s: &str, suffix: &str, run_len: usize, ix: usize) -> bool {
if ix == 0 {
Expand All @@ -1522,7 +1523,8 @@ fn delim_run_can_close(s: &str, suffix: &str, run_len: usize, ix: usize) -> bool
return true;
};
let delim = suffix.chars().next().unwrap();
if delim == '*' && !is_punctuation(prev_char) {
// `*` and `~~` can be intraword, `_` cannot
if (delim == '*' || delim == '~') && !is_punctuation(prev_char) {
return true;
}

Expand Down
20 changes: 20 additions & 0 deletions tests/suite/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,3 +1048,23 @@ fn regression_test_72() {

test_markdown_html(original, expected, false, false);
}

#[test]
fn regression_test_73() {
let original = r##"~~foo~~bar
"##;
let expected = r##"<p><del>foo</del>bar</p>
"##;

test_markdown_html(original, expected, false, false);
}

#[test]
fn regression_test_74() {
let original = r##"foo~~bar~~
"##;
let expected = r##"<p>foo<del>bar</del></p>
"##;

test_markdown_html(original, expected, false, false);
}

0 comments on commit e4d5305

Please sign in to comment.