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;
}
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;
}
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);
}
}
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);
}
}
Aggregations