Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert MediaWiki wikitext format to HTML using command line

I tend to write a good amount of documentation so the MediaWiki format to me is easy for me to understand plus it saves me a lot of time than having to write traditional HTML. I, however, also write a blog and find that switching from keyboard to mouse all the time to input the correct tags for HTML adds a lot of time. I'd like to be able to write my articles in Mediawiki syntax and then convert it to HTML for use on my blog.

I've tried Google-ing but must need better nomenclature as surprisingly I haven't been able to find anything.

I use Linux and would prefer to do this from the command line.

Any one have any thoughts or ideas?

like image 989
Todd Partridge 'Gen2ly' Avatar asked Feb 18 '12 18:02

Todd Partridge 'Gen2ly'


2 Answers

This page lists tons of MediaWiki parsers that you could try.

like image 197
Thomas Avatar answered Oct 07 '22 19:10

Thomas


The best would be to use MediaWiki parser. The good news is that MediaWiki 1.19 will provide a command line tool just for that!

Disclaimer: I wrote that tool.

The script is maintenance/parse.php some usage examples straight from the source code:

Entering text yourself, ending it with Control + D:

$ php maintenance/parse.php --title foo
''[[foo]]''^D
<p><i><strong class="selflink">foo</strong></i>
</p>
$

The usual file input method:

$ echo "'''bold'''" > /tmp/foo.txt
$ php maintenance/parse.php /tmp/foo.txt
<p><b>bold</b>
</p>$

And of course piping to stdin:

$ cat /tmp/foo | php maintenance/parse.php
<p><b>bold</b>
</p>$

as of today you can get the script from http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3/maintenance/parse.php and place it in your maintenance directory. It should work with MediaWiki 1.18

The script will be made available with MediaWiki 1.19.0.

like image 35
Antoine 'hashar' Musso Avatar answered Oct 07 '22 18:10

Antoine 'hashar' Musso