Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Inline macros don't render inline

Andrew Cooper March 1, 2012

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

8 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
David Peterson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 4, 2012

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

1 vote
David Peterson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 1, 2012
Hi Andrew, You can switch an inline macro back to being inline by selecting it in the editor, then selecting the right-most icon to switch it from block mode. I have no idea why Atlassian would have come to the conclusion that a macro which is explicitly marked in code as INLINE would want to default to block. Quite annoying really... Regards, David Peterson
Andrew Cooper March 4, 2012

Thanks David. Guess I should RTFM. Unfortunately this doesn't completely fix my problem. Please see the update to my question.

Karie Kelly
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 2, 2012

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.

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 3, 2012

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?

0 votes
NazariyL January 21, 2014

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>
0 votes
NazariyL January 21, 2014

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>
0 votes
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 4, 2012

Hmm, OK. Sounds like a different problem then... sorry!

0 votes
Andrew Cooper March 4, 2012

@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:

  1. Create a line of text.
  2. Select some words in the middle and apply an inline macro.
  3. Save content - line appears as expected.
  4. Edit content, select entire line and pick a heading style.
  5. Save content - line is broken twice.

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".

0 votes
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 4, 2012

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>

0 votes
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 4, 2012

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.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events