File Coverage

blib/lib/HTML/WikiConverter/Confluence.pm
Criterion Covered Total %
statement 15 38 39.4
branch 0 16 0.0
condition 0 3 0.0
subroutine 5 9 55.5
pod 0 1 0.0
total 20 67 29.8


line stmt bran cond sub pod time code
1             package HTML::WikiConverter::Confluence;
2 1     1   34705 use base 'HTML::WikiConverter';
  1         3  
  1         555  
3              
4 1     1   6 use warnings;
  1         3  
  1         27  
5 1     1   4 use strict;
  1         6  
  1         36  
6              
7 1     1   3863 use URI;
  1         17537  
  1         44  
8 1     1   17 use File::Basename;
  1         2  
  1         1358  
9             our $VERSION = '0.01';
10              
11             =head1 NAME
12              
13             HTML::WikiConverter::Confluence - Convert HTML to Confluence markup
14              
15             =head1 SYNOPSIS
16              
17             use HTML::WikiConverter;
18             my $wc = new HTML::WikiConverter( dialect => 'Confluence' );
19             print $wc->html2wiki( $html );
20              
21             =head1 DESCRIPTION
22              
23             This module contains rules for converting HTML into Confluence
24             markup. See L for additional usage details.
25             More information about Confluence itself can be found at
26             L.
27              
28             =cut
29              
30             sub rules {
31 0     0 0   my $self = shift;
32              
33 0           my %rules = (
34             # Headings
35             h1 => { start => 'h1. ', line_format => 'single', trim => 'both', block => 1 },
36             h2 => { start => 'h2. ', line_format => 'single', trim => 'both', block => 1 },
37             h3 => { start => 'h3. ', line_format => 'single', trim => 'both', block => 1 },
38             h4 => { start => 'h4. ', line_format => 'single', trim => 'both', block => 1 },
39             h5 => { start => 'h5. ', line_format => 'single', trim => 'both', block => 1 },
40             h6 => { start => 'h6. ', line_format => 'single', trim => 'both', block => 1 },
41            
42             # Text effects: http://confluence.atlassian.com/display/CONF20/Working+with+Text+Effects
43             strong => { start => '*', end => '*', line_format => 'single' },
44             em => { start => '_', end => '_', line_format => 'single' },
45             i => { alias => 'em' },
46             b => { alias => 'strong' },
47             cite => { start => '??', end => '??', line_format => 'single' },
48             del => { start => '-', end => '-', line_format => 'single' },
49             ins => { start => '+', end => '+', line_format => 'single' },
50             sup => { start => '^', end => '^', line_format => 'single' },
51             sub => { start => '~', end => '~', line_format => 'single' },
52             tt => { start => '{{', end => '}}', line_format => 'single' },
53             blockquote => { start => 'bq. ', line_format => 'single', block => 1 },
54             # missing font color
55              
56             # Text breaks: http://confluence.atlassian.com/display/CONF20/Working+with+Text+Breaks
57             br => { replace => "\\\\" },
58             hr => { replace => "\n\n----\n\n" },
59              
60             # Linking to web pages: http://confluence.atlassian.com/display/CONF20/Linking+to+Web+Pages
61             a => { replace => \&_link },
62              
63             p => { block => 1, trim => 'both', line_format => 'single' },
64              
65             # Working with images: http://confluence.atlassian.com/display/CONF20/Displaying+an+Image
66             img => { replace => \&_image },
67              
68             # Working with lists: http://confluence.atlassian.com/display/CONF20/Working+with+Lists
69             ul => { line_format => 'multi', block => 1 },
70             ol => { alias => 'ul' },
71             dl => { alias => 'ul' },
72              
73             li => { start => \&_li_start, trim => 'leading' },
74             dt => { alias => 'li' },
75             dd => { alias => 'li' },
76              
77             # Working with tables: http://confluence.atlassian.com/display/CONF20/Working+with+Tables
78             # TODO
79             );
80              
81 0           return \%rules;
82             }
83              
84             # Calculates the prefix that will be placed before each list item.
85             # Handles ordered, unordered, and definition list items.
86             sub _li_start {
87 0     0     my( $self, $node, $rules ) = @_;
88 0           my @parent_lists = $node->look_up( _tag => qr/ul|ol|dl/ );
89              
90 0           my $prefix = '';
91 0           foreach my $parent ( @parent_lists ) {
92 0           my $bullet = '';
93 0 0         $bullet = '*' if $parent->tag eq 'ul';
94 0 0         $bullet = '#' if $parent->tag eq 'ol';
95 0 0         $bullet = ':' if $parent->tag eq 'dl';
96 0 0 0       $bullet = ';' if $parent->tag eq 'dl' and $node->tag eq 'dt';
97 0           $prefix = $bullet.$prefix;
98             }
99              
100 0           return "\n$prefix ";
101             }
102              
103             sub _link {
104 0     0     my( $self, $node, $rules ) = @_;
105 0 0         my $url = defined $node->attr('href') ? $node->attr('href') : '';
106 0           my $text = $self->get_elem_contents($node);
107              
108             # Handle internal links
109 0 0         if( my $title = $self->get_wiki_page( $url ) ) {
110             # Need to update for Confluence...
111             }
112              
113             # Treat them as external links
114 0 0         return "[$url]" if $url eq $text;
115 0           return "[$text|$url]";
116             }
117              
118             sub _image {
119 0     0     my( $self, $node, $rules ) = @_;
120 0 0         return '' unless $node->attr('src');
121 0           return $node->attr('src');
122             }
123              
124             =head1 AUTHOR
125              
126             David J. Iberri, C<< >>
127              
128             =head1 BUGS
129              
130             Please report any bugs or feature requests to
131             C, or through the web
132             interface at
133             L.
134             I will be notified, and then you'll automatically be notified of
135             progress on your bug as I make changes.
136              
137             =head1 SUPPORT
138              
139             You can find documentation for this module with the perldoc command.
140              
141             perldoc HTML::WikiConverter::Confluence
142              
143             You can also look for information at:
144              
145             =over 4
146              
147             =item * AnnoCPAN: Annotated CPAN documentation
148              
149             L
150              
151             =item * CPAN Ratings
152              
153             L
154              
155             =item * RT: CPAN's request tracker
156              
157             L
158              
159             =item * Search CPAN
160              
161             L
162              
163             =back
164              
165             =head1 COPYRIGHT & LICENSE
166              
167             Copyright 2006 David J. Iberri, all rights reserved.
168              
169             This program is free software; you can redistribute it and/or modify
170             it under the same terms as Perl itself.
171              
172             =cut
173              
174             1;
175              
176             __END__