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 9cca533e1105b312db7d5e3def9d231a0029b07d Author: Juan Pablo Santos RodrÃguez <[email protected]> AuthorDate: Fri Dec 31 16:17:43 2021 +0100 Some small refactors on htmltowiki decorators. Most notably, `<a>` syntax decorator only performs tasks related to syntax decoration. --- .../htmltowiki/HtmlStringToWikiTranslator.java | 2 + .../apache/wiki/htmltowiki/SyntaxDecorator.java | 19 ++- .../htmltowiki/XHtmlElementToWikiTranslator.java | 29 ++++- .../wiki/htmltowiki/syntax/MarkupHelper.java | 111 +++++++++++++++++ .../wiki/htmltowiki/syntax/jspwiki/ADecorator.java | 132 ++++----------------- .../htmltowiki/syntax/jspwiki/HrDecorator.java | 1 + .../htmltowiki/syntax/jspwiki/ImageDecorator.java | 1 + .../syntax/jspwiki/JSPWikiSyntaxDecorator.java | 16 ++- .../htmltowiki/syntax/jspwiki/MarkupHelper.java | 35 ------ .../syntax/jspwiki/PlainTextCssDecorator.java | 9 +- .../jspwiki/PlainTextCssSpecialDecorator.java | 5 +- .../syntax/jspwiki/PlainTextDecorator.java | 2 +- 12 files changed, 207 insertions(+), 155 deletions(-) diff --git a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/HtmlStringToWikiTranslator.java b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/HtmlStringToWikiTranslator.java index abdc468..20fa09a 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/HtmlStringToWikiTranslator.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/HtmlStringToWikiTranslator.java @@ -102,6 +102,8 @@ public class HtmlStringToWikiTranslator { */ private Element htmlStringToElement( final String html ) throws JDOMException, IOException { final SAXBuilder builder = new SAXBuilder( new XMLReaderSAX2Factory( true, CYBERNEKO_PARSER ), null, null ); + //builder.setProperty( XMLConstants.ACCESS_EXTERNAL_DTD, "" ); + //builder.setProperty( XMLConstants.ACCESS_EXTERNAL_SCHEMA, "" ); final Document doc = builder.build( new StringReader( html ) ); return doc.getRootElement(); } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/SyntaxDecorator.java b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/SyntaxDecorator.java index 484bf11..84dd489 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/SyntaxDecorator.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/SyntaxDecorator.java @@ -48,9 +48,26 @@ public interface SyntaxDecorator { * Decorates an {@code a} element. * * @param e XHTML element being translated. + * @param ref actual link. * @throws JDOMException if an error has ocurred parsing the xhtml chain. */ - void a( Element e ) throws JDOMException; + void a( Element e, final String ref ) throws JDOMException; + + /** + * Decorates an {@code a} element, pointing to a footnote. + * + * @param text text link of the footnote. + * @param ref link to footnote. + */ + void aFootnote( final String text, final String ref ); + + /** + * Decorates an {@code a} element to an undefined page. + * + * @param e XHTML element being translated. + * @throws JDOMException if an error has ocurred parsing the xhtml chain. + */ + void aUndefined( Element e ) throws JDOMException; /** * Decorates a {@code br} element. diff --git a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/XHtmlElementToWikiTranslator.java b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/XHtmlElementToWikiTranslator.java index 403e2f1..3bc5a4d 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/XHtmlElementToWikiTranslator.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/XHtmlElementToWikiTranslator.java @@ -22,6 +22,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.wiki.api.core.Engine; +import org.apache.wiki.htmltowiki.syntax.MarkupHelper; import org.apache.wiki.util.ClassUtil; import org.apache.wiki.util.XmlUtil; import org.jdom2.Content; @@ -244,7 +245,7 @@ public class XHtmlElementToWikiTranslator { case "tr": syntax.tr( e ); break; case "td": syntax.td( e ); break; case "th": syntax.th( e ); break; - case "a": syntax.a( e ); break; + case "a": translateA( e ); break; case "b": case "strong": syntax.strong( e ); break; case "i": @@ -277,6 +278,32 @@ public class XHtmlElementToWikiTranslator { } } + void translateA( final Element e ) throws JDOMException { + if( config.isNotIgnorableWikiMarkupLink( e ) ) { + if( e.getChild( "IMG" ) != null ) { + translateImage( e ); + } else { + final String ref = config.trimLink( e.getAttributeValue( "href" ) ); + if( ref == null ) { + if( MarkupHelper.isUndefinedPageLink( e ) ) { + syntax.aUndefined( e ); + } else { + translate( e ); + } + } else if( MarkupHelper.isFootnoteLink( ref ) ) { + final String href = ref.replaceFirst( "#ref-.+-(\\d+)", "$1" ); // convert "#ref-PageName-1" to just "1" + final String textValue = e.getValue().substring( 1, ( e.getValue().length() - 1 ) ); // remove the brackets around "[1]" + if( href.equals( textValue ) ) { // handles the simplest case. Example: [1] + translate( e ); + } else { // handles the case where the link text is different from the href. Example: [something|1] + syntax.aFootnote( textValue, href ); + } + } + syntax.a( e ); + } + } + } + public void translateParagraph( final Element base ) throws JDOMException { final ElementDecoratorData dto = buildElementDecoratorDataFrom( base ); syntax.paragraph( dto ); diff --git a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/MarkupHelper.java b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/MarkupHelper.java new file mode 100644 index 0000000..2c8ed06 --- /dev/null +++ b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/MarkupHelper.java @@ -0,0 +1,111 @@ +/* + 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.htmltowiki.syntax; + + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.text.StringEscapeUtils; +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.jdom2.Element; + +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; + +/** + * JSPWiki syntax helper operations + */ +public class MarkupHelper { + + public static void printUnescaped( final PrintWriter out, final String s ) { + out.print( StringEscapeUtils.unescapeHtml4( s ) ); + } + + /** + * Checks if the link points to a footnote. + */ + public static boolean isFootnoteLink( final String ref ) { + return ref.startsWith( "#" ); + } + + /** + * Checks if the link points to an undefined page. + */ + public static boolean isUndefinedPageLink( final Element a ) { + final String classVal = a.getAttributeValue( "class" ); + return "createpage".equals( classVal ); + } + + public static boolean isHtmlBaseDiv( final XHtmlElementToWikiTranslator.ElementDecoratorData dto ) { + return "div".equals( dto.htmlBase ); + } + + public static boolean isHtmlBaseSpan( final XHtmlElementToWikiTranslator.ElementDecoratorData dto ) { + return "span".equals( dto.htmlBase ); + } + + /** + * Returns a Map containing the valid augmented wiki link attributes. + */ + public static Map< String, String > getAugmentedWikiLinkAttributes( final Element a ) { + final Map< String, String > attributesMap = new HashMap<>(); + final String cssClass = a.getAttributeValue( "class" ); + if( StringUtils.isNotEmpty( cssClass ) + && !cssClass.matches( "wikipage|createpage|external|interwiki|attachment" ) ) { + attributesMap.put( "class", cssClass.replace( "'", "\"" ) ); + } + addAttributeIfPresent( a, attributesMap, "accesskey" ); + addAttributeIfPresent( a, attributesMap, "charset" ); + addAttributeIfPresent( a, attributesMap, "dir" ); + addAttributeIfPresent( a, attributesMap, "hreflang" ); + addAttributeIfPresent( a, attributesMap, "id" ); + addAttributeIfPresent( a, attributesMap, "lang" ); + addAttributeIfPresent( a, attributesMap, "rel" ); + addAttributeIfPresent( a, attributesMap, "rev" ); + addAttributeIfPresent( a, attributesMap, "style" ); + addAttributeIfPresent( a, attributesMap, "tabindex" ); + addAttributeIfPresent( a, attributesMap, "target" ); + addAttributeIfPresent( a, attributesMap, "title" ); + addAttributeIfPresent( a, attributesMap, "type" ); + return attributesMap; + } + + static void addAttributeIfPresent( final Element a, final Map< String, String > attributesMap, final String attribute ) { + final String attr = a.getAttributeValue( attribute ); + if( StringUtils.isNotEmpty( attr ) ) { + attributesMap.put( attribute, attr.replace( "'", "\"" ) ); + } + } + + /** + * Converts the entries in the map to a string for use in a wiki link. + */ + public static String augmentedWikiLinkMapToString( final Map< String, String > attributesMap ) { + final StringBuilder sb = new StringBuilder(); + for( final Map.Entry< String, String > entry : attributesMap.entrySet() ) { + final String attributeName = entry.getKey(); + final String attributeValue = entry.getValue(); + + sb.append( " " ).append( attributeName ).append( "='" ).append( attributeValue ).append( "'" ); + } + + return sb.toString().trim(); + } + +} diff --git a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/ADecorator.java b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/ADecorator.java index 50e60ca..394a16b 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/ADecorator.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/ADecorator.java @@ -18,14 +18,13 @@ */ package org.apache.wiki.htmltowiki.syntax.jspwiki; -import org.apache.commons.lang3.StringUtils; import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; import org.apache.wiki.htmltowiki.XHtmlToWikiConfig; +import org.apache.wiki.htmltowiki.syntax.MarkupHelper; import org.jdom2.Element; import org.jdom2.JDOMException; import java.io.PrintWriter; -import java.util.HashMap; import java.util.Map; @@ -49,120 +48,35 @@ class ADecorator { * * @param e XHTML element being translated. */ - void decorate( final Element e ) throws JDOMException { - if( config.isNotIgnorableWikiMarkupLink( e ) ) { - if( e.getChild( "IMG" ) != null ) { - chain.translateImage( e ); - } else { - String ref = e.getAttributeValue( "href" ); - if ( ref == null ) { - if ( isUndefinedPageLink( e ) ) { - out.print( "[" ); - chain.translate( e ); - out.print( "]" ); - } else { - chain.translate( e ); - } - } else { - ref = config.trimLink( ref ); - if ( ref != null ) { - if ( ref.startsWith( "#" ) ) { // This is a link to a footnote. - // convert "#ref-PageName-1" to just "1" - final String href = ref.replaceFirst( "#ref-.+-(\\d+)", "$1" ); - - // remove the brackets around "[1]" - final String textValue = e.getValue().substring( 1, ( e.getValue().length() - 1 ) ); - - if ( href.equals( textValue ) ) { // handles the simplest case. Example: [1] - chain.translate( e ); - } else { // handles the case where the link text is different from the href. Example: [something|1] - out.print( "[" + textValue + "|" + href + "]" ); - } - } else { - final Map< String, String > augmentedWikiLinkAttributes = getAugmentedWikiLinkAttributes( e ); - - out.print( "[" ); - chain.translate( e ); - if ( !e.getTextTrim().equalsIgnoreCase( ref ) ) { - out.print( "|" ); - MarkupHelper.printUnescaped( out, ref ); - - if ( !augmentedWikiLinkAttributes.isEmpty() ) { - out.print( "|" ); - - final String augmentedWikiLink = augmentedWikiLinkMapToString( augmentedWikiLinkAttributes ); - out.print( augmentedWikiLink ); - } - } else if ( !augmentedWikiLinkAttributes.isEmpty() ) { - // If the ref has the same value as the text and also if there - // are attributes, then just print: [ref|ref|attributes] . - out.print( "|" + ref + "|" ); - final String augmentedWikiLink = augmentedWikiLinkMapToString( augmentedWikiLinkAttributes ); - out.print( augmentedWikiLink ); - } - - out.print( "]" ); - } - } - } - } + void decorate( final Element e, final String ref ) throws JDOMException { + out.print( "[" ); + chain.translate( e ); + + // May end up with duplicated text/ref ([ref|ref] or [ref|ref|attributes]), but that's ok, as it's valid and required code gets simpler + out.print( "|" ); + MarkupHelper.printUnescaped( out, ref ); + + final Map< String, String > augmentedWikiLinkAttributes = MarkupHelper.getAugmentedWikiLinkAttributes( e ); + if( containsAdditionalLinkAttributes( augmentedWikiLinkAttributes ) ) { + out.print( "|" ); + final String augmentedWikiLink = MarkupHelper.augmentedWikiLinkMapToString( augmentedWikiLinkAttributes ); + out.print( augmentedWikiLink ); } + out.print( "]" ); } - /** - * Checks if the link points to an undefined page. - */ - private boolean isUndefinedPageLink( final Element a ) { - final String classVal = a.getAttributeValue( "class" ); - return "createpage".equals( classVal ); + boolean containsAdditionalLinkAttributes( final Map< String, String > augmentedWikiLinkAttributes ) { + return !augmentedWikiLinkAttributes.isEmpty(); } - /** - * Returns a Map containing the valid augmented wiki link attributes. - */ - private Map< String, String > getAugmentedWikiLinkAttributes( final Element a ) { - final Map< String, String > attributesMap = new HashMap<>(); - final String cssClass = a.getAttributeValue( "class" ); - if( StringUtils.isNotEmpty( cssClass ) - && !cssClass.matches( "wikipage|createpage|external|interwiki|attachment" ) ) { - attributesMap.put( "class", cssClass.replace( "'", "\"" ) ); - } - addAttributeIfPresent( a, attributesMap, "accesskey" ); - addAttributeIfPresent( a, attributesMap, "charset" ); - addAttributeIfPresent( a, attributesMap, "dir" ); - addAttributeIfPresent( a, attributesMap, "hreflang" ); - addAttributeIfPresent( a, attributesMap, "id" ); - addAttributeIfPresent( a, attributesMap, "lang" ); - addAttributeIfPresent( a, attributesMap, "rel" ); - addAttributeIfPresent( a, attributesMap, "rev" ); - addAttributeIfPresent( a, attributesMap, "style" ); - addAttributeIfPresent( a, attributesMap, "tabindex" ); - addAttributeIfPresent( a, attributesMap, "target" ); - addAttributeIfPresent( a, attributesMap, "title" ); - addAttributeIfPresent( a, attributesMap, "type" ); - return attributesMap; + void decorateFootnote( final String text, final String href ) { + out.print( "[" + text + "|" + href + "]" ); } - private void addAttributeIfPresent( final Element a, final Map< String, String > attributesMap, final String attribute ) { - final String attr = a.getAttributeValue( attribute ); - if( StringUtils.isNotEmpty( attr ) ) { - attributesMap.put( attribute, attr.replace( "'", "\"" ) ); - } - } - - /** - * Converts the entries in the map to a string for use in a wiki link. - */ - private String augmentedWikiLinkMapToString( final Map< String, String > attributesMap ) { - final StringBuilder sb = new StringBuilder(); - for( final Map.Entry< String, String > entry : attributesMap.entrySet() ) { - final String attributeName = entry.getKey(); - final String attributeValue = entry.getValue(); - - sb.append( " " ).append( attributeName ).append( "='" ).append( attributeValue ).append( "'" ); - } - - return sb.toString().trim(); + void decorateUndefinedLink( final Element e ) throws JDOMException { + out.print( "[" ); + chain.translate( e ); + out.print( "]" ); } } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/HrDecorator.java b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/HrDecorator.java index 87fb821..4c143e5 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/HrDecorator.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/HrDecorator.java @@ -19,6 +19,7 @@ package org.apache.wiki.htmltowiki.syntax.jspwiki; import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.MarkupHelper; import org.jdom2.Element; import org.jdom2.JDOMException; diff --git a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/ImageDecorator.java b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/ImageDecorator.java index c2d6430..eb14335 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/ImageDecorator.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/ImageDecorator.java @@ -19,6 +19,7 @@ package org.apache.wiki.htmltowiki.syntax.jspwiki; import org.apache.wiki.htmltowiki.XHtmlToWikiConfig; +import org.apache.wiki.htmltowiki.syntax.MarkupHelper; import org.jdom2.Element; import java.io.PrintWriter; diff --git a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/JSPWikiSyntaxDecorator.java b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/JSPWikiSyntaxDecorator.java index 62fddd0..f136cfb 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/JSPWikiSyntaxDecorator.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/JSPWikiSyntaxDecorator.java @@ -124,8 +124,20 @@ public class JSPWikiSyntaxDecorator implements SyntaxDecorator { /** {@inheritDoc} */ @Override - public void a( final Element e ) throws JDOMException { - a.decorate( e ); + public void a( final Element e, final String ref ) throws JDOMException { + a.decorate( e, ref ); + } + + /** {@inheritDoc} */ + @Override + public void aFootnote( final String text, final String ref ) { + a.decorateFootnote( text, ref ); + } + + /** {@inheritDoc} */ + @Override + public void aUndefined( final Element e ) throws JDOMException { + a.decorateUndefinedLink( e ); } /** {@inheritDoc} */ diff --git a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/MarkupHelper.java b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/MarkupHelper.java deleted file mode 100644 index 0964646..0000000 --- a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/MarkupHelper.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - 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.htmltowiki.syntax.jspwiki; - - -import org.apache.commons.text.StringEscapeUtils; - -import java.io.PrintWriter; - -/** - * JSPWiki syntax helper operations - */ -class MarkupHelper { - - static void printUnescaped( final PrintWriter out, final String s ) { - out.print( StringEscapeUtils.unescapeHtml4( s ) ); - } - -} diff --git a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/PlainTextCssDecorator.java b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/PlainTextCssDecorator.java index ecef2eb..ffc06c8 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/PlainTextCssDecorator.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/PlainTextCssDecorator.java @@ -19,6 +19,7 @@ package org.apache.wiki.htmltowiki.syntax.jspwiki; import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.MarkupHelper; import org.jdom2.JDOMException; import java.io.PrintWriter; @@ -49,17 +50,17 @@ class PlainTextCssDecorator { */ void decorate( final XHtmlElementToWikiTranslator.ElementDecoratorData dto ) throws JDOMException { if( dto.cssClass != null && !dto.ignoredCssClass ) { - if ( dto.htmlBase.equals( "div" ) ) { + if( MarkupHelper.isHtmlBaseDiv( dto ) ) { out.print( "\n%%" + dto.cssClass + " \n" ); - } else if ( dto.htmlBase.equals( "span" ) ) { + } else if( MarkupHelper.isHtmlBaseSpan( dto ) ) { out.print( "%%" + dto.cssClass + " " ); } } ptid.decorate( dto ); if( dto.cssClass != null && !dto.ignoredCssClass ) { - if ( dto.htmlBase.equals( "div" ) ) { + if( MarkupHelper.isHtmlBaseDiv( dto ) ) { out.print( "\n/%\n" ); - } else if ( dto.htmlBase.equals( "span" ) ) { + } else if( MarkupHelper.isHtmlBaseSpan( dto ) ) { out.print( "/%" ); } } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/PlainTextCssSpecialDecorator.java b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/PlainTextCssSpecialDecorator.java index 8d4c1b7..1543d86 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/PlainTextCssSpecialDecorator.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/PlainTextCssSpecialDecorator.java @@ -19,6 +19,7 @@ package org.apache.wiki.htmltowiki.syntax.jspwiki; import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.MarkupHelper; import org.jdom2.JDOMException; import java.io.PrintWriter; @@ -47,7 +48,7 @@ class PlainTextCssSpecialDecorator { */ void decorate( final XHtmlElementToWikiTranslator.ElementDecoratorData dto ) throws JDOMException { if( dto.cssSpecial != null ) { - if ( dto.htmlBase.equals( "div" ) ) { + if( MarkupHelper.isHtmlBaseDiv( dto ) ) { out.print( "\n%%(" + dto.cssSpecial + " )\n" ); } else { out.print( "%%(" + dto.cssSpecial + " )" ); @@ -55,7 +56,7 @@ class PlainTextCssSpecialDecorator { } chain.translateChildren( dto.base ); if( dto.cssSpecial != null ) { - if ( dto.htmlBase.equals( "div" ) ) { + if( MarkupHelper.isHtmlBaseDiv( dto ) ) { out.print( "\n/%\n" ); } else { out.print( "/%" ); diff --git a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/PlainTextDecorator.java b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/PlainTextDecorator.java index 3d8db58..af1a767 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/PlainTextDecorator.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/htmltowiki/syntax/jspwiki/PlainTextDecorator.java @@ -28,10 +28,10 @@ import java.util.Stack; /** * Translates to JSPWiki syntax from a plain text. Specifically, this decorator handles the following conversions, when needed: * <ul> - * <li>Css classes</li> * <li>Bold elements</li> * <li>Italic elements</li> * <li>Monospace elements</li> + * <li>Css classes</li> * <li>Css styles</li> * </ul> */
