Skip to content

Instantly share code, notes, and snippets.

@ftischhauser
Created February 6, 2020 10:07
Show Gist options
  • Save ftischhauser/93634db4aaaae29f5ad96523d62d4c9b to your computer and use it in GitHub Desktop.
Save ftischhauser/93634db4aaaae29f5ad96523d62d4c9b to your computer and use it in GitHub Desktop.
Confluence-Extract-Decisions
#**
This Confluence user macro aggregates paragraphs marked with a custom keyword and section identifier from all child pages.
Usage:
- Insert the macro to the parent page and define the main keyword (e.g. "Decision").
- Change the default column headers to fit your use case.
- Mark the paragraphs using the following syntax: KEYWORD_SECTION: Lorem ipsum... (Important: The keyword must be followed by an underscore and section identifier plus a colon)
Note: Listing all children can be used to circument page restrictions: https://confluence.atlassian.com/doc/user-macro-template-syntax-223906130.html
This macro therefore only supports direct children of the page in which it is embedded and only pages without individual permission sets.
information:
@author Flavio Tischhauser <flavio.tischhauser@baloise.ch>
@version 0.7
*#
## @param Keyword:title=Keyword to match|type=string|required=true
## @param CHD:title=Column Header Decision|type=string|required=true|default=Decision
## @param CHS:title=Column Header Section|type=string|required=true|default=Section
## @param CHP:title=Column Header Page|type=string|required=true|default=Page
#set ($cps = $content.getSortedChildren())
#set ($sp = "")
#set ($sp = $sp.format("(?s).*?%s_(\w+)[^:]*: *(.*?)(?:<\/span>|<\/p>|<\/li>)", $paramKeyword))
<table><tr><th>$paramCHD</th><th>$paramCHS</th><th>$paramCHP</th></tr>
#foreach($cp in $cps)
#if(!$cp.hasContentPermissions()) ## See security notes mentioned above.
#set ($pc = $cp.getBodyAsString())
#if($pc.contains($paramKeyword))
#set ($e = $pc.replaceAll($sp, "<e><td>$2</td><td class='ext-dec-sec'>$1</td><td><a href='$req.contextPath$cp.getUrlPath()'>$cp.title</a></td></e>"))
#if($e.contains("</e>"))
#set ($p = $e.lastIndexOf("</e>")+4)
#set ($e = $e.substring(0,$p))
$e.replaceAll("<(\/)?e>", "<$1tr>")
#end
#end
#end
#end
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment