org.commonmark.ext.ins.internal.InsDelimiterProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commonmark-ext-ins Show documentation
Show all versions of commonmark-ext-ins Show documentation
commonmark-java extension for <ins> using ++
package org.commonmark.ext.ins.internal;
import org.commonmark.ext.ins.Ins;
import org.commonmark.node.Node;
import org.commonmark.node.Text;
import org.commonmark.parser.delimiter.DelimiterProcessor;
import org.commonmark.parser.delimiter.DelimiterRun;
public class InsDelimiterProcessor 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 ins.
Node ins = new Ins();
Node tmp = opener.getNext();
while (tmp != null && tmp != closer) {
Node next = tmp.getNext();
ins.appendChild(tmp);
tmp = next;
}
opener.insertAfter(ins);
}
}