line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pod::Simple::Wiki::Markdown; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Pod::Simple::Wiki::Markdown - A class for creating Pod to Markdown filters. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Copyright 2003-2014, John McNamara, jmcnamara@cpan.org, Daniel T. Staal, |
9
|
|
|
|
|
|
|
# DStaal@usa.net |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Documentation after __END__ |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# perltidy with the following options: -mbl=2 -pt=0 -nola |
15
|
|
|
|
|
|
|
|
16
|
5
|
|
|
5
|
|
28
|
use Pod::Simple::Wiki; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
176
|
|
17
|
5
|
|
|
5
|
|
27
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
143
|
|
18
|
5
|
|
|
5
|
|
26
|
use vars qw(@ISA $VERSION); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
4147
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
@ISA = qw(Pod::Simple::Wiki); |
22
|
|
|
|
|
|
|
$VERSION = '0.19'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
############################################################################### |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# The tag to wiki mappings. |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
my $tags = { |
29
|
|
|
|
|
|
|
'' => '**', |
30
|
|
|
|
|
|
|
'' => '**', |
31
|
|
|
|
|
|
|
'' => '_', |
32
|
|
|
|
|
|
|
'' => '_', |
33
|
|
|
|
|
|
|
'' => '`', |
34
|
|
|
|
|
|
|
'' => '`', |
35
|
|
|
|
|
|
|
'' => "\n```\n", |
36
|
|
|
|
|
|
|
'' => "\n```\n", |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
'' => '# ', |
39
|
|
|
|
|
|
|
'' => "\n\n", |
40
|
|
|
|
|
|
|
'' => '## ', |
41
|
|
|
|
|
|
|
'' => "\n\n", |
42
|
|
|
|
|
|
|
'' => '### ', |
43
|
|
|
|
|
|
|
'' => "\n\n", |
44
|
|
|
|
|
|
|
'' => '#### ', |
45
|
|
|
|
|
|
|
'' => "\n\n", |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
############################################################################### |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# new() |
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
# Simple constructor inheriting from Pod::Simple::Wiki. |
53
|
|
|
|
|
|
|
# |
54
|
|
|
|
|
|
|
sub new { |
55
|
|
|
|
|
|
|
|
56
|
30
|
|
|
30
|
1
|
51
|
my $class = shift; |
57
|
30
|
|
|
|
|
112
|
my $self = Pod::Simple::Wiki->new( 'wiki', @_ ); |
58
|
30
|
|
|
|
|
74
|
$self->{_tags} = $tags; |
59
|
|
|
|
|
|
|
|
60
|
30
|
|
|
|
|
46
|
bless $self, $class; |
61
|
30
|
|
|
|
|
92
|
return $self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
############################################################################### |
65
|
|
|
|
|
|
|
# |
66
|
|
|
|
|
|
|
# _indent_item() |
67
|
|
|
|
|
|
|
# |
68
|
|
|
|
|
|
|
# Indents an "over-item" to the correct level. |
69
|
|
|
|
|
|
|
# |
70
|
|
|
|
|
|
|
sub _indent_item { |
71
|
|
|
|
|
|
|
|
72
|
37
|
|
|
37
|
|
52
|
my $self = shift; |
73
|
37
|
|
|
|
|
45
|
my $item_type = $_[0]; |
74
|
37
|
|
|
|
|
44
|
my $item_param = $_[1]; |
75
|
37
|
|
|
|
|
57
|
my $indent_level = $self->{_item_indent} - 1; |
76
|
|
|
|
|
|
|
|
77
|
37
|
100
|
|
|
|
104
|
if ( $item_type eq 'bullet' ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
78
|
12
|
|
|
|
|
49
|
$self->_append( ' ' x $indent_level . '* ' ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
elsif ( $item_type eq 'number' ) { |
81
|
12
|
|
|
|
|
43
|
$self->_append( ' ' x $indent_level . '1 ' ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# In theory Markdown supports nested definition lists - but *everything* has to be indented. |
85
|
|
|
|
|
|
|
elsif ( $item_type eq 'text' ) { |
86
|
13
|
|
|
|
|
48
|
$self->_append( ' ' x $indent_level . '' ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
############################################################################### |
91
|
|
|
|
|
|
|
# |
92
|
|
|
|
|
|
|
# _start_L() |
93
|
|
|
|
|
|
|
# |
94
|
|
|
|
|
|
|
# Handle the start of a link element. |
95
|
|
|
|
|
|
|
# |
96
|
|
|
|
|
|
|
sub _start_L { |
97
|
|
|
|
|
|
|
|
98
|
4
|
|
|
4
|
|
7
|
my $self = shift; |
99
|
4
|
|
|
|
|
6
|
my $link_attrs = shift; |
100
|
|
|
|
|
|
|
|
101
|
4
|
|
|
|
|
7
|
$self->{_link_attrs} = $link_attrs; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Ouput start of Confluence link and flush the _wiki_text buffer. |
104
|
4
|
|
|
|
|
17
|
$self->_output( '[' ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
############################################################################### |
109
|
|
|
|
|
|
|
# |
110
|
|
|
|
|
|
|
# _end_L() |
111
|
|
|
|
|
|
|
# |
112
|
|
|
|
|
|
|
# Handle the end of a link element. |
113
|
|
|
|
|
|
|
# |
114
|
|
|
|
|
|
|
sub _end_L { |
115
|
|
|
|
|
|
|
|
116
|
4
|
|
|
4
|
|
8
|
my $self = shift; |
117
|
4
|
|
|
|
|
6
|
my $link_attrs = $self->{_link_attrs}; |
118
|
4
|
|
|
|
|
5
|
my $link_target = $link_attrs->{to}; |
119
|
4
|
|
|
|
|
7
|
my $link_section = $link_attrs->{section}; |
120
|
|
|
|
|
|
|
|
121
|
4
|
100
|
|
|
|
11
|
$link_target = '' if( !defined($link_target)); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Handle links that are parsed as Pod links. |
124
|
4
|
100
|
|
|
|
8
|
if ( defined $link_section ) { |
125
|
2
|
|
|
|
|
7
|
$link_target = "$link_target#$link_section"; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
4
|
|
|
|
|
58
|
$self->_append( "]($link_target)" ); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
############################################################################### |
132
|
|
|
|
|
|
|
# |
133
|
|
|
|
|
|
|
# _handle_text() |
134
|
|
|
|
|
|
|
# |
135
|
|
|
|
|
|
|
# Perform any necessary transforms on the text. This is mainly used to escape |
136
|
|
|
|
|
|
|
# inadvertent CamelCase words. |
137
|
|
|
|
|
|
|
# |
138
|
|
|
|
|
|
|
sub _handle_text { |
139
|
|
|
|
|
|
|
|
140
|
69
|
|
|
69
|
|
535
|
my $self = shift; |
141
|
69
|
|
|
|
|
99
|
my $text = $_[0]; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Only escape words in paragraphs |
144
|
69
|
100
|
|
|
|
161
|
if ( not $self->{_in_Para} ) { |
145
|
41
|
|
|
|
|
66
|
$self->{_wiki_text} .= $text; |
146
|
41
|
|
|
|
|
97
|
return; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# Split the text into tokens but maintain the whitespace |
150
|
28
|
|
|
|
|
160
|
my @tokens = split /(\s+)/, $text; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# Escape any tokens here, if necessary. |
153
|
|
|
|
|
|
|
# The following characters are escaped by prepending a backslash: \`*_ |
154
|
|
|
|
|
|
|
# (Markdown has other escapes as well, but these cover most cases, and the others |
155
|
|
|
|
|
|
|
# are usually optional.) |
156
|
28
|
|
|
|
|
51
|
@tokens = map { s/([\\`\*\_])/\\$1/g; $_ } @tokens; |
|
164
|
|
|
|
|
248
|
|
|
164
|
|
|
|
|
394
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# Rejoin the tokens and whitespace. |
159
|
28
|
|
|
|
|
153
|
$self->{_wiki_text} .= join '', @tokens; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
############################################################################### |
164
|
|
|
|
|
|
|
# |
165
|
|
|
|
|
|
|
# Functions to deal with =over ... =back regions for |
166
|
|
|
|
|
|
|
# |
167
|
|
|
|
|
|
|
# Bulleted lists |
168
|
|
|
|
|
|
|
# Numbered lists |
169
|
|
|
|
|
|
|
# Text lists |
170
|
|
|
|
|
|
|
# Block lists |
171
|
|
|
|
|
|
|
# |
172
|
|
|
|
|
|
|
sub _end_item_text { |
173
|
13
|
|
|
13
|
|
17
|
my $self = shift; |
174
|
13
|
|
|
|
|
21
|
my $indent_level = $self->{_item_indent} - 1; |
175
|
|
|
|
|
|
|
|
176
|
13
|
|
|
|
|
49
|
$self->_output( "\n" . ' ' x $indent_level . ': ' ); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
############################################################################### |
181
|
|
|
|
|
|
|
# |
182
|
|
|
|
|
|
|
# _start_Para() |
183
|
|
|
|
|
|
|
# |
184
|
|
|
|
|
|
|
# Special handling for paragraphs that are part of an "over" block. |
185
|
|
|
|
|
|
|
# |
186
|
|
|
|
|
|
|
sub _start_Para { |
187
|
|
|
|
|
|
|
|
188
|
27
|
|
|
27
|
|
88
|
my $self = shift; |
189
|
27
|
|
|
|
|
56
|
my $indent_level = $self->{_item_indent} - 1; |
190
|
|
|
|
|
|
|
|
191
|
27
|
100
|
|
|
|
109
|
if ( $self->{_in_over_block} ) { |
192
|
1
|
|
|
|
|
6
|
$self->_append( ' ' x $indent_level . '' ); |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
__END__ |