Skip to content

Commit 981c28d

Browse files
committed
Adjust strikethrough flanking rule to better fit Rustdoc Crater run
1 parent 86c5ff3 commit 981c28d

5 files changed

Lines changed: 306 additions & 5 deletions

File tree

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
This is an extension of gfm_strikethrough.txt. Some of these tests are also pulled from commonmark-hs.
2+
3+
# Two tildes
4+
5+
Basic strikethrough is between two tildes:
6+
7+
```````````````````````````````` example
8+
~~This is *stricken out*~~
9+
.
10+
<p><del>This is <em>stricken out</em></del></p>
11+
````````````````````````````````
12+
13+
Backslash escapes:
14+
15+
```````````````````````````````` example
16+
~~This is \~\~stricken~~
17+
.
18+
<p><del>This is ~~stricken</del></p>
19+
````````````````````````````````
20+
21+
Intraword strikeout:
22+
23+
```````````````````````````````` example
24+
This~~is~~stricken
25+
.
26+
<p>This<del>is</del>stricken</p>
27+
````````````````````````````````
28+
29+
```````````````````````````````` example
30+
~~This~~is~~stricken~~
31+
.
32+
<p><del>This</del>is<del>stricken</del></p>
33+
````````````````````````````````
34+
35+
Punctuation is ignored for purposes of determining
36+
flankingness on two tildes:
37+
38+
```````````````````````````````` example
39+
Here I strike out an exclamation point~~!~~.
40+
.
41+
<p>Here I strike out an exclamation point<del>!</del>.</p>
42+
````````````````````````````````
43+
44+
# One tilde
45+
46+
One tilde—and this is where we differ from commonmark-hs—is allowed in certain situations:
47+
48+
```````````````````````````````` example
49+
~This is stricken out~
50+
.
51+
<p><del>This is stricken out</del></p>
52+
````````````````````````````````
53+
54+
Backslash escapes:
55+
56+
```````````````````````````````` example
57+
~This is \~stricken~
58+
.
59+
<p><del>This is ~stricken</del></p>
60+
````````````````````````````````
61+
62+
Intraword strikeout requires two tildes:
63+
64+
```````````````````````````````` example
65+
This~is~nothing
66+
.
67+
<p>This~is~nothing</p>
68+
````````````````````````````````
69+
70+
```````````````````````````````` example
71+
~This~is~nothing~
72+
.
73+
<p><del>This~is~nothing</del></p>
74+
````````````````````````````````
75+
76+
Punctuation is used for purposes of determining
77+
flankingness:
78+
79+
```````````````````````````````` example
80+
Here I fail to strike out an exclamation point~!~.
81+
.
82+
<p>Here I fail to strike out an exclamation point~!~.</p>
83+
````````````````````````````````
84+
85+
Tilde runs can't mix.
86+
87+
```````````````````````````````` example
88+
Here I fail to strike out a tilde ~~~.
89+
.
90+
<p>Here I fail to strike out a tilde ~~~.</p>
91+
````````````````````````````````
92+
93+
```````````````````````````````` example
94+
Here I fail to match up ~~tildes~.
95+
.
96+
<p>Here I fail to match up ~~tildes~.</p>
97+
````````````````````````````````
98+
99+
```````````````````````````````` example
100+
Here I fail to match up ~tildes~~.
101+
.
102+
<p>Here I fail to match up ~tildes~~.</p>
103+
````````````````````````````````
104+
105+
Double tildes are allowed to contain single tildes, and the other way around:
106+
107+
```````````````````````````````` example
108+
~~This ~is stricken.~~
109+
.
110+
<p><del>This ~is stricken.</del></p>
111+
````````````````````````````````
112+
113+
```````````````````````````````` example
114+
~This ~~is stricken.~
115+
.
116+
<p><del>This ~~is stricken.</del></p>
117+
````````````````````````````````
118+
119+
The first one wins.
120+
121+
```````````````````````````````` example
122+
~This ~~is stricken~ but this is not~~
123+
.
124+
<p><del>This ~~is stricken</del> but this is not~~</p>
125+
````````````````````````````````

