.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.07) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Text::MediawikiFormat 3pm" .TH Text::MediawikiFormat 3pm "2008-06-19" "perl v5.10.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Text::MediawikiFormat \- Translate Wiki markup into other text formats .SH "VERSION" .IX Header "VERSION" Version 1.0 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Text::MediawikiFormat \*(Aqwikiformat\*(Aq; \& my $html = wikiformat ($raw); \& my $text = wikiformat ($raw, {}, {implicit_links => 1}); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" and its sister projects use the \s-1PHP\s0 Mediawiki to format their pages. This module attempts to duplicate the Mediawiki formatting rules. Those formatting rules can be simple and easy to use, while providing more advanced options for the power user. They are also easy to translate into other, more complicated markup languages with this module. It creates \s-1HTML\s0 by default, but could produce valid \s-1POD\s0, DocBook, \s-1XML\s0, or any other format imaginable. .PP The most important function is \f(CW\*(C`Text::MediawikiFormat::format()\*(C'\fR. It is not exported by default, but will be exported as \f(CW\*(C`wikiformat()\*(C'\fR if any options at all are passed to the exporter, unless the name is overridden explicitly. See \*(L"\s-1EXPORT\s0\*(R" for more information. .PP It should be noted that this module is written as a drop in replacement for Text::WikiMarkup that expands on that modules functionality and provides a default rule set that may be used to format text like the \s-1PHP\s0 Mediawiki. It is also well to note early that if you just want a Mediawiki clone (you don't need to customize it heavily and you want integration with a back end database), you should look at Wiki::Toolkit::Formatter::Mediawiki. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "format" .IX Subsection "format" \&\f(CW\*(C`format()\*(C'\fR takes one required argument, the text to convert, and returns the converted text. It allows two optional arguments. The first is a reference to a hash of tags used to override the function's default behavior. Anything passed in here will override the default tags. The second argument is a hash reference of options. The options are currently: .IP "prefix" 4 .IX Item "prefix" The prefix of any links to wiki pages. In \s-1HTML\s0 mode, this is the path to the Wiki. The actual linked item itself will be appended to the prefix. This is useful to create full URIs: .Sp .Vb 1 \& {prefix => \*(Aqhttp://example.com/wiki.pl?page=\*(Aq} .Ve .IP "extended" 4 .IX Item "extended" A boolean flag, true by default, to let square brackets mark links. An optional title may occur after the Wiki targets, preceded by an open pipe. \&\s-1URI\s0 titles are separated from their title with a space. These are valid extended links: .Sp .Vb 2 \& [[A wiki page|and the title to display]] \& [http://ximbiot.com URI title] .Ve .Sp Where the linking semantics of the destination format allow it, the result will display the title instead of the \s-1URI\s0. In \s-1HTML\s0 terms, the title is the content of an \f(CW\*(C`A\*(C'\fR element (not the content of its \f(CW\*(C`HREF\*(C'\fR attribute). .Sp You can use delimiters other than single square brackets for marking extended links by passing a value for \f(CW\*(C`extended_link_delimiters\*(C'\fR in the \f(CW%tags\fR hash when calling \f(CW\*(C`format\*(C'\fR. .Sp Note that if you disable this flag, you should probably enable \&\f(CW\*(C`implicit_links\*(C'\fR or there will be no automated way to link to other pages in your wiki. .IP "implicit_links" 4 .IX Item "implicit_links" A boolean flag, false by default, to create links from StudlyCapsStrings. .IP "absolute_links" 4 .IX Item "absolute_links" A boolean flag, true by default, which treats any links that are absolute URIs (such as \f(CW\*(C`http://www.cpan.org/\*(C'\fR) specially. Any prefix will not apply. This should maybe be called implicit_absolute_links since the \f(CW\*(C`extended\*(C'\fR option enables absolute links inside square brackets by default. .Sp A link is any text that starts with a known schema followed by a colon and one or more non-whitespace characters. This is a distinct subset of what \s-1URI\s0 recognizes as a \s-1URI\s0, but is a good first-order approximation. If you need to recognize more complex URIs, use the standard wiki formatting explained earlier. .Sp The recognized schemas are those defined in the \f(CW\*(C`schema\*(C'\fR value in the \f(CW%tags\fR hash. \f(CW\*(C`schema\*(C'\fR defaults to \f(CW\*(C`http\*(C'\fR, \f(CW\*(C`https\*(C'\fR, \f(CW\*(C`ftp\*(C'\fR, \f(CW\*(C`mailto\*(C'\fR, and \&\f(CW\*(C`gopher\*(C'\fR. .IP "process_html" 4 .IX Item "process_html" This flag, true by default, causes the formatter to ignore block level wiki markup (code, ordered, unordered, etc...) when they occur on lines which also contain allowed block-level \s-1HTML\s0 tags (
, 
    ,
      ,
, etc...). Phrase level wiki markup (emphasis, strong, & links) is unaffected by this flag. .SS "format_line" .IX Subsection "format_line" .Vb 1 \& $formatted = format_line ($raw, $tags, $opts); .Ve .PP This function is never exported. It formats the phrase elements of a single line of text (emphasised, strong, and links). .PP This is only meant to be called from Text::MediawikiFormat::Block and so requires \f(CW$tags\fR and \f(CW$opts\fR to have all elements filled in. If you find a use for it, please let me know and maybe I will have it default the missing elements as \&\f(CW\*(C`format()\*(C'\fR does. .SH "Wiki Format" .IX Header "Wiki Format" Refer to for description of the default wiki format, as interpreted by this module. Any discrepencies will be considered bugs in this module, with a few exceptions. .SS "Unimplemented Wiki Markup" .IX Subsection "Unimplemented Wiki Markup" .IP "Templates, Magic Words, and Wanted Links" 4 .IX Item "Templates, Magic Words, and Wanted Links" Templates, magic words, and the colorization of wanted links all require a back end data store that can be consulted on the existance and content of named pages. \f(CW\*(C`Text::MediawikiFormat\*(C'\fR has deliberately been constructed such that it operates independantly from such a back end. For an interface to \&\f(CW\*(C`Text::MediawikiFormat\*(C'\fR which implements these features, see Wiki::Toolkit::Formatter::Mediawiki. .IP "Tables" 4 .IX Item "Tables" This is on the \s-1TODO\s0 list. .SH "EXPORT" .IX Header "EXPORT" If you'd like to make your life more convenient, you can optionally import a subroutine that already has default tags and options set up. This is especially handy if you use a prefix: .PP .Vb 2 \& use Text::MediawikiFormat prefix => \*(Aqhttp://www.example.com/\*(Aq; \& wikiformat (\*(Aqsome text\*(Aq); .Ve .PP Tags are interpreted as default members of the \f(CW$tags\fR hash normally passed to \&\f(CW\*(C`format\*(C'\fR, except for the five options (see above) and the \f(CW\*(C`as\*(C'\fR key, who's value is interpreted as an alternate name for the imported function. .PP To use the \f(CW\*(C`as\*(C'\fR flag to control the name by which your code calls the imported function, for example, .PP .Vb 2 \& use Text::MediawikiFormat as => \*(AqformatTextWithWikiStyle\*(Aq; \& formatTextWithWikiStyle (\*(Aqsome text\*(Aq); .Ve .PP You might choose a better name, though. .PP The calling semantics are effectively the same as those of the \f(CW\*(C`format()\*(C'\fR function. Any additional tags or options to the imported function will override the defaults. This code: .PP .Vb 2 \& use Text::MediawikiFormat as => \*(Aqwf\*(Aq, extended => 0; \& wf (\*(Aqsome text\*(Aq, {}, {extended => 1}); .Ve .PP enables extended links, after specifying that the default behavior should be to disable them. .SH "GORY DETAILS" .IX Header "GORY DETAILS" .SS "Tags" .IX Subsection "Tags" There are two types of Wiki markup: phrase markup and blocks. Blocks include lists, which are made up of lines and can also contain other lists. .PP \fIPhrase Markup\fR .IX Subsection "Phrase Markup" .PP The are currently three types of wiki phrase markup. These are the strong and emphasized markup and links. Links may additionally be of three subtypes, extended, implicit, or absolute. .PP You can change the regular expressions used to find strong and emphasized tags: .PP .Vb 4 \& %tags = ( \& strong_tag => qr/\e*([^*]+?)\e*/, \& emphasized_tag => qr|/([^/]+?)/|, \& ); \& \& $wikitext = \*(Aqthis is *strong*, /emphasized/, and */em+strong/*\*(Aq; \& $htmltext = wikiformat ($wikitext, \e%tags, {}); .Ve .PP You can also change the regular expressions used to find links. The following just sets them to their default states (but enables parsing of implicit links, which is \fInot\fR the default): .PP .Vb 8 \& my $html = wikiformat \& ( \& $raw, \& {implicit_link_delimiters => qr!\eb(?:[A\-Z][a\-z0\-9]\ew*){2,}!, \& extended_link_delimiters => qr!\e[(?:\e[[^][]*\e]|[^][]*)\e]!, \& }, \& {implicit_links => 1} \& ); .Ve .PP In addition, you may set the function references that format strong and emphasized text and links. The strong and emphasized functions receive only the text to be formatted as an argument and are expected to return the formatted text. The link formatter also recieves references to the \f(CW$tags\fR and \f(CW$opts\fR arrays. For example, the following sets the strong and emphasized formatters to their default state while replacing the link formatter with one which strips href information and returns only the title text: .PP .Vb 10 \& my $html = wikiformat \& ( \& $raw, \& {strong => sub {"$_[0]"}, \& emphasized => sub {"$_[0]"}, \& link => sub \& { \& my ($tag, $opts, $tags) = @_; \& if ($tag =~ s/^\e[\e[([^][]+)\e]\e]$/$1/) \& { \& my ($page, $title) = split qr/\e|/, $tag, 2; \& return $title if $title; \& return $page; \& } \& elsif ($tag =~ s/^\e[([^][]+)\e]$/$1/) \& { \& my ($href, $title) = split qr/ /, $tag, 2; \& return $title if $title; \& return $href; \& } \& else \& { \& return $tag; \& } \& }, \& }, \& ); .Ve .PP \fIBlocks\fR .IX Subsection "Blocks" .PP The default block types are \f(CW\*(C`code\*(C'\fR, \f(CW\*(C`line\*(C'\fR, \f(CW\*(C`paragraph\*(C'\fR, \f(CW\*(C`paragraph_break\*(C'\fR, \&\f(CW\*(C`unordered\*(C'\fR, \f(CW\*(C`ordered\*(C'\fR, \f(CW\*(C`definition\*(C'\fR, and \f(CW\*(C`header\*(C'\fR. .PP Block entries in the tag hashes must contain array references. The first two items are the tags used at the start and end of the block. The third and fourth contain the tags used at the start and end of each line. Where there needs to be more processing of individual lines, use a subref as the third item. This is how the module processes ordered lines in \s-1HTML\s0 lists and headers: .PP .Vb 7 \& my $html = wikiformat \& ( \& $raw, \& {ordered => [\*(Aq
    \*(Aq, "
\en", \*(Aq
  • \*(Aq, "
  • \en"], \& header => [\*(Aq\*(Aq, "\en", \e&_make_header], \& }, \& ); .Ve .PP The first argument to these subrefs is the post-processed text of the line itself. (Processing removes the indentation and tokens used to mark this as a list and checks the rest of the line for other line formattings.) The second argument is the indentation level (see below). The subsequent arguments are captured variables in the regular expression used to find this list type. The regexp for headers is: .PP .Vb 5 \& $html = wikiformat \& ( \& $raw, \& {blocks => {header => qr/^(=+)\es*(.+?)\es*\e1$/}} \& ); .Ve .PP The module processes indentation first, if applicable, and stores the indentation level (the length of the indentation removed). .PP Lists automatically start and end as necessary. .PP Because regular expressions could conceivably match more than one line, block level markup is processed in a specific order. The \f(CW\*(C`blockorder\*(C'\fR tag governs this order. It contains a reference to an array of the names of the appropriate blocks to process. If you add a block type, be sure to add an entry for it in \f(CW\*(C`blockorder\*(C'\fR: .PP .Vb 11 \& my $html = wikiformat \& ( \& $raw, \& {invisible => [\*(Aq\*(Aq, \*(Aq\*(Aq, \*(Aq\*(Aq, \*(Aq\*(Aq], \& blocks => {invisible => qr!^\-\-(.*?)\-\-$!}, \& blockorder => [qw(code header line ordered \& unordered definition invisible \& paragraph_break paragraph)] \& }, \& }, \& ); .Ve .PP \fIFinding blocks\fR .IX Subsection "Finding blocks" .PP As has already been mentioned in passing, \f(CW\*(C`Text::MediawikiFormat\*(C'\fR uses regular expressions to find blocks. These are in the \f(CW%tags\fR hash under the \f(CW\*(C`blocks\*(C'\fR key. For example, to change the regular expression to find code block items, use: .PP .Vb 1 \& my $html = wikiformat ($raw, {blocks => {code => qr/^:\es+/}}); .Ve .PP This will require a leading colon to mark code lines (note that as writted here, this would interfere with the default processing of definition lists). .PP \fIFinding Blocks in the Correct Order\fR .IX Subsection "Finding Blocks in the Correct Order" .PP As intrepid bug reporter Tom Hukins pointed out in \s-1CPAN\s0 \s-1RT\s0 bug #671, the order in which \f(CW\*(C`Text::MediawikiFormat\*(C'\fR searches for blocks varies by platform and version of Perl. Because some block-finding regular expressions are more specific than others, what you intend to be one type of block may turn into a different list type. .PP If you're adding new block types, be aware of this. The \f(CW\*(C`blockorder\*(C'\fR entry in \&\f(CW%tags\fR exists to force \f(CW\*(C`Text::MediawikiFormat\*(C'\fR to apply its regexes from most specific to least specific. It contains an array reference. By default, it looks for ordered lists first, unordered lists second, and code references at the end. .SH "SEE ALSO" .IX Header "SEE ALSO" Wiki::Toolkit::Formatter::Mediawiki .SH "SUPPORT" .IX Header "SUPPORT" You can find documentation for this module with the perldoc command. .PP .Vb 1 \& perldoc Text::MediawikiFormat .Ve .PP You can also look for information at: .IP "\(bu" 4 AnnoCPAN: Annotated \s-1CPAN\s0 documentation .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Ratings .Sp .IP "\(bu" 4 \&\s-1RT:\s0 \s-1CPAN\s0's request tracker .Sp .IP "\(bu" 4 Search \s-1CPAN\s0 .Sp .SH "AUTHOR" .IX Header "AUTHOR" Derek Price \f(CW\*(C`derek at ximbiot.com\*(C'\fR is the author. .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" This module is derived from Text::WikiFormat, written by chromatic. chromatic's original credits are below: .PP chromatic, \f(CW\*(C`chromatic at wgz.org\*(C'\fR, with much input from the Jellybean team (including Jonathan Paulett). Kate L Pugh has also provided several patches, many failing tests, and is usually the driving force behind new features and releases. If you think this module is worth buying me a beer, she deserves at least half of it. .PP Alex Vandiver added a nice patch and tests for extended links. .PP Tony Bowden, Tom Hukins, and Andy H. all suggested useful features that are now implemented. .PP Sam Vilain, Chris Winters, Paul Schmidt, and Art Henry have all found and reported silly bugs. .PP Blame me for the implementation. .SH "BUGS" .IX Header "BUGS" The link checker in \f(CW\*(C`format_line()\*(C'\fR may fail to detect existing links that do not follow \s-1HTML\s0, \s-1XML\s0, or \s-1SGML\s0 style. They may die with some \s-1SGML\s0 styles too. \&\fISic transit gloria mundi\fR. .SH "TODO" .IX Header "TODO" .IP "\(bu" 4 Optimize \f(CW\*(C`format_line()\*(C'\fR to work on a list of lines .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" .Vb 2 \& Copyright (c) 2006\-2008 Derek R. Price, all rights reserved. \& Copyright (c) 2002 \- 2006, chromatic, all rights reserved. .Ve .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.