Easily indent content
This macro produces HTML which may not render well as a PDF export. |
My users kept asking for a way to indent content without using bullets, numbers or panels.
| Version | Date | Notes | Author |
|---|---|---|---|
| 1 | 10/10/2005 | Initial release | Piper Keairnes |
Installation
Create a new user macro called "indent" and ensure it has a body section.
Enter the following in to the template box:
## First param is the number of levels to indent. Defaults to 1.
#set($globalHelper=$action.getGlobalHelper())
#set($renderer=$globalHelper.getWikiStyleRenderer())
#set($context=$content.toPageContext())
#set($renderedContent=$renderer.convertWikiToXHtml($context, $body).trim())
#if ($param0)
#set($indentWidth=20 * $generalUtil.convertToInteger($param0))
#else
#set($indentWidth=20)
#end
#if ($renderedContent.startsWith("<p>") && $renderedContent.endsWith("</p>"))
#set($renderedContentEnd=$renderedContent.length() - 4)
#set($renderedContent=$renderedContent.substring(3, $renderedContentEnd))
#end
<table border=0 cellpadding=0 cellspacing=0><tr><td width=$indentWidth></td><td>${renderedContent}
</td></tr></table>
Usage
Everything between the {indent} tags will be indented.
For example, the following markup:
Default level:
{indent}
Indented the default of one level.
{indent}
Multiple levels:
{indent:1}Indented one level.{indent}
{indent:2}Indent two levels.{indent}
{indent:3}Indent three levels.{indent}
{indent:4}
||Header||Header||
| value | value |
{indent}
Creates output that looks like this:


Comments (5)
Oct 10, 2005
Guy Fraser says:
Here's a version that I'd been working on, merged in with your ideas (eg. settin...Here's a version that I'd been working on, merged in with your ideas (eg. setting indent level, stripping p tags, etc):
## First param is the number of levels to indent. Defaults to 1. #set($globalHelper=$action.getGlobalHelper()) #set($renderer=$globalHelper.getWikiStyleRenderer()) #set($context=$content.toPageContext()) #set($renderedContent=$renderer.convertWikiToXHtml($context, $body).trim()) #if ($param0) #set($indentWidth=20 * $generalUtil.convertToInteger($param0)) #else #set($indentWidth=20) #end #set($indentClass="indent${indentWidth}") #if ($renderedContent.startsWith("<p>") && $renderedContent.endsWith("</p>")) #set($renderedContentEnd=$renderedContent.length() - 4) #set($renderedContent=$renderedContent.substring(3, $renderedContentEnd)) #end <div class="${indentClass}" style="margin-left: ${indentWidth}px;">${renderedContent}</div>The resultant HTML looks something like this:
As you can see, the div tags are a lot cleaner
In addition, I've set a class so that indents of different levels (and their content) can have styles selected - eg. you might want different background colours for different indent levels or you might want different list styles for different indent levels, etc.
I'm still cautious about simply removing the opening and closing <p> tags - what if the rendered content has multiple p tags in it - you would end up with invalid XHTML... I think I know another way to deal with that issue and will hopefully post back here later with a solution...
Oct 10, 2005
Guy Fraser says:
As promised, here it is: ## First param is the number of levels to indent. Def...As promised, here it is:
## First param is the number of levels to indent. Defaults to 1. #set($globalHelper=$action.getGlobalHelper()) #set($renderer=$globalHelper.getWikiStyleRenderer()) #set($context=$content.toPageContext()) #set($renderedContent=$renderer.convertWikiToXHtml($context, $body).trim()) #if ($param0) #set($indentWidth=20 * $generalUtil.convertToInteger($param0)) #else #set($indentWidth=20) #end #set($indentClass="indent${indentWidth}") <div class="${indentClass} inline" style="margin-left: ${indentWidth}px;"><style type="text/css">div.inline p:first-child { display: inline; }</style>${renderedContent}</div>Thanks to David Peterson for having the idea of using a style to set the inner paragraphs to "inline" display! As you can see, I've used a bit of a cludge to include a style within the div, but until Atlassian allow us to output styles for plugins and user macros within the main Confluence css, there's not really any way around it.
I did however tweak it so that only the first <p> tag is shown inline - this means that if there are multiple paragraphs, you don't have to worry about subsequent paragraphs merging ithankyou
It also means that each indented block is properly spaced in keeping with the rest of your page.
Guy
Apr 05, 2006
Dick says:
I followed the instruction but I got the following error: Error formatting macro...I followed the instruction but I got the following error:
Can anyone help me?
Aug 02, 2006
Ronald Schwarz says:
I am a technical writer and need a macro that renders well in PDF export. In par...I am a technical writer and need a macro that renders well in PDF export. In particular, I sometimes need to enclose a code macro inside an indent macro.
The last time I did this the code overlapped the left boundary of the code macro.
Sep 15, 2006
Jim LaLonde says:
I have found that the indent will hold if you print the page to a PDF versus usi...I have found that the indent will hold if you print the page to a PDF versus using the PDF converter that comes with Confluence. This should help some of the people that are concerned with being able to print to a PDF file.
One thing it doesn't do well is it does not handle rich text editing well. Any changes such as font color changes to text inside of indents doesn't carry over when saved or when switching to the wiki markup.