use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class InlineParserImpl method parseBackticks.
/**
* Attempt to parse backticks, adding either a backtick code span or a literal sequence of backticks.
*
* @return true if matched backticks, false otherwise
*/
protected boolean parseBackticks() {
BasedSequence ticks = match(myParsing.TICKS_HERE);
if (ticks == null) {
return false;
}
int afterOpenTicks = index;
BasedSequence matched;
while ((matched = match(myParsing.TICKS)) != null) {
if (matched.equals(ticks)) {
int ticksLength = ticks.length();
BasedSequence content = input.subSequence(afterOpenTicks - ticksLength, index - ticksLength);
final BasedSequence codeText = input.subSequence(afterOpenTicks, index - ticksLength);
Code node = new Code(input.subSequence(afterOpenTicks - ticksLength, afterOpenTicks), codeText, input.subSequence(index - ticksLength, index));
if (options.codeSoftLineBreaks) {
// add softbreaks to code ast
final int length = codeText.length();
int lastPos = 0;
while (lastPos < length) {
int softBreak = codeText.indexOfAny("\n\r", lastPos);
int pos = softBreak == -1 ? length : softBreak;
int lineBreak = pos;
final Text textNode = new Text(codeText.subSequence(lastPos, pos));
node.appendChild(textNode);
lastPos = pos;
if (lastPos >= length)
break;
if (codeText.charAt(lastPos) == '\r') {
lastPos++;
if (lastPos >= length)
break;
if (codeText.charAt(lastPos) == '\n')
lastPos++;
} else {
lastPos++;
}
if (lastPos >= length)
break;
if (lineBreak < lastPos) {
SoftLineBreak softLineBreak = new SoftLineBreak(codeText.subSequence(softBreak, lastPos));
node.appendChild(softLineBreak);
}
}
} else {
final Text textNode = new Text(codeText);
node.appendChild(textNode);
}
appendNode(node);
return true;
}
}
// If we got here, we didn't match a closing backtick sequence.
index = afterOpenTicks;
appendText(ticks);
return true;
}
Aggregations