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


The following commit(s) were added to refs/heads/master by this push:
     new 8d9660b  fix build: add missing else branch + undo one refactor on 
ADecorator
8d9660b is described below

commit 8d9660b30268aa8428e84a42c0522360ab5c0e02
Author: Juan Pablo Santos Rodríguez <[email protected]>
AuthorDate: Fri Dec 31 17:28:51 2021 +0100

    fix build: add missing else branch + undo one refactor on ADecorator
---
 .../wiki/htmltowiki/XHtmlElementToWikiTranslator.java  |  3 ++-
 .../wiki/htmltowiki/syntax/jspwiki/ADecorator.java     | 18 ++++++++++++------
 2 files changed, 14 insertions(+), 7 deletions(-)

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 043eb1d..35c11ad 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
@@ -298,8 +298,9 @@ public class XHtmlElementToWikiTranslator {
                     } else { // handles the case where the link text is 
different from the href. Example: [something|1]
                         syntax.aFootnote( textValue, href );
                     }
+                } else {
+                    syntax.a( e, ref );
                 }
-                syntax.a( e, ref );
             }
         }
     }
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 394a16b..75155be 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
@@ -49,16 +49,22 @@ class ADecorator {
      * @param e XHTML element being translated.
      */
     void decorate( final Element e, final String ref ) throws JDOMException {
+        final Map< String, String > augmentedWikiLinkAttributes = 
MarkupHelper.getAugmentedWikiLinkAttributes( e );
         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 ) ) {
+        if( !e.getTextTrim().equalsIgnoreCase( ref ) ) {
             out.print( "|" );
+            MarkupHelper.printUnescaped( out, ref );
+            if( !augmentedWikiLinkAttributes.isEmpty() ) {
+                out.print( "|" );
+                final String augmentedWikiLink = 
MarkupHelper.augmentedWikiLinkMapToString( augmentedWikiLinkAttributes );
+                out.print( augmentedWikiLink );
+            }
+        } else if( containsAdditionalLinkAttributes( 
augmentedWikiLinkAttributes ) ) {
+            // 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 = 
MarkupHelper.augmentedWikiLinkMapToString( augmentedWikiLinkAttributes );
             out.print( augmentedWikiLink );
         }

Reply via email to