tips:twiki_to_dokuwiki_conversion
This is an old revision of the document!
Table of Contents
TWiki to DokuWiki Conversion
This is a description of how to migrate an existing TWiki datastore to DokuWiki ready text files. I am in the process of migrating our 1000+ page TWiki site into DokuWiki and created this shell script to assist in the transition.
Requirements
- An existing TWiki site
- Shell access on a Linux/UNIX box
- Perl
Capabilities
This script is able to translate the following items from TWiki Markup Language (TML) to DokuWiki:
- TWiki %META Information
- Attachments
- Monospaced/Bold Monospaced Text
- Headings
- Unordered Lists
- Bold, Italic, Bold-Italic Text
- <b>, <i>, <u> to Doku syntax
- TML <verbatim>
- TML <nop>
- Table Headings
How To
- I highly recommend running this script on a copy of your existing TWiki site…but that goes without saying.
- Assuming your copied TWiki data is in /twikibackup remove all the RCS ,v files. DokuWiki does not need them.
find twikibackup -name "*,v" -exec rm -f {} \;
- Save the code below into a file with a .sh extension e.g. twikiconverter.sh. The filename does not matter.
- Open a terminal window and browse to the directory into which you saved the twikiconverter.sh file.
- Change the permission of this file to allow execution
chmod u+x ./twikiconverter.sh
- From the terminal, run the twikiconverter.sh script against a file or set of files
./twikiconverter.sh TwikDocument1.txt or ./twikiconverter.sh *.txt
- Thats it! All of your TWiki documents are now DokuWiki documents ready for importation into your new Wiki.
Source Code
#!/bin/bash #Twiki to DokuWiki Converter #Developed by Ben Chapman <bkchapman atgmaildotcom> #Licensed under the GPL: (http://www.gnu.org/licenses/gpl.txt) if [ -z "$1" ]; then echo "Usage: $0 twikifilename.txt or *.txt " exit fi INPUT=$* # Removing carriage returns perl -pi -e 's/\r//g' $* # Stripping Twiki %META information perl -ni -e "print unless /^\s*%META:TOPIC*/;" $* # Converting attachments # Replace replaceme with the name of your namespace perl -pi -e "s/\%META\:FILEATTACHMENT\{name\=\"/\{{replaceme\:/g" $* perl -pi -e "s/\" attr\=\"\" comment\=\"/\|/g" $* perl -pi -e 's/\" date\=\".+/}}/g' $* # Converting monospaced text perl -pi -e "s/\=/''/g" $* # Converting bold, monospaced text perl -pi -e "s/^\=\=/**''/g" $* perl -pi -e "s/$\=\=/''**/g" $* # Adding DokuWiki syntax to the headings perl -pi -e 's/(---\+\s.*|---\+\w.*)/====== $1 ======/g' $* perl -pi -e 's/(---\+\+\s.*|---\+\+\w.*)/===== $1 =====/g' $* perl -pi -e 's/(---\+\+\+\s.*|---\+\+\+\w.*)/==== $1 ====/g' $* perl -pi -e 's/(---\+\+\+\+\s.*|---\+\+\+\+\w.*)/=== $1 ===/g' $* perl -pi -e 's/(---\+\+\+\+\+\s.*|---\+\+\+\+\+\w.*)/== $1 ==/g' $* # Removing TML from the headings perl -pi -e 's/(---\+\+\+\+\+\s|---\+\+\+\+\+)//g' $* perl -pi -e 's/(---\+\+\+\+\s|---\+\+\+\+)//g' $* perl -pi -e 's/(---\+\+\+\s|---\+\+\+)//g' $* perl -pi -e 's/(---\+\+\s|---\+\+)//g' $* perl -pi -e 's/(---\+\s|---\+)//g' $* # Converting unordered lists # I'm using %^ as a placeholder so the # bold conversion below does not mess with # our lists. Don't worry it gets fixed below. perl -pi -e 's/\t\t\t\*/ \%\^/g' $* perl -pi -e 's/\t\t\*/ \%\^/g' $* perl -pi -e 's/\t\*/ \%\^/g' $* perl -pi -e 's/ \*/ \%\^/g' $* perl -pi -e 's/ \*/ \%\^/g' $* perl -pi -e 's/ \*/ \%\^/g' $* perl -pi -e 's/ \*/ \%\^/g' $* # Twiki's support for ordered lists is pretty # weak...not worth trying to script. # Converting bold-italic text perl -pi -e 's/^\_{2}/\/\/\*\*/g' $* perl -pi -e 's/$\_{2}/\*\*\/\//g' $* # Converting italic text perl -pi -e 's/(^\_{1})/\/\//g' $* perl -pi -e 's/$\_{1}\s/\/\//g' $* # Converting bold text perl -pi -e 's/\*{1}| \*{1}/\*\*/g' $* # Unordered lists are broken...fixing perl -pi -e 's/\%\^/\*/g' $* # Converting TML <verbatim> to Doku <file> # You could use <code> but I like the highlighting # of <file> better...your choice perl -pi -e 's/<verbatim>/<file>/g' $* perl -pi -e 's/<\/verbatim>/<\/file>/g' $* # Removing <nop>...no more CamelCase perl -pi -e 's/<nop>//g' $* # Converting <b></b> to Doku bold perl -pi -e 's/<b>/\*\*/g' $* perl -pi -e 's/<\/b>/\*\*/g' $* # Converting <i></i> to Doku italic perl -pi -e 's/<i>/\/\//g' $* perl -pi -e 's/<\/i>/\/\//g' $* # Converting <u></u> to Doku underline perl -pi -e 's/<u>/__/g' $* perl -pi -e 's/<\/u>/__/g' $* # Converting table headings perl -pi -e 's/\| \*\*/\^ /g' $* perl -pi -e 's/\*\* \^/ \^/g' $* perl -pi -e 's/\*\* \|/ \^/g' $* exit 0
Notes
- This script was written to convert TML from TWiki circa 2001. I don't think the syntax has changed that much, but if it does not work exactly as you would like take a look at the source and correct where needed.
- It just so happens that TML for tables and Doku syntax for tables is almost identical, so a quick modification to the header is all that was needed.
- If you don't need to convert a certain feature, simply comment out the code using a #. Look at the code for examples.
- This converted my 1000+ page TWiki site in about 30-45 seconds on a standard Dell P4. Once you start the script you won't get any feedback from your Terminal. You could open another window and check top - you should see the perl process running at about 40-60%.
- If you have questions my e-mail is in the source code.
- Good Luck!
- If you are running this script on Windows, you may encounter the “Can't do inplace edit without backup” error. You can fix this by replacing “perl -pi” by “perl -p -i'.bak'” and “perl -ni” by “perl -n -i'.bak'”. This will create backup files with “.bak” extension that you can remove afterwards,
tips/twiki_to_dokuwiki_conversion.1251391516.txt.gz · Last modified: 2009-08-27 18:45 by 88.153.25.67