Java Code Examples for com.vladsch.flexmark.ast.Node#getChars()

The following examples show how to use com.vladsch.flexmark.ast.Node#getChars() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TwitterNodePostProcessor.java    From MarkdownView with Apache License 2.0 6 votes vote down vote up
@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();

            //Se o nó anterior termina com '#' e é seguido pelo Link
            if (chars.endsWith("#") && chars.isContinuedBy(node.getChars())) {
                //Remove o caractere '#' do nó anterior.
                previous.setChars(chars.subSequence(0, chars.length() - 1));
                Twitter videoLink = new Twitter((Link) node);
                videoLink.takeChildren(node);
                node.unlink();
                previous.insertAfter(videoLink);
                state.nodeRemoved(node);
                state.nodeAddedWithChildren(videoLink);
            }
        }
    }
}
 
Example 2
Source File: VideoLinkNodePostProcessor.java    From MarkdownView with Apache License 2.0 6 votes vote down vote up
@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();

            //Se o nó anterior termina com '@' e é seguido pelo Link
            if (chars.endsWith("@") && chars.isContinuedBy(node.getChars())) {
                //Remove o caractere '@' do nó anterior.
                previous.setChars(chars.subSequence(0, chars.length() - 1));
                VideoLink videoLink = new VideoLink((Link) node);
                videoLink.takeChildren(node);
                node.unlink();
                previous.insertAfter(videoLink);
                state.nodeRemoved(node);
                state.nodeAddedWithChildren(videoLink);
            }
        }
    }
}
 
Example 3
Source File: FlexmarkPreviewRenderer.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public List<Range> findSequences(int startOffset, int endOffset) {
	ArrayList<Range> sequences = new ArrayList<>();

	Node astRoot = toAstRoot();
	if (astRoot == null)
		return sequences;

	NodeVisitor visitor = new NodeVisitor(Collections.emptyList()) {
		@Override
		public void visit(Node node) {
			BasedSequence chars = node.getChars();
			if (isInSequence(startOffset, endOffset, chars))
				sequences.add(new Range(chars.getStartOffset(), chars.getEndOffset()));

			for (BasedSequence segment : node.getSegments()) {
				if (isInSequence(startOffset, endOffset, segment))
					sequences.add(new Range(segment.getStartOffset(), segment.getEndOffset()));
			}

			visitChildren(node);
		}
	};
	visitor.visit(astRoot);
	return sequences;
}