| Wiki-Toolkit-Formatter-Pod documentation | Contained in the Wiki-Toolkit-Formatter-Pod distribution. |
Wiki::Toolkit::Formatter::Pod - A Pod to HTML formatter for Wiki::Toolkit.
A Pod to HTML formatter backend for Wiki::Toolkit.
my $store = Wiki::Toolkit::Store::SQLite->new( ... );
my $formatter = Wiki::Toolkit::Formatter::Pod->new;
my $wiki = Wiki::Toolkit->new( store => $store,
formatter => $formatter );
Go look at Wiki::Toolkit to find out more. This module is distributed separately solely for convenience of testing and maintenance; it's probably not too useful on its own.
my $formatter = Wiki::Toolkit::Formatter::Pod->new(
node_prefix => 'wiki.cgi?node=',
usemod_extended_links => 0,
);
node_prefix is optional and defaults to the value shown above.
If usemod_extended_links is supplied and true, then UseModWiki-style
extended links [[like this]] will be supported - ie
[[foo bar]]
will be translated into a link to the node named "Foo Bar". (Node names are forced to ucfirst, ie first letter of each word is capitalised.)
Note: You must have Wiki::Toolkit::Formatter::UseMod installed if
you wish to use the usemod_extended_links parameter.
my $html = $formatter->format( $content );
Uses Pod::Tree::HTML to translate the pod supplied in $content
into HTML. Links will be treated as links to other wiki pages.
Kake Pugh (kake@earth.li), idea stolen from Matt Sergeant. Many thanks to Steven W McDougall for extending the capabilities of Pod::Tree::HTML so I could make this work.
Copyright (C) 2003 Kake Pugh. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Wiki-Toolkit-Formatter-Pod documentation | Contained in the Wiki-Toolkit-Formatter-Pod distribution. |
package Wiki::Toolkit::Formatter::Pod; use strict; use vars qw( $VERSION ); $VERSION = '0.04'; use IO::Scalar; use Pod::Tree::HTML;
sub new { my ($class, %args) = @_; my $self = { }; bless $self, $class; my $node_prefix = $args{node_prefix} || "wiki.cgi?node="; $self->{_node_prefix} = $node_prefix; $self->{_usemod_extended_links} = $args{usemod_extended_links} || 0; my $link_mapper = Wiki::Toolkit::Formatter::Pod::LinkMapper->new( node_prefix => $node_prefix ); $self->{_link_mapper} = $link_mapper; return $self; }
sub format { my ($self, $raw) = @_; return "" unless $raw; my $source = \$raw; my $formatted; my $dest = IO::Scalar->new( \$formatted ); my %options = ( link_map => $self->{_link_mapper} ); my $html = Pod::Tree::HTML->new( $source, $dest, %options ); $html->translate; $formatted =~ s/^.*<BODY[^>]*>//s; $formatted =~ s|</BODY>.*$||s; if ( $self->{_usemod_extended_links} ) { # Create link from [[foo bar]]. $formatted =~ s/(\[\[[^\]]+\]\])/$self->_linkify($1)/egs; } return $formatted; } sub _linkify { my ($self, $node) = @_; require Wiki::Toolkit::Formatter::UseMod; my $formatter = Wiki::Toolkit::Formatter::UseMod->new( implicit_links => 0, extended_links => 1, node_prefix => $self->{_node_prefix}, ); my $snippet = $formatter->format($1); # Snippet will be created as a paragraph, which we don't want as we're # inlining this. $snippet =~ s/^<p>//s; $snippet =~ s/<\/p>$//s; return $snippet; }
package Wiki::Toolkit::Formatter::Pod::LinkMapper; sub new { my ($class, %args) = @_; my $self = { }; bless $self, $class; $self->{_node_prefix} = $args{node_prefix} || ""; return $self; } sub url { my ($self, $html, $target) = @_; my $page = $target->get_page; my $section = $target->get_section; if ( $page ) { $page = $self->{_node_prefix} . $html->escape_2396($page); } $section = $html->escape_2396($section); return $html->assemble_url("", $page, $section); } 1;