pulldown-cmark/src/firstpass.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,12 +2037,17 @@ fn delim_run_can_open(
20372037
}
20382038
}
20392039
let delim = suffix.chars().next().unwrap();
2040-
// `*` and `~~` can be intraword, `_` cannot
2041-
if (delim == '*' || delim == '~') && !is_punctuation(next_char) {
2040+
// `*` and `~~` can be intraword, `_` and `~` cannot
2041+
if delim == '*' && !is_punctuation(next_char) {
2042+
return true;
2043+
}
2044+
if delim == '~' && run_len > 1 {
20422045
return true;
20432046
}
2044-
20452047
let prev_char = s[..ix].chars().last().unwrap();
2048+
if delim == '~' && prev_char == '~' && !is_punctuation(next_char) {
2049+
return true;
2050+
}
20462051

20472052
prev_char.is_whitespace()
20482053
|| is_punctuation(prev_char) && (delim != '\'' || ![']', ')'].contains(&prev_char))
@@ -2079,8 +2084,11 @@ fn delim_run_can_close(
20792084
}
20802085
}
20812086
let delim = suffix.chars().next().unwrap();
2082-
// `*` and `~~` can be intraword, `_` cannot
2083-
if (delim == '*' || delim == '~') && !is_punctuation(prev_char) {
2087+
// `*` and `~~` can be intraword, `_` and `~` cannot
2088+
if (delim == '*' || (delim == '~' && run_len > 1)) && !is_punctuation(prev_char) {
2089+
return true;
2090+
}
2091+
if delim == '~' && prev_char == '~' {
20842092
return true;
20852093
}
20862094

pulldown-cmark/src/parse.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,9 @@ impl InlineStack {
12611261
.cloned()
12621262
.enumerate()
12631263
.rfind(|(_, el)| {
1264+
if c == b'~' && run_length != el.run_length {
1265+
return false;
1266+
}
12641267
el.c == c && (!both && !el.both || (run_length + el.run_length) % 3 != 0 || run_length % 3 == 0)
12651268
});
12661269

pulldown-cmark/tests/suite/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ mod old_footnotes;
1313
mod regression;
1414
mod smart_punct;
1515
mod spec;
16+
mod strikethrough;
1617
mod table;
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// This file is auto-generated by the build script
2+
// Please, do not modify it manually
3+
4+
use super::test_markdown_html;
5+
6+
#[test]
7+
fn strikethrough_test_1() {
8+
let original = r##"~~This is *stricken out*~~
9+
"##;
10+
let expected = r##"<p><del>This is <em>stricken out</em></del></p>
11+
"##;
12+
13+
test_markdown_html(original, expected, false, false, false);
14+
}
15+
16+
#[test]
17+
fn strikethrough_test_2() {
18+
let original = r##"~~This is \~\~stricken~~
19+
"##;
20+
let expected = r##"<p><del>This is ~~stricken</del></p>
21+
"##;
22+
23+
test_markdown_html(original, expected, false, false, false);
24+
}
25+
26+
#[test]
27+
fn strikethrough_test_3() {
28+
let original = r##"This~~is~~stricken
29+
"##;
30+
let expected = r##"<p>This<del>is</del>stricken</p>
31+
"##;
32+
33+
test_markdown_html(original, expected, false, false, false);
34+
}
35+
36+
#[test]
37+
fn strikethrough_test_4() {
38+
let original = r##"~~This~~is~~stricken~~
39+
"##;
40+
let expected = r##"<p><del>This</del>is<del>stricken</del></p>
41+
"##;
42+
43+
test_markdown_html(original, expected, false, false, false);
44+
}
45+
46+
#[test]
47+
fn strikethrough_test_5() {
48+
let original = r##"Here I strike out an exclamation point~~!~~.
49+
"##;
50+
let expected = r##"<p>Here I strike out an exclamation point<del>!</del>.</p>
51+
"##;
52+
53+
test_markdown_html(original, expected, false, false, false);
54+
}
55+
56+
#[test]
57+
fn strikethrough_test_6() {
58+
let original = r##"~This is stricken out~
59+
"##;
60+
let expected = r##"<p><del>This is stricken out</del></p>
61+
"##;
62+
63+
test_markdown_html(original, expected, false, false, false);
64+
}
65+
66+
#[test]
67+
fn strikethrough_test_7() {
68+
let original = r##"~This is \~stricken~
69+
"##;
70+
let expected = r##"<p><del>This is ~stricken</del></p>
71+
"##;
72+
73+
test_markdown_html(original, expected, false, false, false);
74+
}
75+
76+
#[test]
77+
fn strikethrough_test_8() {
78+
let original = r##"This~is~nothing
79+
"##;
80+
let expected = r##"<p>This~is~nothing</p>
81+
"##;
82+
83+
test_markdown_html(original, expected, false, false, false);
84+
}
85+
86+
#[test]
87+
fn strikethrough_test_9() {
88+
let original = r##"~This~is~nothing~
89+
"##;
90+
let expected = r##"<p><del>This~is~nothing</del></p>
91+
"##;
92+
93+
test_markdown_html(original, expected, false, false, false);
94+
}
95+
96+
#[test]
97+
fn strikethrough_test_10() {
98+
let original = r##"Here I fail to strike out an exclamation point~!~.
99+
"##;
100+
let expected = r##"<p>Here I fail to strike out an exclamation point~!~.</p>
101+
"##;
102+
103+
test_markdown_html(original, expected, false, false, false);
104+
}
105+
106+
#[test]
107+
fn strikethrough_test_11() {
108+
let original = r##"Here I fail to strike out a tilde ~~~.
109+
"##;
110+
let expected = r##"<p>Here I fail to strike out a tilde ~~~.</p>
111+
"##;
112+
113+
test_markdown_html(original, expected, false, false, false);
114+
}
115+
116+
#[test]
117+
fn strikethrough_test_12() {
118+
let original = r##"Here I fail to match up ~~tildes~.
119+
"##;
120+
let expected = r##"<p>Here I fail to match up ~~tildes~.</p>
121+
"##;
122+
123+
test_markdown_html(original, expected, false, false, false);
124+
}
125+
126+
#[test]
127+
fn strikethrough_test_13() {
128+
let original = r##"Here I fail to match up ~tildes~~.
129+
"##;
130+
let expected = r##"<p>Here I fail to match up ~tildes~~.</p>
131+
"##;
132+
133+
test_markdown_html(original, expected, false, false, false);
134+
}
135+
136+
#[test]
137+
fn strikethrough_test_14() {
138+
let original = r##"~~This ~is stricken.~~
139+
"##;
140+
let expected = r##"<p><del>This ~is stricken.</del></p>
141+
"##;
142+
143+
test_markdown_html(original, expected, false, false, false);
144+
}
145+
146+
#[test]
147+
fn strikethrough_test_15() {
148+
let original = r##"~This ~~is stricken.~
149+
"##;
150+
let expected = r##"<p><del>This ~~is stricken.</del></p>
151+
"##;
152+
153+
test_markdown_html(original, expected, false, false, false);
154+
}
155+
156+
#[test]
157+
fn strikethrough_test_16() {
158+
let original = r##"~This ~~is stricken~ but this is not~~
159+
"##;
160+
let expected = r##"<p><del>This ~~is stricken</del> but this is not~~</p>
161+
"##;
162+
163+
test_markdown_html(original, expected, false, false, false);
164+
}

0 commit comments

Comments
 (0)