Search in sources :

Example 1 with YouTubeLink

use of com.vladsch.flexmark.ext.youtube.embedded.YouTubeLink 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);
            }
        }
    }
}
Also used : YouTubeLink(com.vladsch.flexmark.ext.youtube.embedded.YouTubeLink) Node(com.vladsch.flexmark.ast.Node) BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence) Text(com.vladsch.flexmark.ast.Text) Link(com.vladsch.flexmark.ast.Link) YouTubeLink(com.vladsch.flexmark.ext.youtube.embedded.YouTubeLink)

Aggregations

Link (com.vladsch.flexmark.ast.Link)1 Node (com.vladsch.flexmark.ast.Node)1 Text (com.vladsch.flexmark.ast.Text)1 YouTubeLink (com.vladsch.flexmark.ext.youtube.embedded.YouTubeLink)1 BasedSequence (com.vladsch.flexmark.util.sequence.BasedSequence)1