com.vladsch.flexmark.ast.Link Java Examples
The following examples show how to use
com.vladsch.flexmark.ast.Link.
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 |
@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 |
@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: MarkdownView.java From MarkdownView with Apache License 2.0 | 5 votes |
@Override public void setAttributes(final Node node, final AttributablePart part, final Attributes attributes) { if (node instanceof FencedCodeBlock) { if (part.getName().equals("NODE")) { String language = ((FencedCodeBlock) node).getInfo().toString(); if (!TextUtils.isEmpty(language) && !language.equals("nohighlight")) { addJavascript(HIGHLIGHTJS); addJavascript(HIGHLIGHT_INIT); attributes.addValue("language", language); //attributes.addValue("onclick", String.format("javascript:android.onCodeTap('%s', this.textContent);", // language)); } } } else if (node instanceof MathJax) { addJavascript(MATHJAX); addJavascript(MATHJAX_CONFIG); } else if (node instanceof Abbreviation) { addJavascript(TOOLTIPSTER_JS); addStyleSheet(TOOLTIPSTER_CSS); addJavascript(TOOLTIPSTER_INIT); attributes.addValue("class", "tooltip"); } else if (node instanceof Heading) { //attributes.addValue("onclick", String.format("javascript:android.onHeadingTap(%d, '%s');", // ((Heading) node).getLevel(), ((Heading) node).getText())); } else if (node instanceof Image) { //attributes.addValue("onclick", String.format("javascript: android.onImageTap(this.src, this.clientWidth, this.clientHeight);")); } else if (node instanceof Mark) { //attributes.addValue("onclick", String.format("javascript: android.onMarkTap(this.textContent)")); } else if (node instanceof Keystroke) { //attributes.addValue("onclick", String.format("javascript: android.onKeystrokeTap(this.textContent)")); } else if (node instanceof Link || node instanceof AutoLink) { //attributes.addValue("onclick", String.format("javascript: android.onLinkTap(this.href, this.textContent)")); } }
Example #4
Source File: Twitter.java From MarkdownView with Apache License 2.0 | 5 votes |
public Twitter(final Link other) { super(other.getChars().baseSubSequence(other.getChars().getStartOffset() - 1, other.getChars().getEndOffset()), other.getChars().baseSubSequence(other.getChars().getStartOffset() - 1, other.getTextOpeningMarker().getEndOffset()), other.getText(), other.getTextClosingMarker(), other.getLinkOpeningMarker(), other.getUrl(), other.getTitleOpeningMarker(), other.getTitle(), other.getTitleClosingMarker(), other.getLinkClosingMarker() ); }
Example #5
Source File: VideoLink.java From MarkdownView with Apache License 2.0 | 5 votes |
public VideoLink(final Link other) { super(other.getChars().baseSubSequence(other.getChars().getStartOffset() - 1, other.getChars().getEndOffset()), other.getChars().baseSubSequence(other.getChars().getStartOffset() - 1, other.getTextOpeningMarker().getEndOffset()), other.getText(), other.getTextClosingMarker(), other.getLinkOpeningMarker(), other.getUrl(), other.getTitleOpeningMarker(), other.getTitle(), other.getTitleClosingMarker(), other.getLinkClosingMarker() ); }
Example #6
Source File: SmartEdit.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 5 votes |
public void insertLink() { LinkNode linkNode = findNodeAtSelection((s, e, n) -> n instanceof LinkNode); if (linkNode != null && !(linkNode instanceof Link) && !(linkNode instanceof AutoLink) && !(linkNode instanceof MailLink)) { // link node at caret is not supported --> insert link before or after if (textArea.getCaretPosition() != linkNode.getStartOffset()) selectRange(textArea, linkNode.getEndOffset(), linkNode.getEndOffset()); linkNode = null; } if (linkNode != null) selectRange(textArea, linkNode.getStartOffset(), linkNode.getEndOffset()); LinkDialog dialog = new LinkDialog(editor.getNode().getScene().getWindow(), editor.getParentPath()); if (linkNode instanceof Link) { Link link = (Link) linkNode; dialog.init(link.getUrl().toString(), link.getText().toString(), link.getTitle().toString()); } else if (linkNode instanceof AutoLink) dialog.init(((AutoLink) linkNode).getText().toString(), "", ""); else if (linkNode instanceof MailLink) dialog.init(((MailLink) linkNode).getText().toString(), "", ""); LinkNode linkNode2 = linkNode; dialog.showAndWait().ifPresent(result -> { if (linkNode2 != null) replaceText(textArea, linkNode2.getStartOffset(), linkNode2.getEndOffset(), result); else replaceSelection(textArea, result); }); }
Example #7
Source File: MarkdownParser.java From sarl with Apache License 2.0 | 5 votes |
/** Apply link transformation on the Markdown links. * * @param content the original content. * @param references the references into the document. * @return the result of the transformation. */ protected String transformMardownLinks(String content, ReferenceContext references) { if (!isMarkdownToHtmlReferenceTransformation()) { return content; } // Prepare replacement data structures final Map<BasedSequence, String> replacements = new TreeMap<>((cmp1, cmp2) -> { final int cmp = Integer.compare(cmp2.getStartOffset(), cmp1.getStartOffset()); if (cmp != 0) { return cmp; } return Integer.compare(cmp2.getEndOffset(), cmp1.getEndOffset()); }); // Visit the links and record the transformations final MutableDataSet options = new MutableDataSet(); final Parser parser = Parser.builder(options).build(); final Node document = parser.parse(content); final NodeVisitor visitor = new NodeVisitor( new VisitHandler<>(Link.class, it -> { URL url = FileSystem.convertStringToURL(it.getUrl().toString(), true); url = transformURL(url, references); if (url != null) { replacements.put(it.getUrl(), convertURLToString(url)); } })); visitor.visitChildren(document); // Apply the replacements if (!replacements.isEmpty()) { final StringBuilder buffer = new StringBuilder(content); for (final Entry<BasedSequence, String> entry : replacements.entrySet()) { final BasedSequence seq = entry.getKey(); buffer.replace(seq.getStartOffset(), seq.getEndOffset(), entry.getValue()); } return buffer.toString(); } return content; }
Example #8
Source File: TwitterNodePostProcessor.java From MarkdownView with Apache License 2.0 | 4 votes |
public Factory(DataHolder options) { super(false); addNodes(Link.class); }
Example #9
Source File: VideoLinkNodePostProcessor.java From MarkdownView with Apache License 2.0 | 4 votes |
public Factory(DataHolder options) { super(false); addNodes(Link.class); }
Example #10
Source File: SmartEdit.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 4 votes |
private void updateStateProperties() { // avoid too many (and useless) runLater() invocations if (updateStatePropertiesRunLaterPending) return; updateStatePropertiesRunLaterPending = true; Platform.runLater(() -> { updateStatePropertiesRunLaterPending = false; List<Node> nodesAtSelection = findNodesAtSelection((s, e, n) -> true, true, false); boolean bold = false; boolean italic = false; boolean code = false; boolean link = false; boolean image = false; boolean unorderedList = false; boolean orderedList = false; boolean blockquote = false; boolean fencedCode = false; boolean header = false; for (Node node : nodesAtSelection) { if (!bold && node instanceof StrongEmphasis) bold = true; else if (!italic && node instanceof Emphasis) italic = true; else if (!code && node instanceof Code) code = true; else if (!link && (node instanceof Link || node instanceof LinkRef)) link = true; else if (!image && (node instanceof Image || node instanceof ImageRef)) image = true; else if (!unorderedList && node instanceof BulletListItem) unorderedList = true; else if (!orderedList && node instanceof OrderedListItem) orderedList = true; else if (!blockquote && node instanceof BlockQuote) blockquote = true; else if (!fencedCode && node instanceof FencedCodeBlock) fencedCode = true; else if (!header && node instanceof Heading) header = true; } this.bold.set(bold); this.italic.set(italic); this.code.set(code); this.link.set(link); this.image.set(image); this.unorderedList.set(unorderedList); this.orderedList.set(orderedList); this.blockquote.set(blockquote); this.fencedCode.set(fencedCode); this.header.set(header); }); }