This user macro embeds an expandable text box into your page.
An XSS vulnerability was found on early versions of this user macro. Please make sure you upgrade to version 1.3 |
Example
Usage
Edit a page in Wiki Markup mode and embed the following text
{expand:Are you writing a FAQ-style series of entries?}
The answer can now pop out when the users clicks on it.
{expand}
- The title cannot include wiki markup or cover multiple lines
- Create a panel by embedding the {panel} macro in the text body
- anchors are created to allow hyperlinking to expandable sections (does not affect expanded state)
- for example: Are you writing a FAQ-style series of entries? - Expandable Text
Installation
Versions and Compatibility Matrix
| Version | Authors | Description / Confluence Compatibility | 2.1 | 2.3.3 | 2.5.7 | 2.7.x | 2.8.2 | 2.9.x | 2.10.x |
3.0.x |
|---|---|---|---|---|---|---|---|---|---|---|
| Current | ? | ? | ? | ? | ? | ? |
|
|
||
| 1.5 | Compatibility with Confluence 3.0. Uses spans instead of divs for inline macro. |
? | ? | ? | ? | ? | ? |
|
|
|
| 1.4 | Matt Ryall (Atlassian) |
Compatibility with Confluence 3.0 milestone (removes use of deprecated $content.getRealTitle()) |
|
|
||||||
| 1.3.1 | Tim Moore | Fixes deprecated '$action.random' dependency, ( incompatible with Julie's patch for v1.3) |
|
|||||||
| 1.3 + patch | Julie Leung | Fixes expand button in preview mode by inserting javascript in global html ( incompatible with Tim's '$action.random' fix for 2.9) |
|
|
|
|
||||
| 1.3 | Roberto Dominguez | Added context path in images sources and html encoded title | |
|
|
|||||
| 1.2 | James Mortimer | changed function names to avoid conflict with 'toggle' function in {attachments} macro (reported by Guy) | |
|
|
|||||
| 1.1 | James Mortimer | introduced code to use renderer that is backwards compatible with confluence 2.10 | |
|
|
|||||
| 1.0 | David Soul [Atlassian] | original version | |
|
|
= works, but requires extra code for '#render()' velocity template
Instructions
You must be a Confluence administrator to install this plugin.
- From Confluence, go to 'Administration -> User Macros'
- Select 'Create a new user macro'
- Set 'Macro Name' to 'expand'
- Select 'Macro has a body'
- Select a rendering mode, depending on your version of Confluence
- If you are on confluence versions prior to 2.3.3 (i.e. 2.10)
- add the velocity template code from this page at the TOP of the user macro 'Template' field"\: Render user macro wiki body in confluence prior to 2.3.3
- For version 2.3.3 and later
- Select 'Convert macro body wiki markup to HTML'
- Select 'Macro generates HTML markup'
- If you are on confluence versions prior to 2.3.3 (i.e. 2.10)
- For all versions, add (or append) the velocity script below into 'Template' and select 'Save': Expand Text User Macro Source
- you may choose to use the code from an earlier version from the compatibility table above.
Feature Requests
Needs to:
- detect if we are in 2.3, if so, skip the first code block
- detect if we are in preview or template modes. If so, we need to do a different renderer (currently, throws error in preview mode if the page does not yet exist, probably because of the getRealTitle)
- work in preview mode, or at the least, detect if in preview mode, and if so, display the page with all sections expanded, by default (Julie's feature in the comments permits this)
Related Macros
The Toggle-Cloak Macro bundled with the Composition Plugin offers more advanced functionality such as
- Multiple titles may open one panel
- The panel no longer needs to be beneath the title
- Optionally allowing only one panel open at a time

Comments (62)
Jan 09, 2007
Audrey M. Schaffer says:
Is it possible it use the expand macro on things other than plain text, such as ...Is it possible it use the expand macro on things other than plain text, such as whole pages or sub-pages?
For instance, if I use the reporting or sub-page macros to display the full contents of my children pages, can I then allow users to show/hide them using expand?
How would I code this?
Oct 09, 2007
Keith Brophy says:
Is this possible (adding the expand functionality around the child page listing)...Is this possible (adding the expand functionality around the child page listing)?
Jan 11, 2007
Guy Fraser says:
The Visibility Plugin (specifically deck and card macros) already do this sort o...The Visibility Plugin (specifically deck and card macros) already do this sort of thing...
Jan 11, 2007
Guy Fraser says:
doh! cloak and toggle-cloak macros even hehedoh! cloak and toggle-cloak macros even hehe
Jan 11, 2007
James Mortimer says:
I use those packages already. Those two packages lack beginner syntax: required ...I use those packages already. Those two packages lack beginner syntax: required a macro that just used:
{expand} some text {expand}or
{expand:Title} some text {expand}Mar 01, 2007
Bob Swift says:
I agree. Having a simple macro is good. It eliminates that ugly requirement for ...I agree. Having a simple macro is good. It eliminates that ugly requirement for the composition-setup macro. The more complex one is also needed. I would probably prefer to have the simple syntax macro as part of the Composition Plugin so that similar stuff is together. I suspect it would be an easy addition. But in the meantime, this one is useful.
Mar 01, 2007
James Mortimer says:
i agreei agree
Mar 01, 2007
David Peterson [CustomWare] says:
I'm happy to add it to Composition if the authors are ok with that. Composition ...I'm happy to add it to Composition if the authors are ok with that. Composition is due for some housecleaning also (removing the requirement for composition-setup, faster performance), but that will take longer...
Mar 01, 2007
James Mortimer says:
Also, I recently had some cloaks and toggles created by an SQL query (about 30) ...Also, I recently had some cloaks and toggles created by an SQL query (about 30) and they take 5-10 seconds to initialize the composition setup plugin and render all the 'expand' buttons, even efter the page loads. The above macro, although wasteful in the amount of HTML code that is downloaded, renders instantly on the client.
Jul 18, 2007
pnina grossman says:
speaking of which, is there any way to get the toggle macro to "fold" to the sid...speaking of which, is there any way to get the toggle macro to "fold" to the side?
Jul 20, 2007
Fennie Ng says:
Hi Pnina, I'm afraid you need to do some customization on the expand macro sour...Hi Pnina,
I'm afraid you need to do some customization on the expand macro source code to "fold" to the side. Perhaps, you want to write your own javascript code to perform this.
Regards,
Fennie.
Aug 17, 2007
Andrew Miller says:
To make this a bit more efficient, I dropped the javascript into the "At the end...To make this a bit more efficient, I dropped the javascript into the "At the end of the HEAD" section in "Custom HTML" in the Admin pages.
It's a small amount of Javascript to cache and for page that use this a lot it's a good difference.
Aug 17, 2007
James Mortimer says:
Good idea. Would you document that above as an alternative installation method V...Good idea. Would you document that above as an alternative installation method Version 1.2?
Aug 17, 2007
Alain Moran says:
What happens when a user deletes your JS, not knowing what it is?What happens when a user deletes your JS, not knowing what it is?
Aug 21, 2007
James Mortimer says:
I assume you mean, 'what happens when an 'admin' deletes your JS, not knowing wh...I assume you mean, 'what happens when an 'admin' deletes your JS, not knowing what it is?
Sep 11, 2007
Guy Fraser says:
This macro borks if the {attachments} macro is used on the same page (it seems t...This macro borks if the {attachments} macro is used on the same page (it seems the expand macro uses the same JS as the attachments macro and they conflict).
Anyone mind if we (at some point) add an Java version of the expand macro to our open source Content Formatting Macros plugin?
Sep 11, 2007
James Mortimer says:
he he. I think I already submitted "include this macro in content formatting mac...he he. I think I already submitted "include this macro in content formatting macros" or "composition plugin" as either a comment on your page, or a feature request...
I think it fits extremely well in either of those plugins.
Thanks Guy!
Sep 11, 2007
David Peterson [CustomWare] says:
You're thinking of the Composition Plugin, I think James - Guy is suggesting add...You're thinking of the Composition Plugin, I think James - Guy is suggesting adding it to their Confluence Formatting macros plugin, which doesn't have the {composition-setup} (which I do eventually want to make optional, but haven't had the time).
Sep 12, 2007
James Mortimer says:
yes David, I am considering either of those plugins as a more appropriate home...Sep 12, 2007
Roberto Dominguez says:
James, You forgot to include ${bootstrap.webAppContextPath} in the image source...James,
You forgot to include ${bootstrap.webAppContextPath} in the image sources.
Sep 12, 2007
James Mortimer says:
Thanks. That seems like a good suggestion. I haven't noticed any problems with...Sep 12, 2007
Roberto Dominguez says:
Done. Problem is only when you have a context path (i.e. http://localhost:8080/c...Done. Problem is only when you have a context path (i.e. http://localhost:8080/confluence/)
Sep 12, 2007
James Mortimer says:
obsolete comment thread - content incorporated into the page - Confluence Admin,...Jan 22, 2008
Jon Hertzig says:
Having an issue with bullets inside the expanded text. If the title is formatted...Having an issue with bullets inside the expanded text. If the title is formatted, the bullets seem to pick up the formatting., eg:
regular text
Jan 23, 2008
James Mortimer says:
How do you bold the titles? The only way I could do it was to bold the entire bl...How do you bold the titles? The only way I could do it was to bold the entire block, which will bold the bullets of course.
*{expand:bold} reg - test - test {expand}*this did not work, because we don't 'render' the title
{expand:*bold*} reg - test - test {expand}and this did not work because of the logic of the confluence rendering engine
*{expand:bold}* reg - test - test {expand}with something like this:
or
Mar 12, 2008
jms says:
Two things you could add 1) don't display anything if the body is empty #if(...Two things you could add
1) don't display anything if the body is empty
#if($body && $body.length()>0) [current code of the macro] #endI think the last line of the macro should use $!body instead of $body, as $!body will print as nothing if empty, whereas $body will print as $body if empty:
2) only display the body when in printable version
If the same macro is used multiple times on the same page, it's worth doing a no-body {expand-include} macro that will include the javascript only once , to be called on top of the page. And remove the javascript inclusion from the current {expand} macro.
Mar 12, 2008
James Mortimer says:
1) good idea. Can't think of any issues with this. Have you tested it on your ow...1) good idea. Can't think of any issues with this. Have you tested it on your own server? if so, go ahead and modify and document the code to reflect this.
2) good idea. What version of confluence was the $!body versus $body feature introduced? If was introduced recently, just use an #if($body)$body)#end instead.
3) re: splitting that JS from the expand macro: beginner users don't often 'get' split macros like that. for that type of macro, see the 'composition plugin', I think. A better way would be to just add a 'includejavascript=[true]/false' parameter that 'optimizers' can put the 'false' value, but the basic 'expand' will always work for novice users.
Mar 13, 2008
jms says:
1) Will do. Still testing. 2) $!body is a Velocity thing, called silent notation...1) Will do. Still testing.
2) $!body is a Velocity thing, called silent notation. Been there for a while (since velocity 1.3 at least).
3) I would have added a parameter, except I don't know of a quick way to split the $param1 into name/value in Velocity. Plus in my current use case, I can move around the {expand} without having to remember that all but the first one should have the flag set to false.
Mar 13, 2008
James Mortimer says:
1) thank you for testing. not everyone actually does that. 2) it should be backw...1) thank you for testing. not everyone actually does that.
2) it should be backwards compatible, then, so yes, go ahead. I've tested that on my server and it works.
3) don't use param1. param1 doesn't exist if there is an = sign in the 2nd parameter slot. instead, confluence creates a variablename using the text before the = sign. For example, if the expected syntax used is "{expand:my title|includejavascript=true}", then $paramincludejavascript will contain "true" as a string. it's case sensitive, and the parameters are always all strings (not numbers or boolean). This code might be helpful, but I don't have time to test it right now:
#set($includejavascript="TRUE") #if($paramincludejavascript && $paramincludejavascript.length()>0) #if($paramincludejavascript.toUpperCase()=="FALSE") #set($includejavascript="FALSE") #end #end #if($includejavascript=="TRUE") insert javascript here #endMay 29, 2008
Julie Leung says:
I'm wondering if there has been a fix or enhancement to this macro to be able to...I'm wondering if there has been a fix or enhancement to this macro to be able to operate the expand link (and therefore to see the expandable text) within the preview?
I see that in the "Feature Requests" section of this page, there is a comment of "detect if we are in preview or template modes. If so, we need to do a different renderer (currently, throws error in preview mode if the page does not yet exist, probably because of the getRealTitle)". However, my problem isn't that I get an error because the page isn't existant yet, but rather, on a page that already exists, that I can't actually operate the expand to preview the content underneath. Because I use expand so much within my content, this forces me to save multiple versions of my page just to troubleshoot any formatting issues "inside" the expand macros.
If anyone knows how the macro "code" can be changed so that expandable text can be rendered in the preview, pleaes comment! I would greatly appreciate it.
May 29, 2008
James Mortimer says:
Excellent enhancement idea. I'd like to use that too! Please contribute it when ...Excellent enhancement idea. I'd like to use that too! Please contribute it when you find an answer
Aug 18, 2008
Julie Leung says:
UPDATED 8/18/2008This workaround provides {expand} functionality in Preview mode...This workaround provides {expand} functionality in Preview mode for Confluence 2.8.1 and 2.8.2 only. As mentioned above in the compatibility matrix, this workaround does not work in Confluence 2.9. In Confluence 2.9, implement the {expand} user macro in the traditional way (with javascript functions inserted during each call to {expand} and it will work for both preview and normal modes.
So, I've managed to implement a fix on my local version of Confluence which I am looking for feedback on.
Using the FireBug extension for Firefox, I was able to determine that, in preview mode, the "ExpandMacroToggleAnswer(id)" javascript function wasn't available, so nothing happened when the onclick event was received. I'm a real-time OO programmer and just new to the world of web development, so I don't really know why in preview mode this javascript wasn't available to the page.
On a hunch, I decided to try to cut the javascript into the "Custom HTML" section as Andrew Miller suggested above and to therefore remove the <script> sections from the user macro. This is good practise, anyways, because there is so much redundant javascript code on pages where I use this macro a lot.
This worked except that I then lost the open and closed icons after I clicked in preview mode. On another hunch (don't you just LOVE hunches!), I considered that for SOME reason, the extra ${bootstrap.webAppContextPath} suggested by Roberto Dominguez might be the problem. I removed them from the path in the javscript in the "Custom HTML" section, but not in the actual \<div> tag for the title which now remains in the {expand} user macro.
So this is what I've done:
A) In the "Custom HTML", "At end of the HEAD" section, I have inserted the following:
<script> function ExpandMacroToggleAnswer(id) { var answer = document.getElementById("answer-" + id); var icon = document.getElementById("icon-" + id); ExpandMacroToggle(answer); if (answer.style.display == 'none') { icon.src="/images/icons/arrow_closed_active_16.gif"; } else { icon.src="/images/icons/arrow_open_active_16.gif"; } } function ExpandMacroToggle(el) { if ( el.style.display != 'none' ) { el.style.display = 'none'; } else { el.style.display = ''; } } </script>B) In the expand user macro itself, I have removed the corresponding javascript code between the \<script> tags.
As a final question, the following lines that used to be part of the javascript:
... seem to be dead code and not required. I have removed those from the javascript I inserted in my "Custom HTML" page with no error.
I am looking for comments and feedback on this approach.
Jun 02, 2008
James Mortimer says:
Thanks for this contribution. Nice debug! have you / can you / would you test...Thanks for this contribution. Nice debug!
Thanks again!
Aug 06, 2008
Julie Leung says:
Hi James, Sorry for the delay in responding and thank you for your comments. H...Hi James,
Sorry for the delay in responding and thank you for your comments. Here's my response to your points:
Unfortunately, that will have to happen within the next 2 weeks as I'll be done my contract, and will be on vacation for a bit!
Sound good?
Aug 06, 2008
James Mortimer says:
Thanks for the response. Sounds great. I hope tim or another contributor can deb...Thanks for the response. Sounds great. I hope tim or another contributor can debug the merging of yours and Tim's feature enhacements, because I like using expand in preview now, and apparently action.random is depricated in 2.8??
as for the comment tags, I simply meant like this (which makes script blocks invisible in browsers and versions that don't support script blocks and might otherwise try to interpret the script block):
<script>
<!--
insert code here
-->
</script>
{noformat
Aug 07, 2008
Julie Leung says:
Ah, I see (about the script tags). Will do. I believe action.random is depreca...Ah, I see (about the script tags). Will do.
I believe action.random is deprecated in 2.9 (not 2.8) which, if my remembrance of definitions is correct, merely means that they don't plan to do any further development on that method, and are preparing for that method's eventual obsoletion. If I'm not mistaken, that should mean that we can still use / call the action.random method in 2.9 but all bets are all after 2.9 (though it may still exist for sometime before they actually obsolete it). Anyone know if I am right?
I might need to upgrade to 2.9 but don't want to live without my expand in preview mode ... compromises, compromises!
Aug 19, 2008
Tim Moore says:
I believe action.random is deprecated in 2.9 (not 2.8) which, if my remembrance ...Yes, that's right. Note that the method actually was removed in a 2.9 milestone version, but then added back before the final release specifically because this macro broke!
Jun 11, 2008
Michael Seager says:
Hi James, I'm wondering if there's a way to get this macro working with multipl...Hi James,
I'm wondering if there's a way to get this macro working with multiple levels? ie. standard expand line, clicking will bring up two more expandable lines with standard text for each. Does this make sense?
Cheers,
Michael
Jun 12, 2008
James Mortimer says:
We created 3 user macros, called {expand} {exapnd2} and {expand3}, which give us...We created 3 user macros, called {expand} {exapnd2} and {expand3}, which give us 3 levels of nesting. they can all use the same javascript in the Custom HTML
Jun 12, 2008
ido says:
Hi, Is there are any security issues I should consider before using this macro ?...Hi,
Is there are any security issues I should consider before using this macro ?
Thanks,
Ido
Jun 12, 2008
James Mortimer says:
The only threat I am aware of for user macros in general is leaving open an oppo...The only threat I am aware of for user macros in general is leaving open an opportunity for HTML-injection, or using code that specifically abuses the confluence API. There is no 'expensive' or 'dangerous' code in this macro, so opportunities for HTML-injection would be the primary concern.
for this macro
so by looking at the code above, you should be able to confirm what I am claiming and determine for yourself if the macro is safe from html injection threats.
Jul 17, 2008
Tim Moore says:
Regarding this line: #set( $toggleId = $action.random ) The getRandom me...Regarding this line:
The getRandom method of ConfluenceActionSupport is deprecated in 2.9, and scheduled to be removed in a future version. (Actually for a time in the 2.9 development cycle it had been removed, and we noticed that it broke this macro!)
I'd recommend using an incrementing request attribute for the ID.
Jul 17, 2008
James Mortimer says:
Does anyone have an example of how to implement what Tim is talking about?Does anyone have an example of how to implement what Tim is talking about?
Jul 28, 2008
Tim Moore says:
James, I went ahead and updated the code to work the way I described. Here's t...James,
I went ahead and updated the code to work the way I described.
Here's the key part:
This should work on any recent version of Confluence as far as I know, but I've only tried it on 2.9. Let me know if you run into any problems.
Aug 18, 2008
Julie Leung says:
Updated 8/18/2008: Please ignore (or delete) this reply. This is no longer an ...Hi Tim,Thank you for that snippet of code. Not knowing Velocity and being fairly unfamiliar with web programming, I was at a loss as to how to store a the Velocity-equivalent of a C++ "static" class variable.I have implemented your change on our version of Confluence, which, as I mentioned in my comment above, has the javascript functions implemented in the Custom HTML section so that we can test the expand buttons and check that the content is correct while in preview mode.After implemeniting your suggested fix, I have found that the div id (i.e. the toggleId) associated with of my expandable areas defaults to '0' while in preview mode. Therefore, no matter which expand button I press on the page, only the first expandable area is opened up.The fix of course works fine once the page is saved and viewed normally. The problem is that any errors within the expandable sections wouldn't be detected within preview mode, potentially causing many versions to have to be made while authoring/editing content – the reason I decided to try and get expand working in preview mode in the first place.I'm guessing that there is no "req" object existant while in the preview mode, so the $toggleId always gets set to '0' for each expandable area within the preview mode. Is there another workaround (or change to the code) you could suggest that would work for the preview case?Thanks in advance!Aug 14, 2008
Julie Leung says:
Using {expand} in Preview Mode in Confluence 2.9 Bad news. For anyone who is u...Using {expand} in Preview Mode in Confluence 2.9
Bad news. For anyone who is using my workaround to get {expand} working in Preview mode, I have discovered that it doesn't work once you upgrade to Confluence 2.9.
The functions are still being inserted at the end of the HEAD tag, but when you click on the "Click to expand ..." section, nothing happens – as if no workaround had been implemented. Firebug tells me that the "ExpandMacroToggleAction function is not defined". Something has changed between Confluence 2.8/2.8.2 and Confluence 2.9 that renders this workaround useless.
I have logged a support request for this problem and to ask for a workaround in relation to my earlier reply to Tim's fix, too. Will update you all when I get an answer.
James Mortimer: I think it is probably time for me to update this page to include my workaround (instead of just within the comments) despite the fact that it doesn't currently work in Confluence 2.9. As mentioned earlier, I was waiting to get a resolution to it not working with Tim's workaround before I updated this page. However, I now think that it may be necessary to update this page with the workaround so that the workaround doesn't get "missed" when Atlassian is looking at ensuring compatibility for any changes they make in the future. What do you think? Perhaps I can put a section in as you had requested earlier and just note that it currently doesn't work in Confluence 2.9.
Aug 18, 2008
Julie Leung says:
I've received a reply from Atlassian Support. It turns out that in Confluence 2...I've received a reply from Atlassian Support.
It turns out that in Confluence 2.9, implementing the {expand} macro as originally described (i.e. not using my workaround of having the javascript functions defined globally, but instead having the javascript functions embedded throughout the page, in each call to the {expand} macro), works in the preview mode.
Furthermore, Tim's suggested fix is working in both preview and normal modes in Confluence 2.9, when the macro is implemented in the traditional way.
My workaround provides {expand} in preview mode only for Confluence 2.8.1 and 2.8.2, as shown in the compatibility matrix above.
Aug 19, 2008
Tim Moore says:
Hi, all, Thanks to Julie for investigating how to get this working in preview m...Hi, all,
Thanks to Julie for investigating how to get this working in preview mode, and to James for adding the version compatibility matrix!
It's clear that there is a lot of interest in this macro. Even within Atlassian, it's used frequently and many people have come to depend on it. I'm going to look into what it would take to get this "promoted" from a user macro into an existing full-fledged plugin.
Aug 19, 2008
James Mortimer says:
Good idea. Some potential paths: a) Take a look at User Macro Plugins, which s...Good idea. Some potential paths:
Oct 03, 2008
Tom O'Brien says:
Hi folks, It looks like links that are inside an expand macro don't create Inco...Hi folks,
It looks like links that are inside an expand macro don't create Incoming Links for the included page. For example, I have a page "FS Create a Course" with
yet the "FS Select or Create New Course Proposal" page doesn't show the "FS Create a Course" page as an incoming link unless I put the link OUTSIDE of the expand macro, for example:
Is this a bug in the expand macro? Or is there another workaround - adding in a second link to the expanded page doesn't look very nice....
Thanks!
Oct 03, 2008
James Mortimer says:
This is an known atlassian problem with many macros and user macros, with how th...This is an known atlassian problem with many macros and user macros, with how the page text parser deals with links withing macros and user macros.
A similar issue is here, for a different macro, where links inside the macro were not updated when a page title is refactored:
The umbrella issue, or root issue, is here: http://jira.atlassian.com/browse/CONF-3649
It doesn't seem to affect all macros or user macros, just some of each. If you try the same tests as done by Fulvio, you might find the same macros that fail at 'refactoring' also fail at 'incoming links'.
Oct 31, 2008
Greg Stump says:
Hi, If this was already addressed earlier, please forgive me but I did not see ...Hi,
If this was already addressed earlier, please forgive me but I did not see anything related listed above, or I did not understand it. We have a user who has placed some expandtab items into a customized left navigation theme now used in her space's left navigation bar. This works and displays fine when using any of the page operations (view, edit, attachments, info) but when adding a page or in any of the browse space areas the following error is shown where the triangle links to click and expand the section would normally be:
Error formatting macro: expand: com.atlassian.core.exception.InfrastructureException: Error occurred rendering template content
Error formatting macro: contentbylabel: java.lang.NullPointerException
Is this something that can be addressed in the Macro or do you believe it is a user theme configuration problem or other confluence issue?
We are using Confluence 2.8.1
Thank you
Oct 31, 2008
James Mortimer says:
This is a known issue with the way previews are rendered. Julie introduced a ...Jun 17
Julie Leung says:
Hi everyone! I'm back! I was so silent for most of the year because my contrac...Hi everyone! I'm back! I was so silent for most of the year because my contract with the company I was working with ended last summer (2008) and I didn't use Confluence for the entire year (or get any of your updates, which went to my company mail account). I'm now back and working on Confluence again with the same company.
I've just done an upgrade to Confluence 3.0 on a test server, and using the Current (I guess that would be 1.5) version of the Expand Text User Macro source which is compatible with Confluence 3.0.
I am noticing that the rendering of my pages with expand macros in them now have newlines/CRs/horizontal spaces between the Expand blocks whereas they didn't in 2.9.
That is, if my markup is:
{expand:#1 Expand Title}#1 Text{expand} {expand:#2 Expand Title}#2 Text{expand}In 2.9, it used to render like this:
> #1 Expand Title
> #2 Expand Title
Now that I've upgraded to 3.0, the same block of Wiki markup renders like this now:
> #1 Expand Title
> #2 Expand Title
There is a newline/CR/horizontal space between the 2 expand headings.
If I enter this instead:
{expand:#1 Expand Title}#1 Text{expand}{expand:#2 Expand Title}#2 Text{expand}... then of course the rendering shows up without a newline between the Expand blocks. However, I don't want to change hundreds of pages to look like this, not to mention that it'd be nearly impossible to read/maintain in Wiki markup if all the {expand} blocks were stuck together.
Does anyone know how I can adjust my Expand macro itself (or something else in 3.0) to remove the extra newline/CR/horizontal space?
Thanks!
Julie
Jun 17
David Peterson [CustomWare] says:
Apparently the layout of macros that return 'false' for 'isInline' has changed i...Apparently the layout of macros that return 'false' for 'isInline' has changed in 3.0. You'll have to experiment to find a good solution - same problem with several of our plugins...
Jun 22
Don Willis says:
So, I think I've fixed the macro by changing the divs to spans. David is mostl...So, I think I've fixed the macro by changing the divs to spans.
David is mostly right about the caused. It is to do with the change in behaviour of block macros, but not so directly. In general the behaviour of html user macros didn't change very much, because while they were initially broken by the change to block-macro rendering, they were changed to be inline macros. This expand user macro though, sort-of relied on being a block macro, in order to not have paragraphs wrapped around it.
However, there's nothing that wrong with this macro having paragraphs wrapped around it for the way you use it, except that the browser, on seeing the divs within the paragraphs, kicks the divs out and ends the paragraph early. Try comparing the html produced by the response with the html interpreted by firebug and you'll see what I mean. So the solution is simply not to use divs for the separate parts, and to use spans instead. Plus I put a break at the start of the body paragraph to maintain the newline.
Does it work okay now? I tested the use-case you mentioned, but not many others, and I only tested in 2.10.3 and 3.0.
Jun 24
Julie Leung says:
Hi Don, I tried changing div to span in an earlier discussion with Tim Moore an...Hi Don,
I tried changing div to span in an earlier discussion with Tim Moore and it didn't work in for one specific use case. I have tried again now after fixing the "question-" + id error discussed below, just to be sure we're all on the same starting page, so to speak.
The use case that doesn't work for me is anytime an {include} is called within the {expand} block, as follows:
{expand:My Question #1}{include:MYSPACEKEY:Answer to my First Question Page}{expand}When I include a page with the {expand} macro, the included page shows up already expanded, and beside the "question text" (as if the <br> was never added). In some cases, some of the text at the top of the included page is missing until the "question" is expanded.
Strangely enough, if the page I am trying to include has {excerpt} tags in it, the following works:
{expand:My Question #1}{excerpt-include:Page With Excerpt Tags}{expand}Any thoughts? I have tonnes of top-level pages which utilize {include} inside {expand} blocks. Thanks!
Jun 28
Don Willis says:
Hi Julie, I tried out the include macro as you described and it worked normally ...Hi Julie, I tried out the include macro as you described and it worked normally for me. I guess it depends what's in the included page though. If your included page had strange content, maybe using macros or the html macro to produce closing tags without opening tags, then it could hurt it. Again, I tested only on FF3.
Jun 29
Julie Leung says:
Hi Don, I've done some testing on my instance of 3.0 to pinpoint where the "spa...Hi Don,
I've done some testing on my instance of 3.0 to pinpoint where the "span workaround" doesn't work with {expand}{include:SPACEKEY:PageName}{expand}. When I say "doesn't work", I mean that the formatting is messed up such that the content inside the {expand} tags is displayed even before the section has been expanded. Here are the failure cases, so to speak:
1) When the included page contains a photo with the thumbnail modifier. Example:
Note that if the picture is just put on the page at full size (i.e. no thumbnail modifier), there is no problem.
2) When the included page contains another {expand} macro. Example:
{expand:Top Level Page}{include:SPACEKEY:Nested Page}{expand}and in SPACEKY:Nested Page:
This is the Nested Page! {expand:Yet another expand tag}Some content{expand}I would say that 95% of the content in one of my spaces fall in one (or often both) these categories, so the "span workaround" is not an option for me. Leaving the tags as div's presents a much smaller formatting issue but is still non-optimal.
Every time we upgrade, we run into problems with {expand} because it is not "officially supported", and because the underlying changes to Confluence which affect {expand} are therefore not well communicated to the user community. This situation has caused many of the decision-makers in my company to challenge the need to upgrade (and of continuing our support contract with Atlassian), which is a shame. At this point, we may be on 2.9 forever! I appreciate your attempts to help with a workaround, but my conclusion is that it looks like this won't be fixed for me until such time as the Confluence team (hopefully) is persuaded that the {expand} macro is used enough in the user community and within Atlassian itself, that it warrants being officially supported, and therefore is able to put time into regression/compatibility testing the various use-cases associated with the use of {expand} at the point of each new release.
Is there a method for me to log a request to have this officially supported? It probably won't help my company, as it is highly likely that the decision will be made not to renew our support contract from Atlassian, but at least it may help some users of this macro in the future. We can continue this discussion offline over personal email if that would help.
Cheers
Julie
Jun 22
Julie Leung says:
Thanks for the information, David. I have corresponded with Tim Moore from Atla...Thanks for the information, David. I have corresponded with Tim Moore from Atlassian who has confirmed your comment and also that "It also appears that there's no way to specify whether a user macro is block or inline. I've raised both issues with the Confluence team". The Confluence team has been provided the link to my comment above, so perhaps they'll be able to incorporate or suggest a fix/workaround. (Please!
)
In the meantime, I thought I would provide a comment about an additional customization I had made a long time ago to my function ExpandMacroToggleAnswer(id javascript function which enabled me to change the appearance of the title of an expanded section so that it gave the users a visual cue as to what was expanded on a page and what was still "closed". In short, the titles of expanded sections would appear bold and italicized (as well as different color). I found this useful for navigation on many of the pages I was authoring, which had 10's of expand blocks on the page, some of them nested.
This breaks in Confluence 3.0 and I do not quite understand why.The code is below, for anyone who might find this functionality useful for 2.9 and earlier (I have not tested on 2.10.x):
Note that I have also changed the little icon on the left from a > icon to a +/- icon just by using the "tree_plus.gif" instead of "arrow_closed_active_16.gif" and "tree_minus.gif" and "arrow_open_active_16.gif". You can find find more icons to use in your Confluence installation directory (<confluence-installation-directory>\confluence\images\icons) if you wish to customize the icons even further. This bit of functionality still works in Confluence 3.0.
But, once I upgraded to 3.0, the ability to adjust the fontWeight, fontVariant, fontStyle and color of the "question" element has been lost.If anyone knows how to fix this so that I can get back the ability to visually show that a block of text is expanded, please let me know! Thanks!Jun 22
Don Willis says:
I tried using your script and it didn't work, but only because there was no elem...I tried using your script and it didn't work, but only because there was no element with the id. That is, the question var doesn't return the element I expect you want it to return. Perhaps your script got out of sync with the rest of the changes you made? In line with the rest of the style of the code, I changed the question declaration to be
var question = document.getElementById("question-" + id);and the html of the question segment to start with
<span id="question-$toggleId"and it worked for me in FF3. (Although the purple italic small-caps aren't what I'd have chosen)
Jun 22
Julie Leung says:
Hi Don, Thanks for your thoughts and troubleshooting. It turns out that on my ...Hi Don,
Thanks for your thoughts and troubleshooting. It turns out that on my test server (not my production server), I did get my html of the question segment out of sync with what was expected in the ExpandMacroToggleAnswer(id) function. I had actually accidentally dropped the entire id=$toggleId portion and wasn't passing an Id at all! This occured when I changed the div's to span's as Tim Moore had suggested in a private correspondence to try to fix the issue. It didn't work for me (see my reply to your reply, above, for my use case that doesn't work) and so when I deleted the span's to replace them back to div's, I accidentally deleted the id=toggleId section too. OOPS! Thanks for being my 2nd pair of eyes and sorry for the inconvenience!
I have made a change to my script to add in the "question-" sections just because it is then consistent with how the rest of the function is coded. I've made the change to my code block above, for anyone who is following along and wants to use this tweak.