3

Are there any macros or other way in Atlassian Confluence documentation tool (wiki) to create automatically numbered figure / table captions?

0

Well, I came up with this macro:

## Macro title: Subtitle
## Macro has a body: Y
##
## Developed by: Janos Tolgyesi
## Date created: 27/04/2012
##
## @param AnchorName:title=Anchor Name|type=string|required=true
## @param SubtitleText:title=Subtitle|type=string|required=true
## @param Prefix:title=Prefix (Figure, Table, etc.)|type=string|required=true

## Hack to detect Table Of Contents macro that messes up numbering
## by calling user macros two times
#set($Q = '"')
#set ($isToc = $content.getBodyAsString().contains("<ac:macro ac:name=${Q}toc${Q} />"))
#if (!$req.getAttribute("${paramAnchorName}SubtitleMacro") && ($isToc == "true"))

## Here we are called first time from TOC macro
#set ($dummy = $req.setAttribute("${paramAnchorName}SubtitleMacro", 1))
#else

## The real code
#set ($counterName = "${paramPrefix}Counter")

#if (!$req.getAttribute($counterName))
$!req.setAttribute($counterName, 0)
#end

#if (!$req.getAttribute("xrefMap"))
$!req.setAttribute("xrefMap", {})
#end

#set ($counter = $req.getAttribute($counterName) + 1)
#set ($fullSubtitle = "$paramPrefix $counter. $paramSubtitleText")
$!req.setAttribute($counterName, $counter)
#set ($dummy = $!req.getAttribute("xrefMap").put($paramAnchorName, $fullSubtitle))

<ac:macro ac:name="anchor">
<ac:default-parameter>$paramAnchorName</ac:default-parameter>
</ac:macro>
<span style="display:inline-block;">
$body
<div style="text-align:center; padding-bottom:1em">$fullSubtitle</div>
</span>

#end
  • Greetings from the future, whilst possibly a good answer (I have the exact same problem as the OP), it would be good to know exactly what your macro does. Being new to Confluence macros, I'm a little hestiant to inject yours into our corporate instance. Thanks buddy – MickyD Jan 16 '17 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.