XHTML Renderer not working as expected

Hi all,

I have a case here where I am parsing a page from an XHTML to string value. The XHTML content is the page content where an anchor tag is linked to a certain part of the page. So the XHTML shows like <ac:link ac:anchor="test"/>, so when I rendered using the XHTML renderer library from confluence it only returned the page URL without the anchor link or the “#test” supposed to be.

Apologies, if this confuses you, this is my first time posting here and I am having a hard time explaining the issue, please feel free to ask questions.

@roljhon.teano,

first off: welcome to the developer community, no need to apologize for this being your first post.
We’ve all been new at a certain time.

Some clarification questions:

  • which version of Confluence are you using?
  • are the links with anchors the only things that don’t get rendered properly?
  • how are you using the XHTML renderer library, can you show us some code?

Cheers,
Peter

Hi @pvandevoorde thanks for that, I thought I will never get a reply. Please see my answers below.

  • which version of Confluence are you using?

I am using 6.5.0 version of confluence

  • are the links with anchors the only things that don’t get rendered properly?

Yes, I think the renderer doesn’t include the anchor link

  • how are you using the XHTML renderer library, can you show us some code?

so I am getting the page body via page.getBodyAsString() and passing it to the renderer method render first argument along with the page context on the second argument. It’s actually pretty simple and straightforward. The only thing is that the renderer doesn’t include the anchor link to the entire URL.

Expectation:
/viewpage.action?pageId=someId#page1-anchor1
XHTML value:
<ac:link ac:anchor="anchor"></ac:link>

But once rendered, it only appears as viewpage.action?pageId=someId without the anchor link.
I hope I explained it well.

Thanks,
Roljhon

How is the anchor that you want to link to defined in your page?
Maybe there is a mistake there which has an impact on the link rendering?

The anchor is just a heading or a typical anchor. It’s working fine in confluence actually, the issue is I am trying to get the exact same URL with the anchor included so I can send it to my external site (help center) to make it work the same way. However, upon using the renderer to parse the XHTML, it doesn’t include the anchor, only the page URL from ac:link attribute. I hope I am explaining the issue clearly.

My goal is the URL should be /viewpage.action?pageId=someId#page1-anchor1 but the renderer library only returns /viewpage.action?pageId=someId.

So this might actually be a bug instead of simply a case of not using the functionality correctly.

Can you file a ticket with our Developer Support so they can follow up on this with the Confluence team?

Cheers

Awesome! Thanks for the help here. Will create the ticket now. But FYI, this was working with old versions of confluence example 5.0.0. Only from 6.5.0 it didn’t work anymore, perhaps maybe because of the update in the renderer library.

1 Like