org.commonmark.ext.gfm.strikethrough.internal.StrikethroughDelimiterProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commonmark-ext-gfm-strikethrough Show documentation
Show all versions of commonmark-ext-gfm-strikethrough Show documentation
commonmark-java extension for GFM strikethrough using ~~ (GitHub Flavored Markdown)
package org.commonmark.ext.gfm.strikethrough.internal;
import org.commonmark.ext.gfm.strikethrough.Strikethrough;
import org.commonmark.node.Node;
import org.commonmark.node.Text;
import org.commonmark.parser.delimiter.DelimiterProcessor;
import org.commonmark.parser.delimiter.DelimiterRun;
public class StrikethroughDelimiterProcessor implements DelimiterProcessor {
@Override
public char getOpeningCharacter() {
return '~';
}
@Override
public char getClosingCharacter() {
return '~';
}
@Override
public int getMinLength() {
return 2;
}
@Override
public int getDelimiterUse(DelimiterRun opener, DelimiterRun closer) {
if (opener.length() >= 2 && closer.length() >= 2) {
// Use exactly two delimiters even if we have more, and don't care about internal openers/closers.
return 2;
} else {
return 0;
}
}
@Override
public void process(Text opener, Text closer, int delimiterCount) {
// Wrap nodes between delimiters in strikethrough.
Node strikethrough = new Strikethrough();
Node tmp = opener.getNext();
while (tmp != null && tmp != closer) {
Node next = tmp.getNext();
strikethrough.appendChild(tmp);
tmp = next;
}
opener.insertAfter(strikethrough);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy