.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) .\" .\" 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" '' . ds C` . ds C' '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. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Wiki::Toolkit::Formatter::UseMod 3pm" .TH Wiki::Toolkit::Formatter::UseMod 3pm "2016-01-17" "perl v5.22.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" Wiki::Toolkit::Formatter::UseMod \- UseModWiki\-style formatting for Wiki::Toolkit .SH "DESCRIPTION" .IX Header "DESCRIPTION" A formatter backend for Wiki::Toolkit that supports UseMod-style formatting. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Wiki::Toolkit::Formatter::UseMod; \& \& # Instantiate \- see below for parameter details. \& my $formatter = Wiki::Toolkit::Formatter::UseMod\->new( %config ); \& \& # Format some text. \& my $cooked = $formatter\->format($raw); \& \& # Find out which other nodes that text would link to. \& my @links_to = $formatter\->find_internal_links($raw); .Ve .SH "METHODS" .IX Header "METHODS" .IP "\fBnew\fR" 4 .IX Item "new" .Vb 10 \& my $formatter = Wiki::Toolkit::Formatter::UseMod\->new( \& extended_links => 0, # $FreeLinks \& implicit_links => 1, # $WikiLinks \& force_ucfirst_nodes => 1, # $FreeUpper \& use_headings => 1, # $UseHeadings \& allowed_tags => [qw(b i)], # defaults to none \& macros => {}, \& pass_wiki_to_macros => 0, \& node_prefix => \*(Aqwiki.pl?\*(Aq, \& node_suffix => \*(Aq\*(Aq, \& edit_prefix => \*(Aqwiki.pl?action=edit;id=\*(Aq, \& edit_suffix => \*(Aq\*(Aq, \& munge_urls => 0, \& external_link_class => \*(Aqexternal\*(Aq, \& escape_url_commas => 1, \& ); .Ve .Sp Parameters will default to the values shown above (apart from \&\f(CW\*(C`allowed_tags\*(C'\fR, which defaults to allowing no tags, and \&\f(CW\*(C`external_link_class\*(C'\fR, which defaults to false). .RS 4 .IP "\fBInternal links\fR" 4 .IX Item "Internal links" \&\f(CW\*(C`node_prefix\*(C'\fR, \f(CW\*(C`node_suffix\*(C'\fR, \f(CW\*(C`edit_prefix\*(C'\fR and \f(CW\*(C`edit_suffix\*(C'\fR allow you to control the URLs generated for links to other wiki pages. So for example with the defaults given above, a link to the Home node will have the \s-1URL \s0\f(CW\*(C`wiki.pl?Home\*(C'\fR and a link to the edit form for the Home node will have the \s-1URL \s0\f(CW\*(C`wiki.pl?action=edit;id=Home\*(C'\fR .Sp (Note that of course the URLs that you wish to have generated will depend on how your wiki application processes its \s-1CGI\s0 parameters \- you can't just put random stuff in there and hope it works!) .Sp By default, any commas in these URLs will be escaped to \f(CW%2C\fR, in line with the default behaviour of URI::Escape. If you don't want this to happen, pass a false value to \f(CW\*(C`escape_url_commas\*(C'\fR. .IP "\fBInternal links \- advanced options\fR" 4 .IX Item "Internal links - advanced options" If you wish to have greater control over the links, you may use the \&\f(CW\*(C`munge_node_name\*(C'\fR parameter. The value of this should be a subroutine reference. This sub will be called on each internal link after all other formatting and munging \fIexcept\fR \s-1URL\s0 escaping has been applied. It will be passed the node name as its first parameter and should return a node name. Note that this will affect the URLs of internal links, but not the link text. .Sp Example: .Sp .Vb 7 \& # The formatter munges links so node names are ucfirst. \& # Ensure \*(Aqstate51\*(Aq always appears in lower case in node names. \& munge_node_name => sub { \& my $node_name = shift; \& $node_name =~ s/State51/state51/g; \& return $node_name; \& } .Ve .Sp \&\fBNote:\fR This is \fIadvanced\fR usage and you should only do it if you \&\fIreally\fR know what you're doing. Consider in particular whether and how your munged nodes are going to be treated by \f(CW\*(C`retrieve_node\*(C'\fR. .IP "\fBExternal links\fR" 4 .IX Item "External links" By default, we emulate the UseModWiki behaviour of formatting external links with hardcoded square brackets around them. If you would instead prefer to control this with \s-1CSS,\s0 supply the \&\f(CW\*(C`external_link_class\*(C'\fR parameter to \f(CW\*(C`\->new\*(C'\fR \- the value of this parameter will be used as the class applied to the link (so it should be a valid \s-1CSS\s0 class name). Controlling the appearance with \s-1CSS\s0 is our recommended method, but the default is as described for reasons of backward compatibility. .IP "\fB\s-1URL\s0 munging\fR" 4 .IX Item "URL munging" If you set \f(CW\*(C`munge_urls\*(C'\fR to true, then your URLs will be more user-friendly, for example .Sp .Vb 1 \& http://example.com/wiki.cgi?Mailing_List_Managers .Ve .Sp rather than .Sp .Vb 1 \& http://example.com/wiki.cgi?Mailing%20List%20Managers .Ve .Sp The former behaviour is the actual UseMod behaviour, but requires a little fiddling about in your code (see \f(CW\*(C`node_name_to_node_param\*(C'\fR), so the default is to \fBnot\fR munge URLs. .IP "\fBMacros\fR" 4 .IX Item "Macros" Be aware that macros are processed \fIafter\fR filtering out disallowed \&\s-1HTML\s0 tags and \fIbefore\fR transforming from wiki markup into \s-1HTML. \s0 They are also not called in any particular order. .Sp The keys of macros should be either regexes or strings. The values can be strings, or, if the corresponding key is a regex, can be coderefs. The coderef will be called with the first nine substrings captured by the regex as arguments. I would like to call it with all captured substrings but apparently this is complicated. .Sp You may wish to have access to the overall wiki object in the subs defined in your macro. To do this: .RS 4 .IP "\(bu" 4 Pass the wiki object to the \f(CW\*(C`\->formatter\*(C'\fR call as described below. .IP "\(bu" 4 Pass a true value in the \f(CW\*(C`pass_wiki_to_macros\*(C'\fR parameter when calling \&\f(CW\*(C`\->new\*(C'\fR. .RE .RS 4 .Sp If you do this, then \fIall\fR coderefs will be called with the wiki object as the first parameter, followed by the first nine captured substrings as described above. Note therefore that setting \f(CW\*(C`pass_wiki_to_macros\*(C'\fR may cause backwards compatibility issues. .RE .RE .RS 4 .Sp Macro examples: .Sp .Vb 1 \& # Simple example \- substitute a little search box for \*(Aq@SEARCHBOX\*(Aq \& \& macros => { \& \& \*(Aq@SEARCHBOX\*(Aq => \& qq(
\& \& \&
), \& } \& \& # More complex example \- substitute a list of all nodes in a \& # category for \*(Aq@INDEX_LINK [[Category Foo]]\*(Aq \& \& pass_wiki_to_macros => 1, \& macros => { \& qr/\e@INDEX_LINK\es+\e[\e[Category\es+([^\e]]+)]]/ => \& sub { \& my ($wiki, $category) = @_; \& my @nodes = $wiki\->list_nodes_by_metadata( \& metadata_type => "category", \& metadata_value => $category, \& ignore_case => 1, \& ); \& my $return = "\en"; \& foreach my $node ( @nodes ) { \& $return .= "* " \& . $wiki\->formatter\->format_link( \& wiki => $wiki, \& link => $node, \& ) \& . "\en"; \& } \& return $return; \& }, \& } .Ve .RE .IP "\fBformat\fR" 4 .IX Item "format" .Vb 1 \& my $html = $formatter\->format($submitted_content, $wiki); .Ve .Sp Escapes any tags which weren't specified as allowed on creation, then interpolates any macros, then translates the raw Wiki language supplied into \s-1HTML.\s0 .Sp A Wiki::Toolkit object can be supplied as an optional second parameter. This object will be used to determine whether a linked-to node exists or not, and alter the presentation of the link accordingly. This is only really in here for use when this method is being called from within Wiki::Toolkit. .IP "\fBformat_link\fR" 4 .IX Item "format_link" .Vb 4 \& my $string = $formatter\->format_link( \& link => "Home Node", \& wiki => $wiki, \& ); .Ve .Sp An internal method exposed to make it easy to go from eg .Sp .Vb 2 \& * Foo \& * Bar .Ve .Sp to .Sp .Vb 2 \& * Foo \& * Bar .Ve .Sp See Macro Examples above for why you might find this useful. .Sp \&\f(CW\*(C`link\*(C'\fR should be something that would go inside your extended link delimiters. \f(CW\*(C`wiki\*(C'\fR is optional but should be a Wiki::Toolkit object. If you do supply \f(CW\*(C`wiki\*(C'\fR then the method will be able to check whether the node exists yet or not and so will call \f(CW\*(C`\->make_edit_link\*(C'\fR instead of \f(CW\*(C`\->make_internal_link\*(C'\fR where appropriate. If you don't supply \f(CW\*(C`wiki\*(C'\fR then \f(CW\*(C`\->make_internal_link\*(C'\fR will be called always. .Sp This method used to be private so may do unexpected things if you use it in a way that I haven't tested yet. .IP "\fBfind_internal_links\fR" 4 .IX Item "find_internal_links" .Vb 1 \& my @links_to = $formatter\->find_internal_links( $content ); .Ve .Sp Returns a list of all nodes that the supplied content links to. .IP "\fBnode_name_to_node_param\fR" 4 .IX Item "node_name_to_node_param" .Vb 3 \& use URI::Escape; \& $param = $formatter\->node_name_to_node_param( "Recent Changes" ); \& my $url = "wiki.pl?" . uri_escape($param); .Ve .Sp In usemod, the node name is encoded prior to being used as part of the \&\s-1URL.\s0 This method does this encoding (essentially, whitespace is munged into underscores). In addition, if \f(CW\*(C`force_ucfirst_nodes\*(C'\fR is in action then the node names will be forced ucfirst if they weren't already. .Sp Note that unless \f(CW\*(C`munge_urls\*(C'\fR was set to true when \f(CW\*(C`new\*(C'\fR was called, this method will do nothing. .IP "\fBnode_param_to_node_name\fR" 4 .IX Item "node_param_to_node_name" .Vb 2 \& my $node = $q\->param(\*(Aqnode\*(Aq) || ""; \& $node = $formatter\->node_param_to_node_name( $node ); .Ve .Sp In usemod, the node name is encoded prior to being used as part of the \&\s-1URL,\s0 so we must decode it before we can get back the original node name. .Sp Note that unless \f(CW\*(C`munge_urls\*(C'\fR was set to true when \f(CW\*(C`new\*(C'\fR was called, this method will do nothing. .SH "SUBCLASSING" .IX Header "SUBCLASSING" The following methods can be overridden to provide custom behaviour. .IP "\fBmake_edit_link\fR" 4 .IX Item "make_edit_link" .Vb 4 \& my $link = $self\->make_edit_link( \& title => "Home Page", \& url => "http://example.com/?id=Home", \& ); .Ve .Sp This method will be passed a title and a url and should return an \s-1HTML\s0 snippet. For example, you can add a \f(CW\*(C`title\*(C'\fR attribute to the link like so: .Sp .Vb 6 \& sub make_edit_link { \& my ($self, %args) = @_; \& my $title = $args{title}; \& my $url = $args{url}; \& return qq|[$title]?|; \& } .Ve .IP "\fBmake_internal_link\fR" 4 .IX Item "make_internal_link" .Vb 4 \& my $link = $self\->make_internal_link( \& title => "Home Page", \& url => "http://example.com/?id=Home", \& ); .Ve .Sp This method will be passed a title and a url and should return an \s-1HTML\s0 snippet. For example, you can add a \f(CW\*(C`class\*(C'\fR attribute to the link like so: .Sp .Vb 6 \& sub make_internal_link { \& my ($self, %args) = @_; \& my $title = $args{title}; \& my $url = $args{url}; \& return qq|$title|; \& } .Ve .IP "\fBmake_external_link\fR" 4 .IX Item "make_external_link" .Vb 4 \& my $link = $self\->make_external_link( \& title => "London Perlmongers", \& url => "http://london.pm.org", \& ); .Ve .Sp This method will be passed a title and a url and should return an \s-1HTML\s0 snippet. For example, you can add a little icon after each external link like so: .Sp .Vb 6 \& sub make_external_link { \& my ($self, %args) = @_; \& my $title = $args{title}; \& my $url = $args{url}; \& return qq|$title |; \& } .Ve .SH "AUTHOR" .IX Header "AUTHOR" Kake Pugh (kake@earth.li) and the Wiki::Toolkit team. .SH "COPYRIGHT" .IX Header "COPYRIGHT" .Vb 2 \& Copyright (C) 2003\-2004 Kake Pugh. All Rights Reserved. \& Copyright (C) 2006\-2012 the Wiki::Toolkit team. All Rights Reserved. .Ve .PP This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "CREDITS" .IX Header "CREDITS" The OpenGuides London team () sent some very helpful bug reports. A lot of the work of this module is done within chromatic's module, Text::WikiFormat. .SH "CAVEATS" .IX Header "CAVEATS" This doesn't yet support all of UseMod's formatting features and options, by any means. This really truly \fIis\fR a 0.* release. Please send bug reports, omissions, patches, and stuff, to me at \&\f(CW\*(C`kake@earth.li\*(C'\fR. .SH "NOTE ON USEMOD COMPATIBILITY" .IX Header "NOTE ON USEMOD COMPATIBILITY" UseModWiki \*(L"encodes\*(R" node names before making them part of a \s-1URL,\s0 so for example a node about Wombat Defenestration will have a \s-1URL\s0 like .PP .Vb 1 \& http://example.com/wiki.cgi?Wombat_Defenestration .Ve .PP So if we want to emulate a UseModWiki exactly, we need to munge back and forth between node names as titles, and node names as \s-1CGI\s0 params. .PP .Vb 3 \& my $formatter = Wiki::Toolkit::Formatter::UseMod\->new( munge_urls => 1 ); \& my $node_param = $q\->param(\*(Aqid\*(Aq) || $q\->param(\*(Aqkeywords\*(Aq) || ""; \& my $node_name = $formatter\->node_param_to_node_name( $node_param ); \& \& use URI::Escape; \& my $url = "http://example.com/wiki.cgi?" \& . uri_escape( \& $formatter\->node_name_to_node_param( "Wombat Defenestration" ) \& ); .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 Wiki::Toolkit .IP "\(bu" 4 Text::WikiFormat .IP "\(bu" 4 UseModWiki ()