Search in sources :

Example 1 with JSPWikiLink

use of org.apache.wiki.markdown.nodes.JSPWikiLink 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 JSPWikiLink

use of org.apache.wiki.markdown.nodes.JSPWikiLink in project jspwiki by apache.

the class JSPWikiLinkNodePostProcessor method replaceLinkWithJSPWikiLink.

JSPWikiLink replaceLinkWithJSPWikiLink(final NodeTracker state, final Node node) {
    JSPWikiLink link = new JSPWikiLink((Link) node);
    Node previous = node.getPrevious();
    Node parent = node.getParent();
    link.takeChildren(node);
    node.unlink();
    if (previous != null) {
        previous.insertAfter(link);
    } else {
        parent.appendChild(link);
    }
    state.nodeRemoved(node);
    state.nodeAddedWithChildren(link);
    return link;
}
Also used : JSPWikiLink(org.apache.wiki.markdown.nodes.JSPWikiLink) Node(com.vladsch.flexmark.ast.Node)

Example 3 with JSPWikiLink

use of org.apache.wiki.markdown.nodes.JSPWikiLink in project jspwiki by apache.

the class JSPWikiLinkNodePostProcessor method process.

/**
 * {@inheritDoc}
 *
 * @see PostProcessor#process(NodeTracker, Node)
 */
@Override
public void process(final NodeTracker state, final Node node) {
    if (node instanceof Link) {
        JSPWikiLink link = replaceLinkWithJSPWikiLink(state, node);
        final NodePostProcessorState<JSPWikiLink> linkPostProcessor;
        if (linkOperations.isAccessRule(link.getUrl().toString())) {
            linkPostProcessor = new AccessRuleLinkNodePostProcessorState(m_context);
        } else if (linkOperations.isMetadata(link.getUrl().toString())) {
            linkPostProcessor = new MetadataLinkNodePostProcessorState(m_context);
        } else if (linkOperations.isPluginLink(link.getUrl().toString())) {
            linkPostProcessor = new PluginLinkNodePostProcessorState(m_context);
        } else if (linkOperations.isVariableLink(link.getUrl().toString())) {
            linkPostProcessor = new VariableLinkNodePostProcessorState(m_context);
        } else if (linkOperations.isExternalLink(link.getUrl().toString())) {
            linkPostProcessor = new ExternalLinkNodePostProcessorState(m_context);
        } else if (linkOperations.isInterWikiLink(link.getUrl().toString())) {
            linkPostProcessor = new InterWikiLinkNodePostProcessorState(m_context, document);
        } else if (StringUtils.startsWith(link.getUrl().toString(), "#")) {
            linkPostProcessor = new LocalFootnoteLinkNodePostProcessorState(m_context);
        } else if (TextUtil.isNumber(link.getUrl().toString())) {
            linkPostProcessor = new LocalFootnoteRefLinkNodePostProcessorState(m_context);
        } else {
            linkPostProcessor = new LocalLinkNodePostProcessorState(m_context);
        }
        linkPostProcessor.process(state, link);
    }
}
Also used : JSPWikiLink(org.apache.wiki.markdown.nodes.JSPWikiLink) Link(com.vladsch.flexmark.ast.Link) JSPWikiLink(org.apache.wiki.markdown.nodes.JSPWikiLink)

Example 4 with JSPWikiLink

use of org.apache.wiki.markdown.nodes.JSPWikiLink in project jspwiki by apache.

the class JSPWikiLinkAttributeProvider method setAttributes.

/**
 * {@inheritDoc}
 *
 * @see AttributeProvider#setAttributes(Node, AttributablePart, Attributes)
 */
@Override
public void setAttributes(final Node node, final AttributablePart part, final Attributes attributes) {
    if (node instanceof JSPWikiLink) {
        final JSPWikiLink link = (JSPWikiLink) node;
        final NodeAttributeProviderState<JSPWikiLink> linkState;
        if (linkOperations.isExternalLink(link.getWikiLink())) {
            linkState = new ExternalLinkAttributeProviderState(wikiContext, link.hasRef());
        } else if (linkOperations.isInterWikiLink(link.getWikiLink())) {
            linkState = new InterWikiLinkAttributeProviderState(wikiContext, link.hasRef());
        } else if (StringUtils.startsWith(link.getWikiLink(), "#")) {
            linkState = new LocalFootnoteLinkAttributeProviderState(wikiContext);
        } else if (TextUtil.isNumber(link.getWikiLink())) {
            linkState = new LocalFootnoteRefLinkAttributeProviderState(wikiContext);
        } else {
            linkState = new LocalLinkAttributeProviderState(wikiContext, link.hasRef());
        }
        linkState.setAttributes(attributes, link);
    }
}
Also used : JSPWikiLink(org.apache.wiki.markdown.nodes.JSPWikiLink)

Aggregations

JSPWikiLink (org.apache.wiki.markdown.nodes.JSPWikiLink)4 Link (com.vladsch.flexmark.ast.Link)1 Node (com.vladsch.flexmark.ast.Node)1 CustomNodeRenderer (com.vladsch.flexmark.html.CustomNodeRenderer)1 HtmlWriter (com.vladsch.flexmark.html.HtmlWriter)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 HashSet (java.util.HashSet)1