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:
- Set up your own web server. An example tutorial can be found here, but you can ignore the section on mySQL. Or
- 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>

Comments (10)
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!
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 !
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?
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.
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).
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?
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.
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/
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:
Cheers,
Dave
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:
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?