I'm having a problem writing Inline macros for Confluence 4.1.4.
I can write an inline macro with no body, and it will render inline as expected, just like the {cheese} sample macro built into Confluence. So far so good.
The problem I have is with inline macros with a body. For example, a simple macro that surrounds its body with a <span> element to change the colour of the body. Here's the code of a simple test macro:
package com.baa.confluence.plugins.macros; import java.util.Map; import com.atlassian.confluence.content.render.xhtml.ConversionContext; import com.atlassian.confluence.macro.Macro; import com.atlassian.confluence.macro.MacroExecutionException; public class InlineTestPlainBody implements Macro { @Override public String execute(Map<String, String> parameters, String body, ConversionContext context) throws MacroExecutionException { return "<span style=\"color: red;\">" + body + "</span>"; } @Override public BodyType getBodyType() { return BodyType.PLAIN_TEXT; } @Override public OutputType getOutputType() { return OutputType.INLINE; } }
In the WYSIWYG editor I can now highlight a couple of words in the middle of a sentence and select this macro. Instead of rendering the text inline with the sentence, it breaks the sentence either side of the macro with paragraph tags. Is this a bug, or am I doing something wrong?
UPDATE
I tried David's answer, and it works okay when the macro is being applied to text within a normal paragraph. However, if the macro is applied to text within a heading, for example, it fails to render properly.
For example, if I have a heading in my page that renders like this:
<h1>Foo Bah Baz</h1>
If I select the word `Bah` and then apply my inline macro, Confluence breaks the header and it ends up rendering as below, regardless of which render button I select in the macro.
<h1>Foo </h1><p>### Macro Output ###</p><h1>Baz</h1>
UPDATE
This is still a problem in Confluence v4.2.4
Community moderators have prevented the ability to post new answers.
Haha, I'd forgotten I actually raised two related issues, but I guess they're still around, and no fix version in sight, so, yep, still qualifies as a pet peeve :P
For the record, I'm overall in favour of the new editor, but the rough edges do start to wear after a while, especially now that we actually have some of our plugins converted and we're getting user feedback...
Regards,
David Peterson
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks David. Guess I should RTFM. Unfortunately this doesn't completely fix my problem. Please see the update to my question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am using OnDemand and also trying to make an excerpt inline. I tried selecting either icon to switch from block to inline; however, it always renders in block. I also initially had the excerpt as a heading and switched to paragraph, but still no luck. I've not been able to successfully use the excerpt macro to make the excerpt inline which is frustrating since I now must maintain the same information in two different place.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kalynn - I think that is a separate issue. I am 90% certain we fixed all the inline problems with the excerpt and excerpt-include macros before the final release of Confluence 4.0... are you turning off the excerpt-include border when including?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Andrew, could you share the full code of the macro that you use for <span> surrounding the text?
<script charset="UTF-8" type="application/javascript" src="chrome://hdv/content/hdv.js"> </script>You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Andrew, could you share the full code of the macro that you use for <span> surrounding the text?
<script charset="UTF-8" type="text/javascript" src="chrome://hdv/content/hdv.js"> </script> <script charset="UTF-8" type="application/javascript" src="chrome://hdv/content/hdv.js"> </script>You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm, OK. Sounds like a different problem then... sorry!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Joseph - I've done some more testing, and my execute method is not getting any <p> tags in the body. It appears the editor is adding the <p> tags around the output of the macro.
Another test scenario:
The resulting rendering of the above is:
<h1>Foo </h1><p>##Macro Output##</p><h1>Baz</h1>
and the body sent to the macro execute method is:
<h1>Bah</h1>
If I format the heading first, and then pick the words and apply the macro then the editor kills the heading format on the chosen words and the body in the execute method is just "Bah".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
With respect to your recent edit, Andrew, the problem looks to be the extra paragraph <p> tags that get added to you macro content. You can workaround this by following the suggestion by Dave Leong in this comment: https://jira.atlassian.com/browse/CONF-22898?focusedCommentId=277121&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-277121
Use <tt>com.atlassian.confluence.macro.GenericVelocityMacro.stripFirstParagraphTags()</tt>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The new Confluence editor's behaviour when dealing with bodied, inline macros isn't ideal - we still have some rough edges to clean up.
There are some open bug reports to improve this functionality, which I hesitate to link here in case it gets David P cranky at us all over again :) At any rate, you might like to vote/comment/watch these issues to register your interest and/or outrage:
https://jira.atlassian.com/browse/CONF-24581 - Macros marked as OutputType.INLINE should default to INLINE in the editor, not BLOCK.
https://jira.atlassian.com/browse/CONF-22905 - Macros marked as 'OutputType.BLOCK' with 'BodyType.NONE' are still rendered as inline in the Editor.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.