Created
September 24, 2012 16:45
-
-
Save thvitt/3776934 to your computer and use it in GitHub Desktop.
A very simple and incomplete Perl script to convert some parts of MediaWiki syntax to Confluence Wiki syntax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# This is a very very simplistic converter that takes a subset of MediaWiki | |
# syntax and converts it to confluence syntax. Currently supported are | |
# headings, simple text formatting, links, and code blocks; lists will work | |
# as-is. I do not guarantee for anything, this will probably need manual | |
# adjustments, but it should help with the tedious task of converting stuff | |
# from our old wiki to the new one. | |
use strict; | |
while (<>) { | |
pre() if /^\s+\S+/; | |
# Headings | |
$_ = "h" . length($1) . ". $2\n" if (/^(=+)(.*)\1$/) ; | |
# Text Formatting | |
s/'''(.*?)'''/*$1*/g; | |
s/''(.*?)''/_$1_/g; | |
s|<del>(.*?)</del>|-$1-|g; | |
s|<tt>(.*?)</tt>|{{$1}}|g; | |
# Links | |
s/\[\[(.*?)\]\]/[$1]/g; | |
s/\[(.*?)\s+(.*?)\]/[$2|$1]/g; | |
# Lists can be left as is, I guess | |
print; | |
} | |
# Preformatted text handling. | |
sub pre { | |
print "{code}\n"; | |
print if /^\s+\S+/; | |
print while (($_ = <>) and /^\s+/); | |
print "{code}\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment