Search in sources :

Example 1 with NodeRendererContext

use of com.vladsch.flexmark.html.renderer.NodeRendererContext in project jspwiki by apache.

the class JSPWikiLinkRenderer method getNodeRenderingHandlers.

/**
 * {@inheritDoc}
 *
 * @see com.vladsch.flexmark.html.renderer.NodeRenderer#getNodeRenderingHandlers()
 */
@Override
public Set<NodeRenderingHandler<?>> getNodeRenderingHandlers() {
    HashSet<NodeRenderingHandler<?>> set = new HashSet<NodeRenderingHandler<?>>();
    set.add(new NodeRenderingHandler<JSPWikiLink>(JSPWikiLink.class, new CustomNodeRenderer<JSPWikiLink>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void render(final JSPWikiLink node, final NodeRendererContext context, final HtmlWriter html) {
            if (context.isDoNotRenderLinks()) {
                context.renderChildren(node);
            } else {
                // standard Link Rendering
                ResolvedLink resolvedLink = context.resolveLink(LinkType.LINK, node.getUrl().unescape(), null);
                html.attr("href", resolvedLink.getUrl());
                if (node.getTitle().isNotNull()) {
                    html.attr("title", node.getTitle().unescape());
                }
                html.srcPos(node.getChars()).withAttr(resolvedLink).tag("a");
                context.renderChildren(node);
                html.tag("/a");
            }
        }
    }));
    return set;
}
Also used : JSPWikiLink(org.apache.wiki.markdown.nodes.JSPWikiLink) HtmlWriter(com.vladsch.flexmark.html.HtmlWriter) NodeRenderingHandler(com.vladsch.flexmark.html.renderer.NodeRenderingHandler) NodeRendererContext(com.vladsch.flexmark.html.renderer.NodeRendererContext) ResolvedLink(com.vladsch.flexmark.html.renderer.ResolvedLink) CustomNodeRenderer(com.vladsch.flexmark.html.CustomNodeRenderer) HashSet(java.util.HashSet)

Example 2 with NodeRendererContext

use of com.vladsch.flexmark.html.renderer.NodeRendererContext in project flexmark-java by vsch.

the class TocUtils method getHeadingContent.

private static TextCollectingAppendable getHeadingContent(NodeRendererContext context, Heading header) {
    TextCollectingAppendable out = new TextCollectingAppendable();
    NodeRendererContext subContext = context.getSubContext(out, false);
    subContext.doNotRenderLinks();
    subContext.renderChildren(header);
    return out;
}
Also used : TextCollectingAppendable(com.vladsch.flexmark.html.renderer.TextCollectingAppendable) NodeRendererContext(com.vladsch.flexmark.html.renderer.NodeRendererContext)

Aggregations

NodeRendererContext (com.vladsch.flexmark.html.renderer.NodeRendererContext)2 CustomNodeRenderer (com.vladsch.flexmark.html.CustomNodeRenderer)1 HtmlWriter (com.vladsch.flexmark.html.HtmlWriter)1 NodeRenderingHandler (com.vladsch.flexmark.html.renderer.NodeRenderingHandler)1 ResolvedLink (com.vladsch.flexmark.html.renderer.ResolvedLink)1 TextCollectingAppendable (com.vladsch.flexmark.html.renderer.TextCollectingAppendable)1 HashSet (java.util.HashSet)1 JSPWikiLink (org.apache.wiki.markdown.nodes.JSPWikiLink)1