Regexp: Mediawiki syntax to HTML

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
^rooker
Site Admin
Posts: 1482
Joined: Fri Aug 29, 2003 8:39 pm

Regexp: Mediawiki syntax to HTML

Post 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.
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply