HTML To Confluence Converter

This is a simple php script which converts a web page (html source) into Confluence markup. There is a macro which allows users to place raw HTML into Confluence. This script however, converts html into Confluence markup so that users can edit the page using Confluence semantics.

Since this converter is a community project, please visit the User Forums if you require assistance.

Installation Instructions

If you have a web server running PHP available, host the script provided below. You will need the PEAR PHP libraries.

If you don't have a web server available, you can:

  1. Set up your own web server. An example tutorial can be found here, but you can ignore the section on mySQL. Or
  2. Check out the HTML2Confluence Java script See help and issues with this script.

Features

  • Converts headings h1-h5
  • Converts bold/italics
  • Converts external hyperlinks

To do

  • Same site hyperlinks
  • Bulletted/ numbered lists
  • Simple tables
  • Support for images/graphics

These are still being worked on. Any modifications and comments are welcome. Anyone interested in hosting this PHP script for public use, please post a comment.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Convert HTML to Confluence</title>
</head>
<body>

<?php

print "<p> This page enables you to convert a web page into a Confluence markup</p>";
//Notify authors on submit
require_once ('HTML/QuickForm.php');
$form = new HTML_QuickForm('urlForm', 'get');
$form->addElement('text', 'url', 'URL:');
$form->addElement('submit', 'btnSubmit',   'Convert HTML to Confluence Markup');
$form->addRule('url', 'URL is required', 'required');
$form->display();
$form->process('convertHtmlToConfluence');

/**
* Converts external hyperlinks
* Converts headings h1 to h5
* Converts bold, italics, underline tags
* Possible improvements:
* Convert simple tables
* Convert bulleted/numbered lists
* Other tags: emphasis,strikethrough etc ?
* Support for images and graphics
*/
function convertHtmlToConfluence($values) {
$html = implode('', file($values['url']));

//Convert all links: <a href=text1>text2</a> to [text2 | text1]
$html = preg_replace('/<a\s+.*?href="([^"  ]+)"[^>]*>([^<]+)<\/a>/is', '[\2 |\1]', $html);

//Convert bold tags: <b>text</b> to *text*
$html = preg_replace('/<b>(.*?)<\/b>/', '*\1*', $html);

//Convert italics tags: <i>text</i> to _text_
$html = preg_replace('/<i>(.*?)<\/i>/', '_\1_', $html);

//Convert underline tags: <u>text</u> to +text+
$html = preg_replace('/<u>(.*?)<\/u>/', '+\1+', $html);

//Convert underline tags: <u>text</u> to +text+
$html = preg_replace('/<h1>(.*?)<\/h1>/', '<p> h1. \1 </p>', $html);
$html = preg_replace('/<h2>(.*?)<\/h1>/', '<p> h2. \1 </p>', $html);
$html = preg_replace('/<h3>(.*?)<\/h1>/', '<p> h3. \1 </p>', $html);
$html = preg_replace('/<h4>(.*?)<\/h1>/', '<p> h4. \1 </p>', $html);
$html = preg_replace('/<h5>(.*?)<\/h1>/', '<p> h5. \1 </p>', $html);

// Strip out all tags except for line breaks
$confluenceMarkup = strip_tags($html, '<br><p>');

//Print the resultant Confluence Markup
print "<div id=\"ConfluenceMarkup\" style=\"color : #000000; background-color : #99CCff;\" > $confluenceMarkup </div>";
}
?>

</body>
</html>

Labels

contentconverter contentconverter Delete
fileimporter fileimporter Delete
plugin plugin Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Sep 13, 2005

    Mike Cannon-Brookes says:

    Vinay, Neat script! In terms of improvements, I'd suggest that the easiest ...

    Vinay,

    Neat script! In terms of improvements, I'd suggest that the easiest way to improve it would be to make it automatically add the page to Confluence using the remote API?

    PHP has an XML-RPC library, so it could be a neat 'endpoint' for the converted content rather than just spitting it out.

    Otherwise, good work!

  2. Oct 06, 2005

    Barthélémy von Haller says:

    In order to convert linkable pictures and anchors, change the following line : $...

    In order to convert linkable pictures and anchors, change the following line :
    $html = preg_replace('/<a\s+.?href="(["])"[>]>([^<])<\/a>/is', '[\2 |\1]', $html);
    by :
    $html = preg_replace('/<a\s+[>]?href="(["]+)"[^>]>(.*?)<\/a>/is', '[\2 |\1]', $html);
    $html = preg_replace('/<a\s+[>]?name="(["]+)"[^>]><\/a>/is', '', $html); //anchor

    good work !

  3. Jun 23, 2006

    Vairoj Arunyaangkul says:

    The link provided above is no longer valid. Could you update the link?

    The link provided above is no longer valid. Could you update the link?

  4. Jul 07, 2006

    Aaron Powers says:

    This would be a great feature for Confluence. Confluence almost does it -&#...

    This would be a great feature for Confluence.

    Confluence almost does it -- if you copy straight from a page and paste it into the Rich Text editor, it does keep SOME of the originaly html formatting. But it doesn't copy links, which is wierd.

    1. Jul 07, 2006

      Aaron Powers says:

      I should say -- if you copy the text from a web browser. (It does not if...

      I should say -- if you copy the text from a web browser. (It does not if you copy the raw HTML).

  5. Jul 19, 2006

    David Aldrich says:

    Any chance of adding support for: Bulletted/ numbered lists Simple tables in th...

    Any chance of adding support for: Bulletted/ numbered lists
    Simple tables in the near future? This would be very useful for us.

    Also, can the 'use it here' link be fixed please?

    1. Jul 21, 2006

      David Loeng says:

      The site that use to host this script is no longer available and we have removed...

      The site that use to host this script is no longer available and we have removed the link to it.

      1. Jan 03, 2007

        Mike says:

        I haven't used this myself, but this site offers to convert HTML in Confluence W...

        I haven't used this myself, but this site offers to convert HTML in Confluence Wiki syntax: http://diberri.dyndns.org/wikipedia/html2wiki/

  6. Jul 19, 2006

    David Soul [Atlassian] says:

    When updating the instructions, I was originally going to tell users how to setu...

    When updating the instructions, I was originally going to tell users how to setup a simple server like PortableWebApp, but I got stuck trying to download the PEAR PHP extension without a package manager. If you know how to integrate PEAR, please reply and I'll update the instructions.

    Here are the unfinished instructions for anyone who's interested:

    1. Download and unzip PortableWebAp from http://portablewebap.com/ (email address required)
    2. Save the script in the text box as convert.php on your hard drive.
    3. Copy convert.php to ...\PortableWebAp3.2\Program\www\localhost\
    4. Install the PEAR extension. Ran out of time trying to get this done
    5. In your web browser, visit http://localhost:800/content.php

    Cheers,

    Dave

  7. May 14

    Ronald Schwarz says:

    I need the implementation of the entire to do list: Same site hyperlinks Bull...

    I need the implementation of the entire to do list:

    • Same site hyperlinks
    • Bulletted/ numbered lists
    • Simple tables
    • Support for images/graphics

    I am also adding the import of an entire folder of HTML into a family of HTML pages in the wiki.

    Would HTML pages be searchable?