|
3 | 3 | import org.commonmark.ext.gfm.strikethrough.Strikethrough; |
4 | 4 | import org.commonmark.node.Node; |
5 | 5 | 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; |
7 | 8 |
|
8 | 9 | public class StrikethroughDelimiterProcessor implements DelimiterProcessor { |
9 | 10 |
|
10 | 11 | @Override |
11 | | - public char getOpeningDelimiterChar() { |
| 12 | + public char getOpeningCharacter() { |
12 | 13 | return '~'; |
13 | 14 | } |
14 | 15 |
|
15 | 16 | @Override |
16 | | - public char getClosingDelimiterChar() { |
| 17 | + public char getClosingCharacter() { |
17 | 18 | return '~'; |
18 | 19 | } |
19 | 20 |
|
20 | 21 | @Override |
21 | | - public int getMinDelimiterCount() { |
| 22 | + public int getMinLength() { |
22 | 23 | return 2; |
23 | 24 | } |
24 | 25 |
|
25 | 26 | @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. |
28 | 30 | return 2; |
29 | 31 | } 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; |
33 | 33 | } |
34 | 34 | } |
35 | 35 |
|
36 | 36 | @Override |
37 | 37 | 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. |
47 | 39 | Node strikethrough = new Strikethrough(); |
48 | 40 |
|
49 | 41 | Node tmp = opener.getNext(); |
|
0 commit comments