[svn-inject] Installing original source of libhtml-wikiconverter-kwiki-perl
Jonas Smedegaard
15 years ago
0 | # Change log for HTML::WikiConverter::Kwiki | |
1 | ||
2 | version: 0.51 | |
3 | date: Fri Sep 25 2007 | |
4 | changes: | |
5 | - Fix test suite with new t/runtests.pl that doesn't use nonexistent 'strip_comments' attrib | |
6 | ||
7 | version: 0.50 | |
8 | date: Tue Jan 10 2006 | |
9 | changes: | |
10 | - Branched from main HTML::WikiConverter codebase. |
0 | Changes | |
1 | MANIFEST | |
2 | META.yml # Will be created by "make dist" | |
3 | Makefile.PL | |
4 | README | |
5 | lib/HTML/WikiConverter/Kwiki.pm | |
6 | t/00-load.t | |
7 | t/boilerplate.t | |
8 | t/kwiki.t | |
9 | t/pod-coverage.t | |
10 | t/pod.t | |
11 | t/runtests.pl |
0 | # http://module-build.sourceforge.net/META-spec.html | |
1 | #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# | |
2 | name: HTML-WikiConverter-Kwiki | |
3 | version: 0.51 | |
4 | version_from: lib/HTML/WikiConverter/Kwiki.pm | |
5 | installdirs: site | |
6 | requires: | |
7 | HTML::WikiConverter: 0.55 | |
8 | Test::More: 0 | |
9 | ||
10 | distribution_type: module | |
11 | generated_by: ExtUtils::MakeMaker version 6.17 |
0 | use strict; | |
1 | use warnings; | |
2 | use ExtUtils::MakeMaker; | |
3 | ||
4 | WriteMakefile( | |
5 | NAME => 'HTML::WikiConverter::Kwiki', | |
6 | AUTHOR => 'David J. Iberri <diberri@cpan.org>', | |
7 | VERSION_FROM => 'lib/HTML/WikiConverter/Kwiki.pm', | |
8 | ABSTRACT_FROM => 'lib/HTML/WikiConverter/Kwiki.pm', | |
9 | PL_FILES => {}, | |
10 | PREREQ_PM => { | |
11 | 'Test::More' => 0, | |
12 | 'HTML::WikiConverter' => 0.55, | |
13 | }, | |
14 | dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, | |
15 | clean => { FILES => 'HTML-WikiConverter-Kwiki-*' }, | |
16 | ); |
0 | HTML::WikiConverter::Kwiki version 0.51 | |
1 | ======================================= | |
2 | ||
3 | HTML::WikiConverter::Kwiki adds the Kwiki dialect to | |
4 | HTML::WikiConverter allowing the conversion of HTML to Kwiki markup. | |
5 | ||
6 | SYNOPSIS | |
7 | ||
8 | Converting HTML to wiki markup is easy: | |
9 | ||
10 | use HTML::WikiConverter; | |
11 | my $wc = new HTML::WikiConverter( dialect => 'Kwiki' ); | |
12 | print $wc->html2wiki( $html ); | |
13 | ||
14 | Or from the command line: | |
15 | ||
16 | % html2wiki --dialect Kwiki input.html > output.wiki | |
17 | ||
18 | There's also a web interface if you're so inclined: | |
19 | ||
20 | http://diberri.dyndns.org/wikipedia/html2wiki/ | |
21 | ||
22 | CHANGES IN 0.51 | |
23 | ||
24 | * Test suite fixed so installation should proceed normally | |
25 | ||
26 | DEPENDENCIES | |
27 | ||
28 | * HTML::WikiConverter version 0.55 | |
29 | ||
30 | INSTALLATION | |
31 | ||
32 | To install this module, run the following commands: | |
33 | ||
34 | perl Makefile.PL | |
35 | make | |
36 | make test | |
37 | make install | |
38 | ||
39 | SUPPORT AND DOCUMENTATION | |
40 | ||
41 | After installing, you can find documentation for this module with the | |
42 | perldoc command. | |
43 | ||
44 | perldoc HTML::WikiConverter::Kwiki | |
45 | ||
46 | You can also look for information at: | |
47 | ||
48 | Search CPAN | |
49 | http://search.cpan.org/dist/HTML-WikiConverter-Kwiki | |
50 | ||
51 | CPAN Request Tracker: | |
52 | http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-WikiConverter-Kwiki | |
53 | ||
54 | AnnoCPAN, annotated CPAN documentation: | |
55 | http://annocpan.org/dist/HTML-WikiConverter-Kwiki | |
56 | ||
57 | CPAN Ratings: | |
58 | http://cpanratings.perl.org/d/HTML-WikiConverter-Kwiki | |
59 | ||
60 | COPYRIGHT AND LICENCE | |
61 | ||
62 | Copyright (C) 2006 David J. Iberri | |
63 | ||
64 | This program is free software; you can redistribute it and/or modify | |
65 | it under the same terms as Perl itself. |
0 | package HTML::WikiConverter::Kwiki; | |
1 | ||
2 | use warnings; | |
3 | use strict; | |
4 | ||
5 | use base 'HTML::WikiConverter'; | |
6 | ||
7 | our $VERSION = '0.51'; | |
8 | ||
9 | =head1 NAME | |
10 | ||
11 | HTML::WikiConverter::Kwiki - Convert HTML to Kwiki markup | |
12 | ||
13 | =head1 SYNOPSIS | |
14 | ||
15 | use HTML::WikiConverter; | |
16 | my $wc = new HTML::WikiConverter( dialect => 'Kwiki' ); | |
17 | print $wc->html2wiki( $html ); | |
18 | ||
19 | =head1 DESCRIPTION | |
20 | ||
21 | This module contains rules for converting HTML into Kwiki markup. See | |
22 | L<HTML::WikiConverter> for additional usage details. | |
23 | ||
24 | =cut | |
25 | ||
26 | sub rules { | |
27 | my %rules = ( | |
28 | hr => { replace => "\n----\n" }, | |
29 | br => { replace => "\n" }, | |
30 | ||
31 | h1 => { start => '= ', block => 1, trim => 'both', line_format => 'single' }, | |
32 | h2 => { start => '== ', block => 1, trim => 'both', line_format => 'single' }, | |
33 | h3 => { start => '=== ', block => 1, trim => 'both', line_format => 'single' }, | |
34 | h4 => { start => '==== ', block => 1, trim => 'both', line_format => 'single' }, | |
35 | h5 => { start => '===== ', block => 1, trim => 'both', line_format => 'single' }, | |
36 | h6 => { start => '====== ', block => 1, trim => 'both', line_format => 'single' }, | |
37 | ||
38 | p => { block => 1, trim => 'both', line_format => 'multi' }, | |
39 | b => { start => '*', end => '*', line_format => 'single' }, | |
40 | strong => { alias => 'b' }, | |
41 | i => { start => '/', end => '/', line_format => 'single' }, | |
42 | em => { alias => 'i' }, | |
43 | u => { start => '_', end => '_', line_format => 'single' }, | |
44 | strike => { start => '-', end => '-', line_format => 'single' }, | |
45 | s => { alias => 'strike' }, | |
46 | ||
47 | tt => { start => '[=', end => ']', trim => 'both', line_format => 'single' }, | |
48 | code => { alias => 'tt' }, | |
49 | pre => { line_prefix => ' ', block => 1 }, | |
50 | ||
51 | a => { replace => \&_link }, | |
52 | img => { replace => \&_image }, | |
53 | ||
54 | table => { block => 1 }, | |
55 | tr => { end => " |\n", line_format => 'single' }, | |
56 | td => { start => '| ', end => ' ' }, | |
57 | th => { alias => 'td' }, | |
58 | ||
59 | ul => { line_format => 'multi', block => 1 }, | |
60 | ol => { alias => 'ul' }, | |
61 | li => { start => \&_li_start, trim => 'leading' }, | |
62 | ); | |
63 | ||
64 | return \%rules; | |
65 | } | |
66 | ||
67 | sub _li_start { | |
68 | my( $self, $node, $rules ) = @_; | |
69 | my @parent_lists = $node->look_up( _tag => qr/ul|ol/ ); | |
70 | my $depth = @parent_lists; | |
71 | ||
72 | my $bullet = ''; | |
73 | $bullet = '*' if $node->parent->tag eq 'ul'; | |
74 | $bullet = '0' if $node->parent->tag eq 'ol'; | |
75 | ||
76 | my $prefix = ( $bullet ) x $depth; | |
77 | return "\n$prefix "; | |
78 | } | |
79 | ||
80 | sub _link { | |
81 | my( $self, $node, $rules ) = @_; | |
82 | my $url = $node->attr('href') || ''; | |
83 | my $text = $self->get_elem_contents($node) || ''; | |
84 | ||
85 | if( my $title = $self->get_wiki_page($url) ) { | |
86 | return $title if $self->is_camel_case( $title ) and $text eq $title; | |
87 | return "[$title]" if $text eq $title; | |
88 | return "[$text http:?$title]" if $text ne $title; | |
89 | } else { | |
90 | return $url if $text eq $url; | |
91 | return "[$text $url]"; | |
92 | } | |
93 | } | |
94 | ||
95 | sub _image { | |
96 | my( $self, $node, $rules ) = @_; | |
97 | return $node->attr('src') || ''; | |
98 | } | |
99 | ||
100 | sub preprocess_node { | |
101 | my( $self, $node ) = @_; | |
102 | $self->strip_aname($node) if $node->tag eq 'a'; | |
103 | $self->caption2para($node) if $node->tag eq 'caption'; | |
104 | } | |
105 | ||
106 | =head1 AUTHOR | |
107 | ||
108 | David J. Iberri, C<< <diberri at cpan.org> >> | |
109 | ||
110 | =head1 BUGS | |
111 | ||
112 | Please report any bugs or feature requests to | |
113 | C<bug-html-wikiconverter-kwiki at rt.cpan.org>, or through the web | |
114 | interface at | |
115 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-WikiConverter-Kwiki>. | |
116 | I will be notified, and then you'll automatically be notified of | |
117 | progress on your bug as I make changes. | |
118 | ||
119 | =head1 SUPPORT | |
120 | ||
121 | You can find documentation for this module with the perldoc command. | |
122 | ||
123 | perldoc HTML::WikiConverter::Kwiki | |
124 | ||
125 | You can also look for information at: | |
126 | ||
127 | =over 4 | |
128 | ||
129 | =item * AnnoCPAN: Annotated CPAN documentation | |
130 | ||
131 | L<http://annocpan.org/dist/HTML-WikiConverter-Kwiki> | |
132 | ||
133 | =item * CPAN Ratings | |
134 | ||
135 | L<http://cpanratings.perl.org/d/HTML-WikiConverter-Kwiki> | |
136 | ||
137 | =item * RT: CPAN's request tracker | |
138 | ||
139 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-WikiConverter-Kwiki> | |
140 | ||
141 | =item * Search CPAN | |
142 | ||
143 | L<http://search.cpan.org/dist/HTML-WikiConverter-Kwiki> | |
144 | ||
145 | =back | |
146 | ||
147 | =head1 COPYRIGHT & LICENSE | |
148 | ||
149 | Copyright 2006 David J. Iberri, all rights reserved. | |
150 | ||
151 | This program is free software; you can redistribute it and/or modify | |
152 | it under the same terms as Perl itself. | |
153 | ||
154 | =cut | |
155 | ||
156 | 1; |
0 | #!perl -T | |
1 | ||
2 | use Test::More tests => 1; | |
3 | ||
4 | BEGIN { | |
5 | use_ok( 'HTML::WikiConverter::Kwiki' ); | |
6 | } | |
7 | ||
8 | diag( "Testing HTML::WikiConverter::Kwiki $HTML::WikiConverter::Kwiki::VERSION, Perl $], $^X" ); |
0 | #!perl -T | |
1 | ||
2 | use strict; | |
3 | use warnings; | |
4 | use Test::More tests => 3; | |
5 | ||
6 | sub not_in_file_ok { | |
7 | my ($filename, %regex) = @_; | |
8 | open my $fh, "<", $filename | |
9 | or die "couldn't open $filename for reading: $!"; | |
10 | ||
11 | my %violated; | |
12 | ||
13 | while (my $line = <$fh>) { | |
14 | while (my ($desc, $regex) = each %regex) { | |
15 | if ($line =~ $regex) { | |
16 | push @{$violated{$desc}||=[]}, $.; | |
17 | } | |
18 | } | |
19 | } | |
20 | ||
21 | if (%violated) { | |
22 | fail("$filename contains boilerplate text"); | |
23 | diag "$_ appears on lines @{$violated{$_}}" for keys %violated; | |
24 | } else { | |
25 | pass("$filename contains no boilerplate text"); | |
26 | } | |
27 | } | |
28 | ||
29 | not_in_file_ok(README => | |
30 | "The README is used..." => qr/The README is used/, | |
31 | "'version information here'" => qr/to provide version information/, | |
32 | ); | |
33 | ||
34 | not_in_file_ok(Changes => | |
35 | "placeholder date/time" => qr(Date/time) | |
36 | ); | |
37 | ||
38 | sub module_boilerplate_ok { | |
39 | my ($module) = @_; | |
40 | not_in_file_ok($module => | |
41 | 'the great new $MODULENAME' => qr/ - The great new /, | |
42 | 'boilerplate description' => qr/Quick summary of what the module/, | |
43 | 'stub function definition' => qr/function[12]/, | |
44 | ); | |
45 | } | |
46 | ||
47 | module_boilerplate_ok('lib/HTML/WikiConverter/Kwiki.pm'); |
0 | local $/; | |
1 | require 't/runtests.pl'; | |
2 | runtests( data => <DATA>, dialect => 'Kwiki', wiki_uri => 'http://www.test.com?' ); | |
3 | close DATA; | |
4 | ||
5 | __DATA__ | |
6 | bold | |
7 | __H__ | |
8 | <html><b>bold</b></html> | |
9 | __W__ | |
10 | *bold* | |
11 | __NEXT__ | |
12 | italics | |
13 | __H__ | |
14 | <html><i>italics</i></html> | |
15 | __W__ | |
16 | /italics/ | |
17 | __NEXT__ | |
18 | bold and italics | |
19 | __H__ | |
20 | <html><b>bold</b> and <i>italics</i></html> | |
21 | __W__ | |
22 | *bold* and /italics/ | |
23 | __NEXT__ | |
24 | bold-italics nested | |
25 | __H__ | |
26 | <html><i><b>bold-italics</b> nested</i></html> | |
27 | __W__ | |
28 | /*bold-italics* nested/ | |
29 | __NEXT__ | |
30 | strong | |
31 | __H__ | |
32 | <html><strong>strong</strong></html> | |
33 | __W__ | |
34 | *strong* | |
35 | __NEXT__ | |
36 | emphasized | |
37 | __H__ | |
38 | <html><em>emphasized</em></html> | |
39 | __W__ | |
40 | /emphasized/ | |
41 | __NEXT__ | |
42 | underlined | |
43 | __H__ | |
44 | <html><u>text</u></html> | |
45 | __W__ | |
46 | _text_ | |
47 | __NEXT__ | |
48 | strikethrough | |
49 | __H__ | |
50 | <html><s>text</s></html> | |
51 | __W__ | |
52 | -text- | |
53 | __NEXT__ | |
54 | one-line phrasals | |
55 | __H__ | |
56 | <html><i>phrasals | |
57 | in one line</i></html> | |
58 | __W__ | |
59 | /phrasals in one line/ | |
60 | __NEXT__ | |
61 | paragraph blocking | |
62 | __H__ | |
63 | <html><p>p1</p><p>p2</p></html> | |
64 | __W__ | |
65 | p1 | |
66 | ||
67 | p2 | |
68 | __NEXT__ | |
69 | lists | |
70 | __H__ | |
71 | <html><ul><li>1</li><li>2</li></ul></html> | |
72 | __W__ | |
73 | * 1 | |
74 | * 2 | |
75 | __NEXT__ | |
76 | nested lists | |
77 | __H__ | |
78 | <html><ul><li>1<ul><li>1a</li><li>1b</li></ul></li><li>2</li></ul> | |
79 | __W__ | |
80 | * 1 | |
81 | ** 1a | |
82 | ** 1b | |
83 | * 2 | |
84 | __NEXT__ | |
85 | nested lists (different types) | |
86 | __H__ | |
87 | <html><ul><li>1<ul><li>a<ol><li>i</li></ol></li><li>b</li></ul></li><li>2</li></ul></html> | |
88 | __W__ | |
89 | * 1 | |
90 | ** a | |
91 | 000 i | |
92 | ** b | |
93 | * 2 | |
94 | __NEXT__ | |
95 | hr | |
96 | __H__ | |
97 | <html><hr /></html> | |
98 | __W__ | |
99 | ---- | |
100 | __NEXT__ | |
101 | br | |
102 | __H__ | |
103 | <html><p>stuff<br />stuff two</p></html> | |
104 | __W__ | |
105 | stuff | |
106 | stuff two | |
107 | __NEXT__ | |
108 | code | |
109 | __H__ | |
110 | <html><code>$name = 'stan';</code></html> | |
111 | __W__ | |
112 | [=$name = 'stan';] | |
113 | __NEXT__ | |
114 | tt | |
115 | __H__ | |
116 | <html><tt>tt text</tt></html> | |
117 | __W__ | |
118 | [=tt text] | |
119 | __NEXT__ | |
120 | pre | |
121 | __H__ | |
122 | <html><pre>this | |
123 | is | |
124 | preformatted | |
125 | text</pre></html> | |
126 | __W__ | |
127 | this | |
128 | is | |
129 | preformatted | |
130 | text | |
131 | __NEXT__ | |
132 | h1 | |
133 | __H__ | |
134 | <h1>h1</h1> | |
135 | __W__ | |
136 | = h1 | |
137 | __NEXT__ | |
138 | h2 | |
139 | __H__ | |
140 | <h2>h2</h2> | |
141 | __W__ | |
142 | == h2 | |
143 | __NEXT__ | |
144 | h3 | |
145 | __H__ | |
146 | <h3>h3</h3> | |
147 | __W__ | |
148 | === h3 | |
149 | __NEXT__ | |
150 | h4 | |
151 | __H__ | |
152 | <h4>h4</h4> | |
153 | __W__ | |
154 | ==== h4 | |
155 | __NEXT__ | |
156 | h5 | |
157 | __H__ | |
158 | <h5>h5</h5> | |
159 | __W__ | |
160 | ===== h5 | |
161 | __NEXT__ | |
162 | h6 | |
163 | __H__ | |
164 | <h6>h6</h6> | |
165 | __W__ | |
166 | ====== h6 | |
167 | __NEXT__ | |
168 | img | |
169 | __H__ | |
170 | <html><img src="thing.gif" /></html> | |
171 | __W__ | |
172 | http://www.test.com/thing.gif | |
173 | __NEXT__ | |
174 | internal links (camel-case) | |
175 | __H__ | |
176 | <html><a href="?FunTimes">FunTimes</a></html> | |
177 | __W__ | |
178 | FunTimes | |
179 | __NEXT__ | |
180 | forced internal links (no camel-case) | |
181 | __H__ | |
182 | <html><a href="?funTimes">funTimes</a></html> | |
183 | __W__ | |
184 | [funTimes] | |
185 | __NEXT__ | |
186 | internal links (camel-case w/ diff. text) | |
187 | __H__ | |
188 | <html><a href="?FunTimes">click here</a></html> | |
189 | __W__ | |
190 | [click here http:?FunTimes] | |
191 | __NEXT__ | |
192 | external links | |
193 | __H__ | |
194 | <html><a href="test.html">thing</a></html> | |
195 | __W__ | |
196 | [thing http://www.test.com/test.html] | |
197 | __NEXT__ | |
198 | external link (plain) | |
199 | __H__ | |
200 | <html><a href="http://www.test.com">http://www.test.com</a></html> | |
201 | __W__ | |
202 | http://www.test.com | |
203 | __NEXT__ | |
204 | simple tables | |
205 | __H__ | |
206 | <html><table> | |
207 | <tr><td> </td><td>Dick</td><td>Jane</td></tr> | |
208 | <tr><td>height</td><td>72"</td><td>65"</td></tr> | |
209 | <tr><td>weigtht</td><td>130lbs</td><td>150lbs</td></tr> | |
210 | </table></html> | |
211 | __W__ | |
212 | | | Dick | Jane | | |
213 | | height | 72" | 65" | | |
214 | | weigtht | 130lbs | 150lbs | | |
215 | __NEXT__ | |
216 | table w/ caption | |
217 | __H__ | |
218 | <html><table> | |
219 | <caption>Caption</caption> | |
220 | <tr><td> </td><td>Dick</td><td>Jane</td></tr> | |
221 | <tr><td>height</td><td>72"</td><td>65"</td></tr> | |
222 | <tr><td>weigtht</td><td>130lbs</td><td>150lbs</td></tr> | |
223 | </table></html> | |
224 | __W__ | |
225 | Caption | |
226 | ||
227 | | | Dick | Jane | | |
228 | | height | 72" | 65" | | |
229 | | weigtht | 130lbs | 150lbs | |
0 | #!perl -T | |
1 | ||
2 | use Test::More; | |
3 | eval "use Test::Pod::Coverage 1.04"; | |
4 | plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; | |
5 | all_pod_coverage_ok( { also_private => [ | |
6 | # These methods are documented in HTML::WikiConverter::Dialects | |
7 | qr/ | |
8 | get_elem_contents | |
9 | |get_wiki_page | |
10 | |get_attr_str | |
11 | |elem_within_block | |
12 | |is_camel_case | |
13 | |rule | |
14 | |rules | |
15 | |attribute | |
16 | |attributes | |
17 | |preprocess_tree | |
18 | |preprocess_node | |
19 | |postprocess_output | |
20 | |caption2para | |
21 | |strip_aname | |
22 | |base_url | |
23 | |wiki_url | |
24 | /x | |
25 | ] } ); |
0 | #!perl -T | |
1 | ||
2 | use Test::More; | |
3 | eval "use Test::Pod 1.14"; | |
4 | plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; | |
5 | all_pod_files_ok(); |
0 | #!/usr/bin/perl | |
1 | use warnings; | |
2 | use strict; | |
3 | ||
4 | use Test::More; | |
5 | use File::Spec; | |
6 | use HTML::Entities; | |
7 | use HTML::WikiConverter; | |
8 | *e = \&encode_entities; | |
9 | ||
10 | my $more_tests = <<END_TESTS; | |
11 | __NEXT__ | |
12 | entities (1) | |
13 | __H__ | |
14 | To enter a '<' in your input, use "&lt;" | |
15 | __W__ | |
16 | To enter a '<' in your input, use "&lt;" | |
17 | __NEXT__ | |
18 | entities (2) | |
19 | __H__ | |
20 | To enter a '<' in your input, use "&lt;" | |
21 | __W__ | |
22 | To enter a '<' in your input, use "&lt;" | |
23 | __NEXT__ | |
24 | strip comments | |
25 | __H__ | |
26 | A <!-- stripped --> comment | |
27 | __W__ | |
28 | A comment | |
29 | __NEXT__ | |
30 | strip head | |
31 | __H__ | |
32 | <html> | |
33 | <head><title>fun stuff</title></head> | |
34 | <body> | |
35 | <p>Crazy stuff here</p> | |
36 | </body> | |
37 | </html> | |
38 | __W__ | |
39 | Crazy stuff here | |
40 | __NEXT__ | |
41 | strip scripts | |
42 | __H__ | |
43 | <html> | |
44 | <head><script>bogus stuff</script></head> | |
45 | <body> | |
46 | <script>maliciousCode()</script> | |
47 | <p>benevolent text</p> | |
48 | </body> | |
49 | </html> | |
50 | __W__ | |
51 | benevolent text | |
52 | END_TESTS | |
53 | ||
54 | sub runtests { | |
55 | my %arg = @_; | |
56 | ||
57 | $arg{wrap_in_html} = 1; | |
58 | $arg{base_uri} ||= 'http://www.test.com'; | |
59 | my $minimal = $arg{minimal} || 0; | |
60 | ||
61 | my $data = $arg{data} || ''; | |
62 | $data .= entity_tests() . $more_tests unless $minimal; | |
63 | ||
64 | my @tests = split /__NEXT__\n/, $data; | |
65 | my $numtests = @tests; | |
66 | #$numtests += 1 unless $minimal; # file test | |
67 | plan tests => $numtests; | |
68 | ||
69 | # Delete unrecognized HTML::WikiConverter options | |
70 | delete $arg{$_} for qw/ data minimal /; | |
71 | ||
72 | my $wc = new HTML::WikiConverter(%arg); | |
73 | foreach my $test ( @tests ) { | |
74 | $test =~ s/^(.*?)\n//; my $name = $1; | |
75 | my( $html, $wiki ) = split /__W__\n/, $test; | |
76 | $html =~ s/__H__\n//; | |
77 | ||
78 | $name =~ s{\s*\:\:(\w+\([^\)]*?\))}{ | |
79 | my $method_call = $1; | |
80 | eval "\$wc->$method_call;"; | |
81 | die "Failed test call ($name): $@" if $@; | |
82 | ''; | |
83 | }ge; | |
84 | ||
85 | for( $html, $wiki ) { s/^\n+//; s/\n+$// } | |
86 | is( $wc->html2wiki($html), $wiki, $name ); | |
87 | } | |
88 | ||
89 | #file_test($wc) unless $minimal; | |
90 | } | |
91 | ||
92 | sub entity_tests { | |
93 | my $tmpl = "__NEXT__\n%s\n__H__\n%s\n__W__\n%s\n"; # test-name, html-input, expected-wiki-output | |
94 | ||
95 | my $data = ''; | |
96 | my @chars = ( '<', '>', '&' ); | |
97 | foreach my $char ( @chars ) { | |
98 | ( my $charname = e($char) ) =~ s/[&;]//g; | |
99 | $data .= sprintf $tmpl, "literal ($charname)", $char, e($char) | |
100 | . sprintf $tmpl, "encode ($charname)", e($char), e($char) | |
101 | . sprintf $tmpl, "meta ($charname)", e(e($char)), e(e($char)); | |
102 | } | |
103 | ||
104 | return $data; | |
105 | } | |
106 | ||
107 | sub _slurp { | |
108 | my $path = shift; | |
109 | open H, $path or die "couldn't open $path: $!"; | |
110 | local $/; | |
111 | my $c = <H>; | |
112 | close H; | |
113 | return $c; | |
114 | } | |
115 | ||
116 | sub file_test { | |
117 | my $wc = shift; | |
118 | my $lc_dialect = lc $wc->dialect; | |
119 | my $infile = File::Spec->catfile( 't', 'complete.html' ); | |
120 | my $outfile = File::Spec->catfile( 't', "complete.$lc_dialect" ); | |
121 | ||
122 | SKIP: { | |
123 | skip "Couldn't find $infile (ignore this)", 1 unless -e $infile; | |
124 | skip "Couldn't find $outfile (ignore this)", 1 unless -e $outfile; | |
125 | my( $got, $expect ) = ( $wc->html2wiki( file => $infile, slurp => 1 ), _slurp($outfile) ); | |
126 | for( $got, $expect ) { s/^\n+//; s/\n+$// } | |
127 | is( $got, $expect, 'read from file' ); | |
128 | }; | |
129 | } | |
130 | ||
131 | 1; |