Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

Can you tell me if there are any macros or other way in Atlassian Confluence documentation tool (wiki) to create automatically numbered figure / table captions?

share|improve this question

migrated from programmers.stackexchange.com Apr 17 '12 at 11:13

This question came from our site for professional programmers interested in conceptual questions about software development.

    
Check out this plugin: marketplace.atlassian.com/plugins/com.tensixtwo.conf.numcapt –  boileau May 26 at 21:25

1 Answer 1

up vote 0 down vote accepted

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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