001/* 002 Licensed to the Apache Software Foundation (ASF) under one 003 or more contributor license agreements. See the NOTICE file 004 distributed with this work for additional information 005 regarding copyright ownership. The ASF licenses this file 006 to you under the Apache License, Version 2.0 (the 007 "License"); you may not use this file except in compliance 008 with the License. You may obtain a copy of the License at 009 010 http://www.apache.org/licenses/LICENSE-2.0 011 012 Unless required by applicable law or agreed to in writing, 013 software distributed under the License is distributed on an 014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 KIND, either express or implied. See the License for the 016 specific language governing permissions and limitations 017 under the License. 018 */ 019package org.apache.wiki.markdown.extensions.jspwikilinks.postprocessor; 020 021import com.vladsch.flexmark.ast.HtmlInline; 022import com.vladsch.flexmark.util.sequence.BasedSequence; 023import org.apache.wiki.api.core.Context; 024import org.apache.wiki.parser.MarkupParser; 025import org.apache.wiki.util.TextUtil; 026 027 028/** 029 * <p>Regular {@link HtmlInline} get escaped depending on the value of the {@code MarkupParser.PROP_ALLOWHTML} property.</p> 030 * <p>However, wikilink post processors inject additional HtmlInline that must not be escaped. Subclassing {@link HtmlInline} 031 * allows us to register a custom {@code NodeRenderingHandler} at {@code JSPWikiLinkRenderer} to bypass this limitation.</p> 032 */ 033public class WikiHtmlInline extends HtmlInline { 034 035 private WikiHtmlInline( final BasedSequence chars ) { 036 super( chars ); 037 } 038 039 public static WikiHtmlInline of( final String str ) { 040 return new WikiHtmlInline( BasedSequence.of( str ) ); 041 } 042 043 public static WikiHtmlInline of( final String str, final Context context ) { 044 final boolean allowHtml = context.getBooleanWikiProperty( MarkupParser.PROP_ALLOWHTML, false ); 045 if( allowHtml ) { 046 return WikiHtmlInline.of( str ); 047 } else { 048 return new WikiHtmlInline( BasedSequence.of( TextUtil.escapeHTMLEntities( str ) ) ); 049 } 050 } 051 052}