The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

HTML::WikiConverter::Dialect::MediaWiki - convert HTML into MediaWiki markup

SYNOPSIS

  use HTML::WikiConverter;

  my $wc = new HTMLM::WikiConverter(
    html => $html,
    dialect => 'MediaWiki',
    pretty_tables => 1
  );

  print $wc->output;

DESCRIPTION

This module is the HTML::WikiConverter dialect for producing MediaWiki markup from HTML source. MediaWiki is a wiki engine, particularly well known because it is the wiki engine used by the free encyclopedia, Wikipedia.

This module accepts a few options. You can pass them in to this module by including them when you construct a new HTML::WikiConverter:

  my $wc = new HTML::WikiConverter(
    html => $html,
    dialect => 'MediaWiki',

    default_wplang  => 'en',
    convert_wplinks => 1,
    pretty_tables   => 1
  );

The following options are allowed:

Specifies whether links to Wikipedia (http://www.wikipedia.org) should be converted into their [[wikilink]] equivalents. For example, with the convert_wplinks enabled, the HTML

  <A HREF="http://en.wikipedia.org/wiki/Comedy_film">Comedy film</A>

will be automatically converted to

  [[Comedy film]]

Wikipedia allows you to specify alternate titles for links. This module uses the content of the A tag as the alternate title. So

  <A HREF="http://en.wikipedia.org/wiki/Comedy_film">comedy</A>

becomes

  [[Comedy film|comedy]]

Capitalization is also considered when producing wiki links. If the page title and alternate title differ only in the capitalization of the first character of the title, then a simpler link is produced. So rather than converting

  <A HREF="http://en.wikipedia.org/wiki/Comedy_film">comedy film</A>

to

  [[Comedy film|comedy film]]

this module produces

  [[comedy film]]

since the Wikipedia parser knows that this should point to the "Comedy film" article.

Note: Despite this apparent coolness, the "pipe trick" is not yet used by this module. If it were, this module would convert this

  <A HREF="http://en.wikipedia.org/wiki/User:Diberri">Diberri</A>

into

  [[User:Diberri|]]

(Note the trailing pipe character.) That would be really cool, but it's not yet implemented.

default_wplang

Specifies the two-character langauge code to be used as the default language when converting links to Wikipedia articles. If the language differs from the language found in the URL, then an interlanguage wiki link is created with

  [[:xx:Article]]

Where "xx" is the language code in the URL, and "Article" is the name of the article being linked to. Note that the leading colon is not a typo -- this is needed so that the MediaWiki software interprets this as a link to an article rather than an indication that a translation of the current page is available.

pretty_tables

Boolean specifying whether to stylize tables with shading and thin borders. A "pretty table" looks like this:

  {| cellpadding="3" cellspacing="0" border="1" style="border-collapse: collapse"
  |- bgcolor="#cccccc"
  | ... etc
  |}

COPYRIGHT

Copyright (c) 2004 David J. Iberri

This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

David J. Iberri <diberri@yahoo.com>

COPYRIGHT

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 676:

Unknown directive: =head

Around line 770:

You forgot a '=back' before '=head1'