Skip to content

Commit 9a61507

Browse files
authored
Merge pull request #56 from atlassian/issue-55-spec-0.26
Update to CommonMark spec 0.26 (#55)
2 parents d4d3814 + 863f1b4 commit 9a61507

15 files changed

Lines changed: 482 additions & 322 deletions

File tree

commonmark-ext-gfm-strikethrough/src/main/java/org/commonmark/ext/gfm/strikethrough/internal/StrikethroughDelimiterProcessor.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,39 @@
33
import org.commonmark.ext.gfm.strikethrough.Strikethrough;
44
import org.commonmark.node.Node;
55
import org.commonmark.node.Text;
6-
import org.commonmark.parser.DelimiterProcessor;
6+
import org.commonmark.parser.delimiter.DelimiterProcessor;
7+
import org.commonmark.parser.delimiter.DelimiterRun;
78

89
public class StrikethroughDelimiterProcessor implements DelimiterProcessor {
910

1011
@Override
11-
public char getOpeningDelimiterChar() {
12+
public char getOpeningCharacter() {
1213
return '~';
1314
}
1415

1516
@Override
16-
public char getClosingDelimiterChar() {
17+
public char getClosingCharacter() {
1718
return '~';
1819
}
1920

2021
@Override
21-
public int getMinDelimiterCount() {
22+
public int getMinLength() {
2223
return 2;
2324
}
2425

2526
@Override
26-
public int getDelimiterUse(int openerCount, int closerCount) {
27-
if (openerCount >= 2 && closerCount >= 2) {
27+
public int getDelimiterUse(DelimiterRun opener, DelimiterRun closer) {
28+
if (opener.length() >= 2 && closer.length() >= 2) {
29+
// Use exactly two delimiters even if we have more, and don't care about internal openers/closers.
2830
return 2;
2931
} else {
30-
// Can happen if a run had 3 delimiters before, and we removed 2 of them in an earlier processing step.
31-
// So just use 1 of them, see corresponding handling in process method.
32-
return 1;
32+
return 0;
3333
}
3434
}
3535

3636
@Override
3737
public void process(Text opener, Text closer, int delimiterCount) {
38-
// Can happen if a run had 3 or more delimiters, so 1 is left over. Don't turn that into strikethrough, but
39-
// preserve original character.
40-
if (delimiterCount == 1) {
41-
opener.insertAfter(new Text("~"));
42-
closer.insertBefore(new Text("~"));
43-
return;
44-
}
45-
46-
// Normal case, wrap nodes between delimiters in strikethrough.
38+
// Wrap nodes between delimiters in strikethrough.
4739
Node strikethrough = new Strikethrough();
4840

4941
Node tmp = opener.getNext();

commonmark-ext-gfm-strikethrough/src/test/java/org/commonmark/ext/gfm/strikethrough/StrikethroughTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ public void twoInnerThree() {
5050
}
5151

5252
@Test
53-
public void twoStrikethroughsWithoutSpacing() {
53+
public void tildesInside() {
54+
assertRendering("~~foo~bar~~", "<p><del>foo~bar</del></p>\n");
55+
assertRendering("~~foo~~bar~~", "<p><del>foo</del>bar~~</p>\n");
56+
assertRendering("~~foo~~~bar~~", "<p><del>foo</del>~bar~~</p>\n");
5457
assertRendering("~~foo~~~~bar~~", "<p><del>foo</del><del>bar</del></p>\n");
58+
assertRendering("~~foo~~~~~bar~~", "<p><del>foo</del>~<del>bar</del></p>\n");
59+
assertRendering("~~foo~~~~~~bar~~", "<p><del>foo</del>~~<del>bar</del></p>\n");
60+
assertRendering("~~foo~~~~~~~bar~~", "<p><del>foo</del>~~~<del>bar</del></p>\n");
5561
}
5662

5763
@Test

0 commit comments

Comments
 (0)