use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class FormattingAppendableImpl method appendImpl.
private void appendImpl(final CharSequence csq, final int start, final int end) throws IOException {
int lastPos = start;
BasedSequence seq = BasedSequenceImpl.of(csq);
if (myPreFormattedNesting > 0) {
setOffsetBefore(myAppendable.getLength());
int endNoEOL = start + seq.subSequence(start, end).removeSuffix("\n").length();
if (lastPos < end) {
beforePre();
}
while (lastPos < endNoEOL) {
int pos = seq.indexOf(myEOL, lastPos, endNoEOL);
int endPos = pos == -1 ? endNoEOL : pos + 1;
if (lastPos < endPos) {
if (myPendingPreFormattedPrefix && !myPrefix.isEmpty()) {
myAppendable.append(myPrefix);
}
myPendingPreFormattedPrefix = false;
myAppendable.append(csq, lastPos, endPos);
lastPos = endPos;
}
if (pos == -1)
break;
myLineCount++;
myPendingPreFormattedPrefix = true;
lastPos = endPos;
}
myModCount++;
// if EOL is last then we reset pending and eol mod count
if (lastPos == endNoEOL && endNoEOL != end) {
myPendingEOL = 1;
myPendingPreFormattedPrefix = true;
}
} else {
// have to handle \n, white spaces, etc
boolean firstAppend = true;
while (lastPos < end) {
int pos = seq.indexOfAny(myWhitespaceEOL, lastPos, end);
// output what has accumulated before
int spanEnd = pos == -1 ? end : pos;
if (lastPos < spanEnd) {
beforeAppendText(true, true, true);
if (firstAppend) {
setOffsetBefore(myAppendable.getLength());
firstAppend = false;
}
myAppendable.append(csq, lastPos, spanEnd);
myModCount++;
}
if (pos == -1)
break;
// spaces and tabs are only output if we don't have a pending EOL and they don't come before an EOL
int span = seq.countChars(myWhitespaceEOL, pos, end);
if (myPendingEOL == 0) {
int eolPos = seq.indexOf(myEOL, pos, pos + span);
if (eolPos != -1) {
// we don't output the spaces after the EOL but make EOL pending
if (eolPos > pos && !haveOptions(SUPPRESS_TRAILING_WHITESPACE))
addPendingSpaces(eolPos - pos);
setPendingEOL(1);
} else {
// no eol, make spaces pending
addPendingSpaces(span);
}
} else {
// we are coming after an EOL, all whitespaces are ignored
}
pos += span;
lastPos = pos;
}
}
}
use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class BlockContent method getString.
public String getString() {
if (lines.size() == 0)
return "";
StringBuilder sb = new StringBuilder();
for (BasedSequence line : lines) {
sb.append(line.trimEOL());
sb.append('\n');
}
return sb.toString();
}
use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class EnumRefTextCollectingVisitor method visit.
private void visit(HardLineBreak node) {
final BasedSequence chars = node.getChars();
out.append(chars.subSequence(chars.length() - 1, chars.length()));
}
use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class EnumeratedReferenceLinkRefProcessor method createNode.
@Override
public Node createNode(BasedSequence nodeChars) {
BasedSequence enumeratedReferenceId = nodeChars.midSequence(2, -1).trim();
EnumeratedReferenceBlock enumeratedReferenceBlock = enumeratedReferenceId.length() > 0 ? enumeratedReferenceRepository.get(enumeratedReferenceId.toString()) : null;
if (nodeChars.charAt(1) == '@') {
// reference link
EnumeratedReferenceLink enumeratedReference = new EnumeratedReferenceLink(nodeChars.subSequence(0, 2), enumeratedReferenceId, nodeChars.endSequence(1));
enumeratedReference.setEnumeratedReferenceBlock(enumeratedReferenceBlock);
return enumeratedReference;
} else {
// reference text
EnumeratedReferenceText enumeratedReferenceText = new EnumeratedReferenceText(nodeChars.subSequence(0, 2), enumeratedReferenceId, nodeChars.endSequence(1));
enumeratedReferenceText.setEnumeratedReferenceBlock(enumeratedReferenceBlock);
return enumeratedReferenceText;
}
}
use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class YouTubeLinkNodePostProcessor method process.
@Override
public void process(NodeTracker state, Node node) {
if (node instanceof Link) {
Node previous = node.getPrevious();
if (previous instanceof Text) {
final BasedSequence chars = previous.getChars();
if (chars.endsWith("@") && chars.isContinuedBy(node.getChars())) {
// trim previous chars to remove '@'
previous.setChars(chars.subSequence(0, chars.length() - 1));
YouTubeLink youTubeLink = new YouTubeLink((Link) node);
youTubeLink.takeChildren(node);
node.unlink();
previous.insertAfter(youTubeLink);
state.nodeRemoved(node);
state.nodeAddedWithChildren(youTubeLink);
}
}
}
}
Aggregations