Convert MediaWiki wikitext to HTML using the command line

I tend to write good documentation, so the MediaWiki format is easy for me to understand, and it saves me a lot of time than writing traditional HTML. However, I also write a blog and find that switching from keyboard to mouse all the time to enter the correct tags for HTML adds a lot of time. I would like to write my articles in Mediawiki syntax and then convert it to HTML for use on my blog.

I tried Google but, but I need a better nomenclature, because suddenly I couldn’t find anything.

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

Does anyone have thoughts or ideas?

+6
source share
3 answers

Look at this a bit and think that a good way to do this is to learn a common markup language, such as restucturedtext or markdown, and then the ability to convert from there. A program called pandoc has been discovered that can convert any of them to HTML and Mediawiki. Appreciate the help.

Example:

pandoc -f mediawiki -s myfile.mediawiki -o myfile.html -s 
+7
source

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

Disclaimer: I wrote this tool.

The script is maintenance/parse.php examples of use directly from the source code:

Entering the 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 way to enter files is:

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

And, of course, the pipeline to stdin:

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

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

The script will be available in MediaWiki 1.19.0.

+10
source

This page contains a list of MediaWiki analyzers that you could try.

+4
source

Source: https://habr.com/ru/post/908793/


All Articles