public static void mergeTextNodes(Node parent) { Node prevNode = null; Node child = parent.getFirstChild(); while (child != null) { Node nextChild = child.getNext(); if (prevNode instanceof Text && child instanceof Text && prevNode.getChars().isContinuedBy(child.getChars())) { // merge them child.setChars(prevNode.getChars().spliceAtEnd(child.getChars())); prevNode.unlink(); } prevNode = child; child = nextChild; } }
@Override public void moveNodes(Node fromNode, Node toNode) { if (fromNode != toNode) { Node next = fromNode.getNext(); while (next != null) { Node nextNode = next.getNext(); next.unlink(); fromNode.appendChild(next); if (next == toNode) break; next = nextNode; } } fromNode.setCharsFromContent(); }
public boolean isLastBlockQuoteChild(Node node) { Node parent = node.getParent(); return parent instanceof BlockQuote && parent.getLastChild() == node; }
ArrayList<Node> mergeTextParents = null; for (Node node : sepList) { if (node.getParent() != null && node.getParent() != tableRow) { Node firstNode = node.getPrevious() instanceof WhiteSpace ? node.getPrevious() : node; Node lastNode = node.getNext() instanceof WhiteSpace ? node.getNext() : node; Text text = new Text(node.getChars().baseSubSequence(firstNode.getStartOffset(), lastNode.getEndOffset())); node.insertBefore(text); node.unlink(); firstNode.unlink(); lastNode.unlink(); inlineParser.mergeTextNodes(parent.getFirstChild(), parent.getLastChild());
blankLine.extractChainTo(trailingBlankLines); Node afterParagraph = previous.getNext(); if (options.doubleBlankLineBreaksList) { final BasedSequence interSpace = paragraphPreviousNonBlank == null ? BasedSequence.NULL : BasedSequenceImpl.of(paragraphPreviousNonBlank.getChars().baseSubSequence(paragraphPreviousNonBlank.getChars().getEndOffset(), paragraph.getChars().getStartOffset()).normalizeEOL()); hadPreviousList = paragraphPreviousNonBlank instanceof DefinitionList && interSpace.countChars('\n') < 2; } else { Node next = afterParagraph.getNext(); afterParagraph.unlink(); definitionList.appendChild(afterParagraph); afterParagraph = next; previousList.takeChildren(definitionList); for (Node node : definitionList.getChildren()) { node.unlink(); previousList.appendChild(node); state.blockAddedWithChildren((Block) node); paragraphPrevious.insertAfter(definitionList); } else { if (paragraphParent.getFirstChild() != null) { paragraphParent.getFirstChild().insertBefore(definitionList); } else { paragraphParent.appendChild(definitionList);
Node child = getFirstChild(); ArrayList<BasedSequence> segments = null; Node last = child; if (child.getChars() instanceof SegmentedSequence || child.getChars() instanceof PrefixedSubSequence) { if (last == child.getPrevious()) { segments.add(last.getChars()); } else { segments.add(last.getChars().baseSubSequence(last.getStartOffset(), child.getPrevious().getEndOffset())); segments.add(child.getChars()); last = child.getNext(); child = child.getNext(); child = getLastChild(); if (last != null) { segments.add(last.getChars().baseSubSequence(last.getStartOffset(), child.getEndOffset())); return firstChild.getChars().baseSubSequence(firstChild.getStartOffset(), lastChild.getEndOffset());
public void mergeWhiteSpace() { boolean hadWhitespace = false; Node child = getFirstChild(); while (child instanceof WhiteSpace) { Node next = child.getNext(); Text text = new Text(child.getChars()); child.insertBefore(text); child.unlink(); child = next; hadWhitespace = true; } child = getLastChild(); while (child instanceof WhiteSpace) { Node previous = child.getPrevious(); Text text = new Text(child.getChars()); child.insertBefore(text); child.unlink(); child = previous; hadWhitespace = true; } if (hadWhitespace) { TextNodeConverter.mergeTextNodes(this); } }
if (abbreviations == null) return; BasedSequence original = node.getChars(); ReplacedTextMapper textMapper = new ReplacedTextMapper(original); BasedSequence literal = Escaping.unescape(original, textMapper); boolean wrapInTextBase = !(node.getParent() instanceof TextBase); TextBase textBase = wrapInTextBase ? null : (TextBase) node.getParent(); wrapInTextBase = false; textBase = new TextBase(original); node.insertBefore(textBase); state.nodeAdded(textBase); node.unlink(); state.nodeRemoved(node);
public static BasedSequence getSoftLineBreakSpan(Node node) { if (node == null) return NULL; Node lastNode = node; Node nextNode = node.getNext(); while (nextNode != null && !(nextNode instanceof SoftLineBreak)) { lastNode = nextNode; nextNode = nextNode.getNext(); } return Node.spanningChars(node.getChars(), lastNode.getChars()); }
if (node.getAncestorOfType(DoNotDecorate.class, DoNotLinkDecorate.class) != null) return; BasedSequence combined = node.getChars(); BasedSequence original = combined; Node firstNode = node; Node lastNode = node; if (node.getNext() instanceof TypographicText) { if (node.getNext().getChars().isContinuationOf(combined)) { Node typoGraphic = node.getNext(); ArrayList<BasedSequence> combinedSequences = new ArrayList<>(); combinedSequences.add(combined); if (!typoGraphic.getChars().isContinuationOf(combined) || typoGraphic.getChars().startsWith(" ") || combined.endsWith(" ")) break; combined = typoGraphic.getChars(); combinedSequences.add(combined); lastNode = typoGraphic; typoGraphic = typoGraphic.getNext(); boolean wrapInTextBase = !(node.getParent() instanceof TextBase); TextBase textBase = wrapInTextBase || !(node.getParent() instanceof TextBase) ? null : (TextBase) node.getParent(); boolean processedNode = false; if (startOffset >= node.getChars().length()) { wrapInTextBase = false; textBase = new TextBase(original); node.insertBefore(textBase);
if (parent.getParent() instanceof ParagraphItemContainer) { Node parentPreviousNotBlankLine = parent.getPreviousAnyNot(BlankLine.class); if (parentPreviousNotBlankLine == null) { attributeOwner = parent.getParent().getParent(); } else { if (attributesNode.getNextAnyNot(AttributesNode.class, BlankLine.class) == null) { Node parentPreviousNotBlankLine = parent.getPreviousAnyNot(BlankLine.class); if (parentPreviousNotBlankLine == null) { attributeOwner = parent.getParent(); } else { if ((!myOptions.assignTextAttributes && (previous instanceof Text || previous instanceof TextBase)) || previous.getChars().getEndOffset() < attributesNode.getStartOffset()) { } else if (parent instanceof Paragraph && parent.getParent() instanceof ParagraphItemContainer) { attributeOwner = parent.getParent(); } else { attributeOwner = parent; first = first.getPrevious(); TextBase textBase = new TextBase(previous.getChars()); previous.insertBefore(textBase); previous.unlink(); state.nodeRemoved(previous);
public Node getChildOfType(Class... classes) { Node child = getFirstChild(); while (child != null) { for (Class nodeType : classes) { if (nodeType.isInstance(child)) return child; } child = child.getNext(); } return null; }
public BasedSequence getMacroContentChars() { Node firstChild = getFirstChild(); Node lastChild = getLastChild(); Node firstContentNode = firstChild.getNext(); Node lastContentNode = lastChild instanceof MacroClose ? lastChild.getPrevious() : lastChild; //noinspection UnnecessaryLocalVariable BasedSequence contentChars = Node.spanningChars(firstContentNode == null || firstContentNode instanceof MacroClose ? BasedSequence.NULL : firstContentNode.getChars(), lastContentNode == null || lastContentNode == firstChild ? BasedSequence.NULL : lastContentNode.getChars()); return contentChars; } }
@Override public BasedSequence adjustInlineText(Document document, Node node) { // nothing to do, our prefixes are stripped out of a link ref return node.getChars(); }
@Override public void mergeIfNeeded(Text first, Text last) { if (first != null && last != null && first != last) { ArrayList<BasedSequence> sb = new ArrayList<BasedSequence>(); sb.add(first.getChars()); Node node = first.getNext(); Node stop = last.getNext(); while (node != stop) { sb.add(node.getChars()); Node unlink = node; node = node.getNext(); unlink.unlink(); } BasedSequence literal = SegmentedSequence.of(sb); first.setChars(literal); } }
@Override public void process(NodeTracker state, Node node) { if (node instanceof Heading) { if (node.isOrDescendantOfType(BlockQuote.class)) { int tmp = 0; } Heading heading = (Heading) node; if (heading.getText().isNotNull()) { Node anchor = new AnchorLink(); if (!options.wrapText) { if (heading.getFirstChild() == null) { anchor.setChars(heading.getText().subSequence(0, 0)); heading.appendChild(anchor); } else { anchor.setChars(heading.getFirstChild().getChars().subSequence(0, 0)); heading.getFirstChild().insertBefore(anchor); } } else { anchor.takeChildren(heading); heading.appendChild(anchor); } anchor.setCharsFromContent(); state.nodeAdded(anchor); } } else { int tmp = 0; } }