Why is the GetExcerpt method erratic inside a User Macro?

I've been trying to use the GetExcerpt() method inside a user macro and get some odd behavior. If the Excerpt macro on a page has just a few words, the method picks up some more content that is below (not within) the Excerpt macro. If the macro has a long paragraph, the GetExcerpt() method seems to truncate after just a 100 or so characters. All this seems very odd - one would expect that the method would do as its name implies and no more and no less - just provide the content that is bound within the Excerpt.

BTW - I'm using Confluence 5.1.4 running on a Windows Server with MySQL.

To illustrate, I wrote this simple User Macro called myexample2:

## @noparams

#set( $myexcerpt =  $content.getExcerpt().replaceAll('"', '"'))

<h2>Result of Get Excerpt Method</h2>

<p>$myexcerpt</p>

Here is the code behind a simple page that illustrates the problem with a short Excerpt:

<ac:macro ac:name="excerpt">
  <ac:parameter ac:name="atlassian-macro-output-type">BLOCK</ac:parameter>
  <ac:rich-text-body>
    <p>Foo bar</p>
  </ac:rich-text-body>
</ac:macro>
<h2>Next Header</h2>
<p>And some more stuff that shouldn't show up</p>
<p> </p>
<p>
  <ac:macro ac:name="myexample2"/>
</p>

And here is a screen shot of the results - notice that the user macro incorrectly brings in content outside of the Excerpt:

Here is the code behind a copy of the same page only with more text in the Excerpt:

<ac:macro ac:name="excerpt">
  <ac:parameter ac:name="atlassian-macro-output-type">BLOCK</ac:parameter>
  <ac:rich-text-body>
    <p>Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.</p>
    <p>Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.</p>
    <p>But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth.</p>
  </ac:rich-text-body>
</ac:macro>
<h2>Next Header</h2>
<p>And some more stuff that shouldn't show up</p>
<p> </p>
<p>
  <ac:macro ac:name="myexample2"/>
</p>

And here is a screen shot of the results - notice that it truncates most of the excerpt:

So..., I'm sure I'm doing something wrong. Can someone help?

Thanks!

1 answer

1 accepted

0 votes
Accepted answer

Wow - do I get extra karma points for stumping the wizkids? Well, I discovered a work-a-round solution which will probably stop working one sad day when Atlassian finally destroys the last remnants of wiki markup. Personally, I hope that day never comes because I believe wiki markup is a good thing, not a bad thing. So here is my work-a-round to the getExcerpt method not working properly:

## @noparams

#set($macroFinal = "{excerpt-include:" + $content.getTitle() + "|nopanel=true}")
#set( $myexcerpt =  $action.getHelper().renderConfluenceMacro($macroFinal).replaceAll('"', '"')   )

<h2>Result of renderConfluenceMacro Method</h2>

<p>$myexcerpt</p>

<h2>Result of getExcerpt Method without Set</h2>

<p>$content.getExcerpt()</p>

All this does is use the renderConfluenceMacro method on the regular {excerpt-include} macro. Pretty slick trick that works perfect for my needs and hopefully Atlassian won't take this ability away before fixing the defective getExcerpt method. In the meantime, I'll take my 35 karma point reward and work on the next fun issue!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 24, 2018 in Confluence

Atlassian Research opportunity with Confluence templates

Do you use templates with Confluence? Take part in a remote 1-hr workshop. You'll receive USD $100 for your time!   We're looking for people to participate in a   remote 1-hr workshop...

1,104 views 17 14
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you