1
package HTML::WikiConverter::PhpWiki;
2
use base 'HTML::WikiConverter';
8
hr => { replace => "\n----\n" },
9
br => { replace => '%%%' },
11
blockquote => { start => \&_blockquote_start, block => 1, line_format => 'multi' },
12
p => { block => 1, trim => 'both', line_format => 'multi' },
13
i => { start => "_", end => "_" },
14
em => { alias => 'i' },
15
b => { start => "*", end => "*" },
16
strong => { alias => 'b' },
18
img => { replace => \&_image },
19
a => { replace => \&_link },
21
ul => { line_format => 'multi', block => 1 },
22
ol => { alias => 'ul' },
23
dl => { line_format => 'blocks', block => 1 },
25
li => { start => \&_li_start, trim => 'leading' },
26
dt => { trim => 'both', end => ":\n" },
27
dd => { line_prefix => ' ' },
29
td => { start => \&_td_start, end => \&_td_end, trim => 'both' },
30
th => { alias => 'td' },
32
h1 => { start => '!!! ', block => 1, trim => 'both', line_format => 'single' },
33
h2 => { start => '!!! ', block => 1, trim => 'both', line_format => 'single' },
34
h3 => { start => '!! ', block => 1, trim => 'both', line_format => 'single' },
35
h4 => { start => '! ', block => 1, trim => 'both', line_format => 'single' },
36
h5 => { start => '! ', block => 1, trim => 'both', line_format => 'single' },
37
h6 => { start => '! ', block => 1, trim => 'both', line_format => 'single' },
39
pre => { preserve => 1 },
42
# HTML tags allowed in wiki markup
43
foreach my $tag ( qw/ big small tt abbr acronym cite code dfn kbd samp var sup sub / ) {
44
$rules{$tag} = { preserve => 1 }
50
# Calculates the prefix that will be placed before each list item.
51
# List item include ordered and unordered list items.
53
my( $self, $node, $rules ) = @_;
54
my @parent_lists = $node->look_up( _tag => qr/ul|ol/ );
55
my $depth = @parent_lists;
58
$bullet = '*' if $node->parent->tag eq 'ul';
59
$bullet = '#' if $node->parent->tag eq 'ol';
61
my $prefix = ( $bullet ) x $depth;
66
my( $self, $node, $rules ) = @_;
67
return $node->attr('src') || '';
71
my( $self, $node, $rules ) = @_;
72
my $url = $node->attr('href') || '';
73
my $text = $self->get_elem_contents($node) || '';
74
return "[$text|$url]";
77
# Not quite right yet (e.g. doesn't handle rowspan)
79
my( $self, $node, $rules ) = @_;
80
my @left = $node->left;
81
return '' unless @left;
82
return ( ( ' ' ) x scalar(@left) );
86
my( $self, $node, $rules ) = @_;
87
my $right_tag = $node->right && $node->right->tag ? $node->right->tag : '';
88
return $right_tag =~ /td|th/ ? " |\n" : "\n";
91
sub _blockquote_start {
92
my( $self, $node, $rules ) = @_;
93
my @bq_lineage = $node->look_up( _tag => 'blockquote' );
94
my $depth = @bq_lineage;
95
return "\n" . ( ( ' ' ) x $depth );
99
my( $self, $node ) = @_;
100
$self->strip_aname($node) if $node->tag eq 'a';
101
$self->caption2para($node) if $node->tag eq 'caption';
110
HTML::WikiConverter::PhpWiki - HTML-to-wiki conversion rules for PhpWiki
114
use HTML::WikiConverter;
115
my $wc = new HTML::WikiConverter( dialect => 'PhpWiki' );
116
print $wc->html2wiki( $html );
120
This module contains rules for converting HTML into PhpWiki
121
markup. See L<HTML::WikiConverter> for additional usage details.
125
David J. Iberri <diberri@yahoo.com>
129
Copyright (c) 2005 David J. Iberri
131
This library is free software; you can redistribute it and/or modify
132
it under the same terms as Perl itself.
134
See http://www.perl.com/perl/misc/Artistic.html