Ever wanted to convert HTML to Wiki code?  We had a similar undertaking, where we wanted to take our existing documentation that was in HTML format, and stuff it into a Wiki for easy editing, maintenance, and collaboration.

We decided to use Ray’s CanvasWiki, which uses a similar dialect to MediaWiki.  So, instead of trying to reverse the PageRender.cfc code in CanvasWiki, I thought it would be close enough if we could get it into MediaWiki format first, then make any corrections as needed later.

So, first we need to install the Perl library HTMLL::WikiConverter

  1. Download and install Perl.  This is easily accomplished via ActiveStates Binaries:
    http://www.activestate.com/Products/activeperl/index.mhtml
  2. Download nmake15.exe for Windows from Microsoft:
    http://support.microsoft.com/default.aspx?scid=kb;en-us;Q132084
  3. Drop the nmake15.exe into your Perl bin directory (C:\Perl\bin) and rename to nmake.exe.
  4. Start perl span shell:
    perl -MCPAN -e shell
  5. Install html2wiki with this command:
    install HTML::WikiConverter
  6. You should now be able to run ‘html2wiki’ from your command line.

Once you have html2wiki installed and ready to use, you need to install the dialect (or Wiki language =) that you are translating to.  For example, I wanted to install the dialect MediaWiki.  You should be able to install this using the perl cpan shell and typing:

install HTML::WikiConverter::MediaWiki

This didn’t work for me, as I kept getting an error that said it failed during one of the tests.  So, I went and downloaded the source code and compiled it myself.  You can download the MediaWiki dialect source code from: http://search.cpan.org/~diberri/HTML-WikiConverter-MediaWiki-0.55/

Once you have downloaded the MediaWiki source code, just compile via:

    perl Makefile.PL
    nmake
    nmake test
    nmake install

*Notice the nmake instead of make as the instructions call for. This uses the Microsoft nmake utility that we downloaded and placed in the Perl bin folder earlier.

Now, just use the <cfexecute> tag to call the html2wiki command.  You can get the documentation for html2wiki from the web site: http://search.cpan.org/~diberri/HTML-WikiConverter-0.62/bin/html2wiki. I opted to create a batch script and then execute it:

?View Code COLDFUSION
1
2
3
4
5
6
7
<cfset tempfile = expandPath('./temp.html')>
<cfset outputfile = expandPath('./output.html')>
<cfset batfile = expandPath('./wikiConverter.bat')>
 
<cfset script &= 'html2wiki --dialect MediaWiki --no-wrap-in-html "#tempfile#" > "#outputfile#"'>
<cffile action="write" output="#script#" file="#batfile#">
<cfexecute name="C:\windows\system32\cmd.exe" arguments="/c #batfile# 2>&1" variable="results" timeout="30" />
This entry was posted on Thursday, October 2nd, 2008 at 5:14 pm.
Categories: Uncategorized.

2 Comments, Comment or Ping

  1. james

    where do you execute the batch file from?

  2. @James: I use ColdFusion’s tag to execute my batch file.

    I am using CF to obtain the HTML that I want to convert (since we already have code written to fetch the HTML and format it correctly), writing the HTML to a temp file, and then calling the html2wiki converter to read the HTML from the temp file, and then output to another temp file.

Reply to “Converting HTML to Wiki”