private boolean isEscaped(final BasedSequence chars, String prefix) { int backslashCount = chars.subSequence(0, chars.length() - prefix.length()).countTrailing('\\'); return (backslashCount & 1) != 0; }
static boolean endsWithMarker(BasedSequence line) { int tailBlanks = line.countTrailing(BasedSequence.WHITESPACE_NBSP_CHARS); return tailBlanks + 1 < line.length() && line.charAt(line.length() - tailBlanks - 1) == '|'; }
public void setLink(BasedSequence linkChars, boolean allowAnchors, boolean canEscapeAnchor) { // now parse out the # from the link this.link = linkChars; if (!allowAnchors) { this.pageRef = linkChars; } else { int pos = -1; do { pos = linkChars.indexOf('#', pos + 1); } while (pos != -1 && canEscapeAnchor && (pos > 0 && linkChars.charAt(pos - 1) == '\\' && (linkChars.subSequence(0, pos).countTrailing('\\') & 1) == 1)); if (pos < 0) { this.pageRef = linkChars; } else { this.pageRef = linkChars.subSequence(0, pos); this.anchorMarker = linkChars.subSequence(pos, pos + 1); this.anchorRef = linkChars.subSequence(pos + 1); } } }
private void outputNextLineBreakSpan(final Node node, final HtmlWriter html, final boolean outputBreakText) { final Range range = myLines.get(myNextLine); int eolLength = myEOLs.get(myNextLine); myNextLine++; // remove trailing spaces from text int countTrailing = node.getChars().baseSubSequence(nextLineStartOffset, range.getEnd() - eolLength).countTrailing(" \t"); if (!outputBreakText && countTrailing > 0) { countTrailing--; } eolLength += countTrailing; html.srcPos(nextLineStartOffset, range.getEnd() - eolLength).withAttr(PARAGRAPH_LINE).tag("span"); nextLineStartOffset = range.getEnd(); // remove leading spaces nextLineStartOffset += node.getChars().baseSubSequence(nextLineStartOffset, node.getChars().getBaseSequence().length()).countLeading(BasedSequence.WHITESPACE_NO_EOL_CHARS); }
if (line.length() == typeBreakLength + line.countTrailing(BasedSequence.EOL_CHARS) && line.matchChars(typeBreak)) { if (inSource) { inSource = false; if (sectionStart != -1) { block.setSource(line.baseSubSequence(sectionStart, line.getStartOffset() - prevLine.countTrailing(BasedSequence.EOL_CHARS))); } else { block.setSource(line.subSequence(0, 0)); inHtml = false; if (sectionStart != -1) { block.setHtml(line.baseSubSequence(sectionStart, line.getStartOffset() - prevLine.countTrailing(BasedSequence.EOL_CHARS))); } else { block.setHtml(line.subSequence(0, 0)); block.setSource(line.baseSubSequence(sectionStart, line.getEndOffset() - prevLine.countTrailing(BasedSequence.EOL_CHARS))); } else { block.setSource(line.subSequence(line.length(), line.length())); block.setHtml(line.baseSubSequence(sectionStart, line.getEndOffset() - prevLine.countTrailing(BasedSequence.EOL_CHARS))); } else { block.setHtml(line.subSequence(line.length(), line.length())); block.setAst(line.baseSubSequence(sectionStart, line.getEndOffset() - prevLine.countTrailing(BasedSequence.EOL_CHARS))); } else { block.setAst(line.subSequence(line.length(), line.length()));
private void outputSourceLineSpan(final Node parentNode, final Node startNode, final Node endNode, final HtmlWriter html) { int startOffset = startNode.getStartOffset(); final Range range = myLines.get(myNextLine); int eolLength = myEOLs.get(myNextLine); // remove trailing spaces from text int endOffset = endNode.getEndOffset(); if (range.getEnd() <= endOffset) { endOffset = range.getEnd(); endOffset -= eolLength; endOffset -= parentNode.getChars().baseSubSequence(startOffset, endOffset).countTrailing(BasedSequence.WHITESPACE_NO_EOL_CHARS); myNextLine++; nextLineStartOffset = range.getEnd(); nextLineStartOffset += parentNode.getChars().baseSubSequence(nextLineStartOffset, parentNode.getChars().getEndOffset()).countLeading(BasedSequence.WHITESPACE_NO_EOL_CHARS); } if (range.getStart() > startOffset) { startOffset = range.getStart(); } html.srcPos(startOffset, endOffset).withAttr(PARAGRAPH_LINE).tag("span"); }
do { pos = linkChars.lastIndexOf('|', pos - 1); } while (pos != -1 && canEscapePipe && (pos > 0 && linkChars.charAt(pos - 1) == '\\' && (linkChars.subSequence(0, pos).countTrailing('\\') & 1) == 1)); } else { pos = -1; do { pos = linkChars.indexOf('|', pos + 1); } while (pos != -1 && canEscapePipe && (pos > 0 && linkChars.charAt(pos - 1) == '\\' && (linkChars.subSequence(0, pos).countTrailing('\\') & 1) == 1));
@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())) { int prevBackslash = chars.subSequence(0, chars.length() - 1).countTrailing('\\'); if ((prevBackslash & 1) == 0) { // 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); } } } } }
static boolean endsWithMarker(BasedSequence line) { int tailBlanks = line.countTrailing(BasedSequence.WHITESPACE_NBSP_CHARS); return tailBlanks + 1 < line.length() && line.charAt(line.length() - tailBlanks - 1) == '|'; }
private void outputNextLineBreakSpan(final Node node, final HtmlWriter html, final boolean outputBreakText) { final Range range = myLines.get(myNextLine); int eolLength = myEOLs.get(myNextLine); myNextLine++; // remove trailing spaces from text int countTrailing = node.getChars().baseSubSequence(nextLineStartOffset, range.getEnd() - eolLength).countTrailing(" \t"); if (!outputBreakText && countTrailing > 0) { countTrailing--; } eolLength += countTrailing; html.srcPos(nextLineStartOffset, range.getEnd() - eolLength).withAttr(PARAGRAPH_LINE).tag("span"); nextLineStartOffset = range.getEnd(); // remove leading spaces nextLineStartOffset += node.getChars().baseSubSequence(nextLineStartOffset, node.getChars().getBaseSequence().length()).countLeading(BasedSequence.WHITESPACE_NO_EOL_CHARS); }
private void outputSourceLineSpan(final Node parentNode, final Node startNode, final Node endNode, final HtmlWriter html) { int startOffset = startNode.getStartOffset(); final Range range = myLines.get(myNextLine); int eolLength = myEOLs.get(myNextLine); // remove trailing spaces from text int endOffset = endNode.getEndOffset(); if (range.getEnd() <= endOffset) { endOffset = range.getEnd(); endOffset -= eolLength; endOffset -= parentNode.getChars().baseSubSequence(startOffset, endOffset).countTrailing(BasedSequence.WHITESPACE_NO_EOL_CHARS); myNextLine++; nextLineStartOffset = range.getEnd(); nextLineStartOffset += parentNode.getChars().baseSubSequence(nextLineStartOffset, parentNode.getChars().getEndOffset()).countLeading(BasedSequence.WHITESPACE_NO_EOL_CHARS); } if (range.getStart() > startOffset) { startOffset = range.getStart(); } html.srcPos(startOffset, endOffset).withAttr(PARAGRAPH_LINE).tag("span"); }
if (line.length() == typeBreakLength + line.countTrailing(BasedSequence.EOL_CHARS) && line.matchChars(typeBreak)) { if (inSource) { inSource = false; if (sectionStart != -1) { block.setSource(line.baseSubSequence(sectionStart, line.getStartOffset() - prevLine.countTrailing(BasedSequence.EOL_CHARS))); } else { block.setSource(line.subSequence(0, 0)); inHtml = false; if (sectionStart != -1) { block.setHtml(line.baseSubSequence(sectionStart, line.getStartOffset() - prevLine.countTrailing(BasedSequence.EOL_CHARS))); } else { block.setHtml(line.subSequence(0, 0)); block.setSource(line.baseSubSequence(sectionStart, line.getEndOffset() - prevLine.countTrailing(BasedSequence.EOL_CHARS))); } else { block.setSource(line.subSequence(line.length(), line.length())); block.setHtml(line.baseSubSequence(sectionStart, line.getEndOffset() - prevLine.countTrailing(BasedSequence.EOL_CHARS))); } else { block.setHtml(line.subSequence(line.length(), line.length())); block.setAst(line.baseSubSequence(sectionStart, line.getEndOffset() - prevLine.countTrailing(BasedSequence.EOL_CHARS))); } else { block.setAst(line.subSequence(line.length(), line.length()));
@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())) { int prevBackslash = chars.subSequence(0, chars.length() - 1).countTrailing('\\'); if ((prevBackslash & 1) == 0) { // 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); } } } } }