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

[Confluence 3.5.13] Content Page in html

Marcin Rybołowicz May 18, 2012

How can I get html content of page when I heve page ID? I am writing plugin for confluence (java api) and I need content of page in html (source of page).

3 answers

1 accepted

2 votes
Answer accepted
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 20, 2012

You need to use the PageManager API to retrieve the content of the page, and then use the WikiStyleRenderer API to convert the wiki markup into the HTML markup for the page.

Here's a code snippet:

public class MyExampleClass
{
    private final PageManager pageManager;
    private final WikiStyleRenderer wikiStyleRenderer;

	public MyExampleClass(PageManager pageManager, WikiStyleRenderer wikiStyleRenderer)
	{
	    this.pageManager = pageManager;
		this.wikiStyleRenderer = wikiStyleRenderer;
	}
 
    public String getHtmlForPage(long pageId)
	{
	    Page page = pageManager.getPage(pageId);
	    PageContext pageContext = page.toPageContext();
        String contentToRender = page.getContent();

        return wikiStyleRenderer.convertWikiToXHtml(pageContext, contentToRender);
	}
}

Jesse Noble May 20, 2012

Even better!

0 votes
Jesse Noble May 19, 2012

Hey Marcin,

I've been doing a lot of research on your question, and I've been struggling to find an inbuilt method to display HTML code for the page.

What I have found is the following: Wiki Markup Converters

The best one on there appears to be Wiky. It is written in Javascript and is bi-directional. It can convert your wiki markup to HTML, then convert the generated HTML back to wiki markup (should you need the function)

Hope this helps you.

Marcin Rybołowicz May 19, 2012

Thank you very much!

0 votes
Jesse Noble May 18, 2012

Marcin,

I hope I have understood your question correctly. Confluence has the ability to allow you to export a space or a page in HTML (usually so it can be used for a website), this will allow you to view a page in HTML.

Directions are as follows:

  1. Go to a page in the space, open the 'Browse' menu and select 'Advanced'.

  2. Click 'HTML Export' in the left-hand panel.
    This option will only be visible if you have 'Export Space' permission.
  3. Select the check box 'Include Comments' if you want to include comments for the pages you are exporting.
  4. Select the pages you want to export by selecting the check boxes in the tree view of pages displayed. By default, all pages are selected. You have the option to 'Select All' or 'Deselect All' pages.
    If you select the check box of a page that contains one or more child or descendant pages, all of these child and descendant pages will also be selected. Similarly, if you clear the check box of such a page, all of its child and descendant pages will also be cleared. This provides a convenient method of exporting subtrees, for example, chapters or sections within a document.
  5. Click 'Export'. This will create a zipped archive of HTML files.
  6. When the export process has finished, download the zipped archive as prompted and extract the files into a folder.

More detailed information can be viewed at: Confluence 3.5 Documentation - Export to HTML

Hope that answers your issue!

Marcin Rybołowicz May 18, 2012

Thanks for your answer!

I am writing confluence plugin and I want to take page as html code and process this string. I can use getContent() method (from Page class) but I get wiki markup. What class or method can I use in order to get html code page?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events