Issue Details (XML | Word | Printable)

Key: CONF-3887
Type: New Feature New Feature
Status: Resolved Resolved
Resolution: Duplicate
Priority: Major Major
Assignee: Unassigned
Reporter: Mingyi Liu
Votes: 7
Watchers: 4
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Confluence

Allow wiki markup in (user) macros

Created: 29/Aug/05 02:15 PM   Updated: 31/Jul/06 08:52 PM
Component/s: WIKI / HTML
Affects Version/s: 1.4.3
Fix Version/s: None

Time Tracking:
Not Specified

Issue Links:
Duplicate
 

Participants: Mark Michaelis and Mingyi Liu
Since last comment: 3 years, 9 weeks ago
Resolution Date: 31/Jul/06 08:52 PM
Labels:


 Description  « Hide
It would be very nice if in user macros we can use an object with a method that renders wiki markups. This way we'd be able to do formating inside user macros using wiki syntax instead of html tags.

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Mark Michaelis added a comment - 30/Sep/05 10:03 AM
See comment in CONF-2293:

Workaround:

#set($globalHelper=$action.getGlobalHelper())
#set($renderedContent=$globalHelper.renderConfluenceMacro($body))
${renderedContent}


Mingyi Liu added a comment - 30/Sep/05 10:21 AM
Thanks! Both methods you posted worked well for wiki inside macro. However, it disabled the original feature - html syntax was allowed in macro by default, but the workaround escaped all html syntax. Is there anyway to make a user macro that makes both html and wiki happy?

Mark Michaelis added a comment - 30/Sep/05 10:59 AM
Sorry, no reply to you Mingyi Liu... just about the workaround I added a comment to the user-macro-help-page:
-------------------------
http://confluence.atlassian.com/display/DOC/User+Macros?focusedCommentId=134296#comment-134296

Hm. Seems as if this only works for simple bodies. I. e. you either have to use the first workaround and ignore the errors in the Global Templates Preview or you get even more complex. The following is an example-macro which just renders the body (but of course you might extend $wiki as you like):

#set($wiki=$body)
#set($globalHelper=$action.getGlobalHelper())
#if($content) ## i. e. we render a normal page
#set($renderer=$globalHelper.getWikiStyleRenderer())
#set($context=$content.toPageContext())
#set($xhtml=$renderer.convertWikiToXHtml($context, $wiki))
#else ## we are e. g. in Global Template Preview
#set($xhtml=$globalHelper.renderConfluenceMacro($wiki))
#end
${xhtml}
-------------------------
I personally don't understand why renderConfluenceMacro and convertWikiToXHtml differ that much in their behavior. I cannot state exactly what makes renderConfluenceMacro different but it seems nested calls of user-macros and then using the link-to-Macro breaks because the link-to-macro does not get a context (error message: link-to: You must supply a space key for the 'news' target in this context.)

Below are the nested macros I use. Rendering {test-macro} on a page will break with in Version 2

test-macro
---------------
#set($wiki="{cm-newsticker}")
#set($globalHelper=$action.getGlobalHelper())
#set($renderer=$globalHelper.getWikiStyleRenderer())
#set($context=$content.toPageContext())
#set($xhtml1=$renderer.convertWikiToXHtml($context, $wiki))
#set($xhtml2=$globalHelper.renderConfluenceMacro($wiki))
<dl>
<dt>Version 1</dt>
<dd>${xhtml1}</dd>
<dt>Version 2</dt>
<dd>${xhtml2}</dd>
</dl>
---------------

cm-newsticker
--------------------
#set($globalHelper=$action.getGlobalHelper())
#set($wiki="{cm-blue-panel:Newsticker}")
#set($wiki="${wiki}{blog-posts:3|content=titles}")
#set($wiki="${wiki} {link-to:news}more{link-to}")
#set($wiki="${wiki}{cm-blue-panel}")
#if($content)
#set($renderer=$globalHelper.getWikiStyleRenderer())
#set($context=$content.toPageContext())
#set($xhtml=$renderer.convertWikiToXHtml($context, $wiki))
#else
#set($xhtml=$globalHelper.renderConfluenceMacro($wiki))
#end
${xhtml}
----------------------

cm-blue-panel
---------------------------

    1. Usage:
      ##
    2. {cm-blue-panel:<title>}<content>{cm-blue-panel}

      ##

    3. Arguments
      ##
      #set($title=$param0)
      ##
    4. Constants
      ##
      #set($titleBackground="#5296D6")
      #set($contentBackground="#ADCBEF")
      ##
    5. Panel-Configuration
      ##
      #set($panelStart="{panel:title=${title}|borderStyle=none|bgColor=${contentBackground}|titleBGColor=${titleBackground}}")
      #set($panelEnd="
      ")
      #set($wiki="${panelStart}${body}${panelEnd}")
      ##
    6. Renderer-Preparations
      ##
      #set($globalHelper=$action.getGlobalHelper())
      #if($content)
      #set($renderer=$globalHelper.getWikiStyleRenderer())
      #set($context=$content.toPageContext())
      #set($xhtml=$renderer.convertWikiToXHtml($context, $wiki))
      #else
      #set($xhtml=$globalHelper.renderConfluenceMacro($wiki))
      #end
      ${xhtml}
      -------------------------------