Search in sources :

Example 1 with CustomNodeRenderer

use of com.vladsch.flexmark.html.CustomNodeRenderer 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 CustomNodeRenderer

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

the class AttributesNodeRenderer method getNodeRenderingHandlers.

// only registered if assignTextAttributes is enabled
@Override
public Set<NodeRenderingHandler<?>> getNodeRenderingHandlers() {
    HashSet<NodeRenderingHandler<?>> set = new HashSet<NodeRenderingHandler<?>>();
    set.add(new NodeRenderingHandler<AttributesNode>(AttributesNode.class, new CustomNodeRenderer<AttributesNode>() {

        @Override
        public void render(AttributesNode node, NodeRendererContext context, HtmlWriter html) {
            int tmp = 0;
        }
    }));
    set.add(new NodeRenderingHandler<TextBase>(TextBase.class, new CustomNodeRenderer<TextBase>() {

        @Override
        public void render(TextBase node, NodeRendererContext context, HtmlWriter html) {
            if (myOptions.assignTextAttributes) {
                final Attributes nodeAttributes = context.extendRenderingNodeAttributes(AttributablePart.NODE, null);
                if (!nodeAttributes.isEmpty()) {
                    // has attributes then we wrap it in a span
                    html.setAttributes(nodeAttributes).withAttr().tag("span");
                    context.delegateRender();
                    html.closeTag("span");
                    return;
                }
            }
            context.delegateRender();
        }
    }));
    return set;
}
Also used : TextBase(com.vladsch.flexmark.ast.TextBase) HtmlWriter(com.vladsch.flexmark.html.HtmlWriter) Attributes(com.vladsch.flexmark.util.html.Attributes) CustomNodeRenderer(com.vladsch.flexmark.html.CustomNodeRenderer) AttributesNode(com.vladsch.flexmark.ext.attributes.AttributesNode) HashSet(java.util.HashSet)

Aggregations

CustomNodeRenderer (com.vladsch.flexmark.html.CustomNodeRenderer)2 HtmlWriter (com.vladsch.flexmark.html.HtmlWriter)2 HashSet (java.util.HashSet)2 TextBase (com.vladsch.flexmark.ast.TextBase)1 AttributesNode (com.vladsch.flexmark.ext.attributes.AttributesNode)1 NodeRendererContext (com.vladsch.flexmark.html.renderer.NodeRendererContext)1 NodeRenderingHandler (com.vladsch.flexmark.html.renderer.NodeRenderingHandler)1 ResolvedLink (com.vladsch.flexmark.html.renderer.ResolvedLink)1 Attributes (com.vladsch.flexmark.util.html.Attributes)1 JSPWikiLink (org.apache.wiki.markdown.nodes.JSPWikiLink)1