line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::WikiConverter::XWiki;
|
2
|
1
|
|
|
1
|
|
20648
|
use base 'HTML::WikiConverter';
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
476
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict;
|
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
27
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5669
|
use URI;
|
|
1
|
|
|
|
|
10748
|
|
|
1
|
|
|
|
|
683
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02';
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
HTML::WikiConverter::XWiki - Convert HTML to XWiki markup
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use HTML::WikiConverter;
|
17
|
|
|
|
|
|
|
my $wc = new HTML::WikiConverter(
|
18
|
|
|
|
|
|
|
dialect => 'XWiki',
|
19
|
|
|
|
|
|
|
space_identifier => 'MySpace'
|
20
|
|
|
|
|
|
|
);
|
21
|
|
|
|
|
|
|
print $wc->html2wiki( $html );
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
- or -
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
html2wiki --dialect XWiki --base-uri=http://yoursite.xwiki.org/ index.html
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This module contains rules for converting HTML into XWiki markup, the wiki dialect used by xwiki.org.
|
30
|
|
|
|
|
|
|
See L for additional usage details.
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 ATTRIBUTES
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
The XWiki converter introduces a new attribute C.
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 space_identifier
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
The value of this attribute is used to generate local links. The default value is C<'Main'>.
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Ca href="http://www.xwiki.org/Test"ETestE/aE> would result as C<[Test|Main.Test]>.
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub rules {
|
45
|
0
|
|
|
0
|
0
|
|
my %rules = (
|
46
|
|
|
|
|
|
|
b => { start => '*', end => '*' },
|
47
|
|
|
|
|
|
|
i => { start => '~~', end => '~~' },
|
48
|
|
|
|
|
|
|
strong => { alias => 'b' },
|
49
|
|
|
|
|
|
|
s => { start => '--', end => '--' },
|
50
|
|
|
|
|
|
|
del => { alias => 's' },
|
51
|
|
|
|
|
|
|
em => { alias => 'i' },
|
52
|
|
|
|
|
|
|
hr => { replace => "\n----\n" },
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
ul => { line_format => 'multi', block => 1 },
|
55
|
|
|
|
|
|
|
ol => { alias => 'ul' },
|
56
|
|
|
|
|
|
|
li => { start => \&_li_start, trim => 'leading' },
|
57
|
|
|
|
|
|
|
code => { start => '{code}', end => '{code}', },
|
58
|
|
|
|
|
|
|
pre => { start => '{pre}', end => '{/pre} ', block => 1 },
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
table => { start => "{table}\n", end => '{table}', block => 0, line_format => 'multi' },
|
61
|
|
|
|
|
|
|
tr => { line_format => 'single', end => "\n" },
|
62
|
|
|
|
|
|
|
td => { end => \&_td_end },
|
63
|
|
|
|
|
|
|
th => { alias => 'td' },
|
64
|
|
|
|
|
|
|
dl => { line_format => 'multi', block => 1, preserve => 1 },
|
65
|
|
|
|
|
|
|
dd => { preserve => 1 },
|
66
|
|
|
|
|
|
|
dt => { preserve => 1 },
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
p => { block => 1, line_format => 'multi', trim => 'both' },
|
69
|
|
|
|
|
|
|
br => { start => "\n" },
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
a => { replace => \&_link }
|
73
|
|
|
|
|
|
|
);
|
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my @arr = ();
|
76
|
0
|
|
|
|
|
|
for( 1..6 ) {
|
77
|
0
|
|
|
|
|
|
push( @arr, '1' );
|
78
|
0
|
|
|
|
|
|
my $str = join( ".", @arr );
|
79
|
0
|
|
|
|
|
|
$rules{"h$_"} = { start => "$str ", block => 1, trim => 'both', line_format => 'single' };
|
80
|
|
|
|
|
|
|
}
|
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return \%rules;
|
83
|
|
|
|
|
|
|
}
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub attributes {
|
87
|
0
|
|
|
0
|
0
|
|
my %attributes = (
|
88
|
|
|
|
|
|
|
space_identifier => { default => 'Main', optional => 0 }
|
89
|
|
|
|
|
|
|
);
|
90
|
0
|
|
|
|
|
|
return \%attributes;
|
91
|
|
|
|
|
|
|
}
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub _li_start {
|
95
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_;
|
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my @parents = $node->look_up( _tag => qr/ul|ol/ );
|
98
|
0
|
0
|
|
|
|
|
my $prefix = join '', map{ $_->tag eq 'ol' ? '1' : '*' } reverse @parents;
|
|
0
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
$prefix .= '.' if $node->parent->tag eq 'ol';
|
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return "\n$prefix ";
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _td_end {
|
106
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_;
|
107
|
0
|
0
|
|
|
|
|
my @right_cells = grep { $_->tag && $_->tag =~ /th|td/ } $node->right;
|
|
0
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
return ' | ' if @right_cells;
|
109
|
0
|
|
|
|
|
|
return '';
|
110
|
|
|
|
|
|
|
}
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _link {
|
114
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_;
|
115
|
0
|
|
0
|
|
|
|
my $url = $node->attr('href') || '';
|
116
|
0
|
|
0
|
|
|
|
my $text = $self->get_elem_contents($node) || '';
|
117
|
0
|
|
0
|
|
|
|
my $space = $self->_attr( 'space_identifier' ) || 'Main';
|
118
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
if( my $title = $self->get_wiki_page( $url ) ) {
|
120
|
0
|
|
|
|
|
|
$text =~ s~\+~ ~g; # replace '+' by ' '
|
121
|
0
|
0
|
|
|
|
|
return "[$space.$text]" if lc $text eq lc $title;
|
122
|
0
|
|
|
|
|
|
return "[$text|$space.$title]";
|
123
|
|
|
|
|
|
|
} else {
|
124
|
0
|
0
|
|
|
|
|
return $url if $url eq $text;
|
125
|
0
|
|
|
|
|
|
return "[$text>$url]";
|
126
|
|
|
|
|
|
|
}
|
127
|
|
|
|
|
|
|
}
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 AUTHOR
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Patrick Stählin, C<< >>.
|
133
|
|
|
|
|
|
|
Many thanks to David J. Iberri, C<< >> for writing L.
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 SUPPORT
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command.
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
perldoc HTML::WikiConverter::XWiki
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Copyright 2006 Encodo Systems AG, all rights reserved.
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
147
|
|
|
|
|
|
|
it under the same terms as Perl itself.
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1;
|