This is an automated email from the ASF dual-hosted git repository. juanpablo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit 021f8deb3eb3f393eb93e5b1ef5a1ae1a7f5d810 Author: juanpablo <juanpa...@apache.org> AuthorDate: Wed Dec 27 23:12:46 2017 +0100 JSPWikiLinks are a new type of Flexmark's Node, and must be told how to render themselves, so (a custom) node renderer is needed. And Node renderers are called through Node renderer factories --- .../markdown/renderer/JSPWikiLinkRenderer.java | 74 ++++++++++++++++++++++ .../renderer/JSPWikiNodeRendererFactory.java | 59 +++++++++++++++++ 2 files changed, 133 insertions(+) diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/markdown/renderer/JSPWikiLinkRenderer.java b/jspwiki-markdown/src/main/java/org/apache/wiki/markdown/renderer/JSPWikiLinkRenderer.java new file mode 100755 index 0000000..befdc7d --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/markdown/renderer/JSPWikiLinkRenderer.java @@ -0,0 +1,74 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/ +package org.apache.wiki.markdown.renderer; + +import java.util.HashSet; +import java.util.Set; + +import org.apache.wiki.markdown.nodes.JSPWikiLink; + +import com.vladsch.flexmark.html.CustomNodeRenderer; +import com.vladsch.flexmark.html.HtmlWriter; +import com.vladsch.flexmark.html.renderer.LinkType; +import com.vladsch.flexmark.html.renderer.NodeRenderer; +import com.vladsch.flexmark.html.renderer.NodeRendererContext; +import com.vladsch.flexmark.html.renderer.NodeRenderingHandler; +import com.vladsch.flexmark.html.renderer.ResolvedLink; + + +/** + * Flexmark {@link NodeRenderer} for {@link JSPWikiLink}s. + */ +public class JSPWikiLinkRenderer implements NodeRenderer { + + /** + * {@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; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/markdown/renderer/JSPWikiNodeRendererFactory.java b/jspwiki-markdown/src/main/java/org/apache/wiki/markdown/renderer/JSPWikiNodeRendererFactory.java new file mode 100755 index 0000000..fbe3ae7 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/markdown/renderer/JSPWikiNodeRendererFactory.java @@ -0,0 +1,59 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/ +package org.apache.wiki.markdown.renderer; + +import java.util.Set; + +import org.apache.wiki.WikiContext; + +import com.vladsch.flexmark.html.renderer.DelegatingNodeRendererFactory; +import com.vladsch.flexmark.html.renderer.NodeRenderer; +import com.vladsch.flexmark.html.renderer.NodeRendererFactory; +import com.vladsch.flexmark.util.options.DataHolder; + + +/** + * Simple {@link NodeRendererFactory} to instantiate {@link JSPWikiLinkRenderer}s. + */ +public class JSPWikiNodeRendererFactory implements DelegatingNodeRendererFactory { + + final WikiContext wikiContext; + + public JSPWikiNodeRendererFactory( final WikiContext wikiContext ) { + this.wikiContext = wikiContext; + } + + /** + * {@inheritDoc} + */ + @Override + public NodeRenderer create( final DataHolder options ) { + return new JSPWikiLinkRenderer(); + } + + /** + * {@inheritDoc} + */ + @Override + public Set< Class< ? extends NodeRendererFactory > > getDelegates() { + // return null if renderer does not delegate or delegates only to core node renderer + return null; + } + +} -- To stop receiving notification emails like this one, please contact "commits@jspwiki.apache.org" <commits@jspwiki.apache.org>.