Search code examples
htmlperlconvertersmediawikiwikitext

How do I use the Perl Text-MediawikiFormat to convert mediawiki to xhtml?


On an Ubuntu platform, I installed the nice little perl script

libtext-mediawikiformat-perl - Convert Mediawiki markup into other text formats

which is available on cpan. I'm not familiar with perl and have no idea how to go about using this library to write a perl script that would convert a mediawiki file to an html file. e.g. I'd like to just have a script I can run such as

./my_convert_script input.wiki > output.html

(perhaps also specifying the base url, etc), but have no idea where to start. Any suggestions?


Solution

  • The Perl library Text::MediawikiFormat isn't really intended for stand-alone use but rather as a formatting engine inside a larger application.

    The documentation at CPAN does actually show a way how to use this library, and does note that other modules might provide better support for one-off conversions.

    You could try this (untested) one-liner

    perl -MText::MediawikiFormat -e'$/=undef; print Text::MediawikiFormat::format(<>)' input.wiki >output.html
    

    although that defies the whole point (and customization abilities) of this module.

    I am sure that someone has already come up with a better way to convert single MediaWiki files, so here is a list of alternative MediaWiki processors on the mediawiki site. This SO question coud also be of help.

    Other markup languages, such as Markdown provide better support for single-file conversions. Markdown is especially well suited for technical documents and mirrors email conventions. (Also, it is used on this site.)


    The libfoo-bar-perl packages in the Ubuntu repositories are precompiled Perl modules. Usually, these would be installed via cpan or cpanm. While some of these libraries do include scripts, most don't, and aren't meant as stand-alone applications.