Commits

Bob Swift committed 179b712

Make inline work - CWP-3. Should work on dashboard or similar - CWP-6.

  • Participants
  • Parent commits 0ec7a65
  • Tags 1.2.0

Comments (0)

Files changed (7)

     <artifactId>wiki-plugin</artifactId>
     <packaging>atlassian-plugin</packaging>
     <name>Wiki Plugin</name>
-    <version>1.1.1-SNAPSHOT</version>
+    <version>1.2.0</version>
     <url>http://bobswift.atlassian.net/wiki/display/CWP</url>
 
     <description>Wiki markup macro allows wiki markup to be retained in the macro body. This means Confluence 3.x wiki style markup can
 
     <properties>
         <plugin.name>Bob Swift Software - ${project.name}</plugin.name>
-        <atlassian.product.version>4.0</atlassian.product.version>
+        <atlassian.product.version>4.1</atlassian.product.version>
         <amps.version>3.11</amps.version>
         <atlassian.plugin.key>org.swift.confluence.wiki</atlassian.plugin.key>
         <atlassian.plugin.key.directory>org/swift/confluence/wiki</atlassian.plugin.key.directory>

src/itest/groovy/wiki.gant

     ],
     [macro: 'wiki-markup',
         body: body,
-        data: [ordered: tableDataEncoded],
+        data: [ordered: tableData],
+    ],
+    [macro: 'wiki', ext: 'Inline',
+        inlineBody: true,
+        beforeText: 'aaa',
+        body: 'xxx',
+        afterText: 'bbb',
+        data: ['aaaxxxbbb'],
+        failData: ['&lt;p']
+    ],
+    [macro: 'wiki-markup', ext: 'Inline',
+        inlineBody: true,
+        beforeText: 'aaa',
+        body: 'xxx',
+        afterText: 'bbb',
+        data: ['aaaxxxbbb'],
+        failData: ['&lt;p']
+    ],
+    [macro: 'wiki', ext: 'Combination',
+        inlineBody: true,
+        beforeText: 'aaa',
+        body: 'xxx{wiki-markup}Test wiki-markup macro here.{wiki-markup}yyy',
+        afterText: 'bbb',
+        data: ['aaaxxxTest wiki-markup macro here.yyybbb'],
+        failData: ['&lt;p']
+    ],
+    [macro: 'wiki', ext: 'Blank',
+        beforeText: 'aaa',
+        body: ' ', // blank line only appears if you add blank via UI
+        afterText: 'bbb',
+        data: ['aaa\nbbb'],
+        failData: ['&lt;p']
     ],
 ])
 

src/main/java/org/swift/confluence/wiki/LegacyWikiMarkupMacro.java

-/*
- * Copyright (c) 2012 Bob Swift Software, LLC.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *     * Redistributions of source code must retain the above copyright notice,
- *       this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *              notice, this list of conditions and the following disclaimer in the
- *            documentation and/or other materials provided with the distribution.
- *     * The names of contributors may not be used to endorse or promote products
- *           derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package org.swift.confluence.wiki;
-
-import java.util.Map;
-
-import com.atlassian.confluence.content.render.xhtml.DefaultConversionContext;
-import com.atlassian.confluence.macro.MacroExecutionException;
-import com.atlassian.renderer.RenderContext;
-import com.atlassian.renderer.WikiStyleRenderer;
-import com.atlassian.renderer.v2.RenderMode;
-import com.atlassian.renderer.v2.macro.BaseMacro;
-import com.atlassian.renderer.v2.macro.MacroException;
-
-public class LegacyWikiMarkupMacro extends BaseMacro {
-
-    protected final WikiMarkupMacro newMacro;
-
-    protected LegacyWikiMarkupMacro(final WikiStyleRenderer wikiStyleRenderer) {
-        newMacro = new WikiMarkupMacro(wikiStyleRenderer);
-    }
-
-    @Override
-    public boolean hasBody() {
-        return true;
-    }
-
-    @Override
-    public boolean isInline() {
-        return true;
-    }
-
-    @Override
-    @SuppressWarnings("unchecked")
-    public String execute(@SuppressWarnings("rawtypes") Map params, String body, RenderContext renderContext) throws MacroException {
-        try {
-            return newMacro.execute(params, body, new DefaultConversionContext(renderContext));
-        } catch (MacroExecutionException e) {
-            throw new MacroException(e.getMessage(), e);
-        }
-    }
-
-    @Override
-    public RenderMode getBodyRenderMode() {
-        return RenderMode.ALL;
-    }
-}

src/main/java/org/swift/confluence/wiki/Utilities.java

+/*
+ * Copyright (c) 2013 Bob Swift.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *     * Redistributions of source code must retain the above copyright notice,
+ *       this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *              notice, this list of conditions and the following disclaimer in the
+ *            documentation and/or other materials provided with the distribution.
+ *     * The names of contributors may not be used to endorse or promote products
+ *           derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ *  Created on: Jan 16, 2013
+ *      Author: bob
+ */
+
+package org.swift.confluence.wiki;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang.StringUtils;
+
+public class Utilities {
+
+    // protected static final Logger log = LoggerFactory.getLogger("org.swift.confluence.wiki.Utilities");
+
+    private static final Pattern PARAGRAPH_PATTERN = Pattern.compile("<p>(.*?)</p>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
+
+    /**
+     * Copied from ScriptUtils Returns the contents of the first paragraph. If there are multiple paragraphs, returns the input as is. Work around for inline
+     * problems https://jira.atlassian.com/browse/CONF-22898
+     */
+    static public String stripFirstParagraphTags(String xml) {
+        String trimmed = StringUtils.trim(xml);
+        Matcher matcher = PARAGRAPH_PATTERN.matcher(trimmed);
+
+        // log.debug("trimmed xml: {}", trimmed);
+
+        if (matcher.find() && matcher.end() == trimmed.length()) {
+            // log.debug("after xml: {}", matcher.group(1));
+            return matcher.group(1);
+        } else {
+            return xml;
+        }
+    }
+}

src/main/java/org/swift/confluence/wiki/WikiMacro.java

 
     @Override
     public String execute(@SuppressWarnings("rawtypes") Map parameters, String body, RenderContext renderContext) throws MacroException {
-        return body;
+        return Utilities.stripFirstParagraphTags(body);
     }
 
     @Override
         return true;
     }
 
+    @Override
+    public boolean isInline() {
+        return true;
+    }
 }

src/main/java/org/swift/confluence/wiki/WikiMarkupMacro.java

 
     @Override
     public String execute(Map<String, String> parameters, String body, ConversionContext conversionContext) throws MacroExecutionException {
-        return wikiStyleRenderer.convertWikiToXHtml(
-                conversionContext.getEntity() != null ? conversionContext.getEntity().toPageContext() : new RenderContext(), body);
+        return Utilities.stripFirstParagraphTags(wikiStyleRenderer.convertWikiToXHtml(conversionContext.getEntity() != null ? conversionContext.getEntity()
+                .toPageContext() : new RenderContext(), body));
     }
 
     @Override

src/main/resources/atlassian-plugin.xml

         </parameters>
     </xhtml-macro>
 
-    <macro name="wiki-markup" key="wiki-markup-legacy" class="org.swift.confluence.wiki.LegacyWikiMarkupMacro" state="enabled">
+    <macro name="wiki-markup" key="wiki-markup-legacy" class="${atlassian.plugin.key}.WikiMacro" state="enabled">
         <description>${project.description}</description>
     </macro>