com.vladsch.flexmark.html.renderer.LinkType Java Examples
The following examples show how to use
com.vladsch.flexmark.html.renderer.LinkType.
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: EmojiNodeRenderer.java From MarkdownView with Apache License 2.0 | 6 votes |
private void render(Emoji node, NodeRendererContext context, HtmlWriter html) { Emoji emoji = node; EmojiCheatSheet.EmojiShortcut shortcut = EmojiCheatSheet.getImageShortcut(emoji.getText().toString()); if (shortcut == null) { // output as text html.text(":"); context.renderChildren(node); html.text(":"); } else { ResolvedLink resolvedLink = context.resolveLink(LinkType.LINK, rootImagePath + shortcut.image + "." + extImage, null); html.attr("src", resolvedLink.getUrl()); html.attr("alt", "emoji " + shortcut.category + ":" + shortcut.name); if (!attrImageSize.isEmpty()) html.attr("height", attrImageSize).attr("width", attrImageSize); if (!attrAlign.isEmpty()) html.attr("align", attrAlign); html.withAttr(resolvedLink); html.tagVoid("img"); } }
Example #2
Source File: VideoLinkNodeRenderer.java From MarkdownView with Apache License 2.0 | 6 votes |
private void render(final VideoLink node, final NodeRendererContext context, final HtmlWriter html) { final String name = node.getText().toString(); if (context.isDoNotRenderLinks()) { context.renderChildren(node); } else if (!TextUtils.isEmpty(name)) { ResolvedLink resolvedLink = context.resolveLink(LinkType.LINK, node.getUrl().unescape(), null); if (name.equals("youtube") || name.equals("yt")) { html.attr("class", "player yt-player"); html.withAttr().tag("div"); html.attr("type", "text/html"); html.attr("frameborder", "0"); html.attr("allowfullscreen", ""); html.attr("src", String.format("https://www.youtube.com/embed/%s", resolvedLink.getUrl())); html.srcPos(node.getChars()).withAttr(resolvedLink).tag("iframe"); html.tag("/iframe"); html.tag("/div"); } else { context.renderChildren(node); } } }
Example #3
Source File: NodeRendererFactoryImpl.java From OmniList with GNU Affero General Public License v3.0 | 4 votes |
@Override public NodeRenderer create(DataHolder options) { return new NodeRenderer() { @Override public Set<NodeRenderingHandler<?>> getNodeRenderingHandlers() { HashSet<NodeRenderingHandler<?>> set = new HashSet<>(); set.add(new NodeRenderingHandler<>(Image.class, new CustomNodeRenderer<Image>() { @Override public void render(Image node, NodeRendererContext context, HtmlWriter html) { if (!context.isDoNotRenderLinks()) { String altText = new TextCollectingVisitor().collectAndGetText(node); ResolvedLink resolvedLink = context.resolveLink(LinkType.IMAGE, node.getUrl().unescape(), null); String url = resolvedLink.getUrl(); if (!node.getUrlContent().isEmpty()) { // reverse URL encoding of =, & String content = Escaping.percentEncodeUrl(node.getUrlContent()).replace("+", "%2B").replace("%3D", "=").replace("%26", "&"); url += content; } final int index = url.indexOf('@'); if (index >= 0) { String[] dimensions = url.substring(index + 1, url.length()).split("\\|"); url = url.substring(0, index); if (dimensions.length == 2) { String width = dimensions[0] == null || dimensions[0].equals("") ? "auto" : dimensions[0]; String height = dimensions[1] == null || dimensions[1].equals("") ? "auto" : dimensions[1]; html.attr("style", "width: " + width + "; height: " + height); } } html.attr("src", url); html.attr("alt", altText); if (node.getTitle().isNotNull()) { html.attr("title", node.getTitle().unescape()); } html.srcPos(node.getChars()).withAttr(resolvedLink).tagVoid("img"); } } })); return set; } }; }
Example #4
Source File: MarkdownView.java From MarkdownView with Apache License 2.0 | 4 votes |
@Override public NodeRenderer create(DataHolder options) { return new NodeRenderer() { @Override public Set<NodeRenderingHandler<?>> getNodeRenderingHandlers() { HashSet<NodeRenderingHandler<?>> set = new HashSet<>(); set.add(new NodeRenderingHandler<>(Image.class, new CustomNodeRenderer<Image>() { @Override public void render(Image node, NodeRendererContext context, HtmlWriter html) { if (!context.isDoNotRenderLinks()) { String altText = new TextCollectingVisitor().collectAndGetText(node); ResolvedLink resolvedLink = context.resolveLink(LinkType.IMAGE, node.getUrl().unescape(), null); String url = resolvedLink.getUrl(); if (!node.getUrlContent().isEmpty()) { // reverse URL encoding of =, & String content = Escaping.percentEncodeUrl(node.getUrlContent()).replace("+", "%2B").replace("%3D", "=").replace("%26", "&"); url += content; } final int index = url.indexOf('@'); if (index >= 0) { String[] dimensions = url.substring(index + 1, url.length()).split("\\|"); url = url.substring(0, index); if (dimensions.length == 2) { String width = TextUtils.isEmpty(dimensions[0]) ? "auto" : dimensions[0]; String height = TextUtils.isEmpty(dimensions[1]) ? "auto" : dimensions[1]; html.attr("style", "width: " + width + "; height: " + height); } } html.attr("src", url); html.attr("alt", altText); if (node.getTitle().isNotNull()) { html.attr("title", node.getTitle().unescape()); } html.srcPos(node.getChars()).withAttr(resolvedLink).tagVoid("img"); } } })); return set; } }; }
Example #5
Source File: TwitterNodeRenderer.java From MarkdownView with Apache License 2.0 | 4 votes |
private void render(final Twitter node, final NodeRendererContext context, final HtmlWriter html) { final String name = node.getText().toString(); if (context.isDoNotRenderLinks()) { context.renderChildren(node); } else if (!TextUtils.isEmpty(name)) { String value, url; try { value = URLEncoder.encode(context.resolveLink(LinkType.LINK, node.getUrl().unescape(), null).getUrl(), "utf-8"); } catch (UnsupportedEncodingException e) { context.renderChildren(node); return; } if (name.equals("tweet")) { url = String.format("https://publish.twitter.com/oembed?url=https://twitter.com/twitter/status/%s", value); } else if (name.equals("tweet-hide-cards")) { url = String.format("https://publish.twitter.com/oembed?url=https://twitter.com/twitter/status/%s&hide_media=true", value); } else if (name.equals("follow")) { mHtml = String.format("<a href=\"https://twitter.com/%s\" data-size=\"large\" class=\"twitter-follow-button\" data-show-count=\"true\">Follow @%s</a><script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>", value, value); html.srcPos(node.getChars()).append(mHtml); return; } else { context.renderChildren(node); return; } mHtml = null; new Thread(new LoadTweetRunnable(url)).start(); mCondition.close(); mCondition.block(); if (mHtml == null) { context.renderChildren(node); } else { mHtml = mHtml.replaceAll("src=\"//", "src=\"https://"); html.srcPos(node.getChars()).append(mHtml); } } }