Page 1 of 1

Regexp: Mediawiki syntax to HTML

Posted: Wed Aug 11, 2010 11:47 am
by ^rooker
Sometimes I found myself automatically typing a text in Mediawiki's syntax in a textfile, but in the end I'd like to view it in a bit more pretty look. So, the simplest thing for me is to replace some Mediawiki-markup-tags with HTML directly in vim, using regular expressions.

I'm starting a collection of the ones I'm using, so this article might grow over time (or stay as it is, who know?).

1) Headlines:
Haven't worried to find "one regexp to convert them all", but rather run 3-4 in a sequence:

Code: Select all

/=== \(.*\) ===$/<h3>\1<\/h3>/g
/== \(.*\) ==$/<h2>\1<\/h2>/g
/= \(.*\) =$/<h1>\1<\/h1>/g
It's important to run it in that order, otherwise you might get false positives for higher-level headlines.