line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FreeMind::Convert ; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#use 5.008005 ; |
4
|
1
|
|
|
1
|
|
5
|
use strict ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
43
|
use Carp ; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
100
|
|
7
|
1
|
|
|
1
|
|
6
|
use base qw(Class::Accessor); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3784
|
|
8
|
1
|
|
|
1
|
|
3059
|
use XML::Simple ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Jcode ; |
10
|
|
|
|
|
|
|
use HTML::Entities ; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.03' ; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(_format setOutputJcode)); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
|
|
|
|
|
|
my $class = shift; |
18
|
|
|
|
|
|
|
my $self = bless {}, $class; |
19
|
|
|
|
|
|
|
$self->_init(@_); |
20
|
|
|
|
|
|
|
$self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _init { |
24
|
|
|
|
|
|
|
my $self = shift; |
25
|
|
|
|
|
|
|
$self->{depth} = 0 ; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub loadFile { |
29
|
|
|
|
|
|
|
my $self = shift ; |
30
|
|
|
|
|
|
|
my $file = shift ; |
31
|
|
|
|
|
|
|
$self->{mm} = XMLin($file, ForceArray => 1) ; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub toText { |
35
|
|
|
|
|
|
|
my $self = shift ; |
36
|
|
|
|
|
|
|
$self->_format('text') ; |
37
|
|
|
|
|
|
|
$self->_checkNode($self->{mm}) ; |
38
|
|
|
|
|
|
|
return $self->{result} ; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub toMediaWiki { |
42
|
|
|
|
|
|
|
my $self = shift ; |
43
|
|
|
|
|
|
|
$self->_format('mediawiki') ; |
44
|
|
|
|
|
|
|
$self->_checkNode($self->{mm}) ; |
45
|
|
|
|
|
|
|
return $self->{result} ; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _filterText { |
49
|
|
|
|
|
|
|
my $self = shift ; |
50
|
|
|
|
|
|
|
my $ref = shift ; |
51
|
|
|
|
|
|
|
my $text = $ref->{TEXT} ; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# to unicode |
54
|
|
|
|
|
|
|
decode_entities( $text ) ; |
55
|
|
|
|
|
|
|
$text =~ s|^(.*)$|$1|i ; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# set font tag |
58
|
|
|
|
|
|
|
my $color = $ref->{COLOR} || undef ; |
59
|
|
|
|
|
|
|
my $bgcolor = $ref->{BACKGROUND_COLOR} || undef ; |
60
|
|
|
|
|
|
|
my $size = '1em' ; |
61
|
|
|
|
|
|
|
my $bold ; |
62
|
|
|
|
|
|
|
my $italic ; |
63
|
|
|
|
|
|
|
if( defined( $ref->{font} ) ){ |
64
|
|
|
|
|
|
|
my $fontAttr = $ref->{font}[0] ; |
65
|
|
|
|
|
|
|
$size = ( int( $fontAttr->{SIZE} / 1.2 ) / 10 ). 'em' if( defined( $fontAttr->{SIZE} ) ) ; |
66
|
|
|
|
|
|
|
$bold = 1 if( defined( $fontAttr->{BOLD} ) && $fontAttr->{BOLD} eq 'true' ) ; |
67
|
|
|
|
|
|
|
$italic = 1 if( defined( $fontAttr->{ITALIC} ) && $fontAttr->{ITALIC} eq 'true' ) ; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
my $style ; |
70
|
|
|
|
|
|
|
$style .= "font-size: $size;" if( defined( $size ) ) ; |
71
|
|
|
|
|
|
|
$style .= "color: $color;" if( defined( $color ) ) ; |
72
|
|
|
|
|
|
|
$style .= "background: $bgcolor;" if( defined( $bgcolor ) ) ; |
73
|
|
|
|
|
|
|
$style .= "font-weight: bold;" if( defined( $bold ) ) ; |
74
|
|
|
|
|
|
|
$style .= "font-style: italic;" if( defined( $italic ) ) ; |
75
|
|
|
|
|
|
|
if( defined( $style ) ){ |
76
|
|
|
|
|
|
|
$text = "$text" ; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# to japanese |
80
|
|
|
|
|
|
|
if( $self->setOutputJcode() ){ |
81
|
|
|
|
|
|
|
Jcode::convert( \$text, $self->setOutputJcode, 'utf8' ) ; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
return $text ; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _checkNode { |
87
|
|
|
|
|
|
|
my $self = shift ; |
88
|
|
|
|
|
|
|
my $ref = shift ; |
89
|
|
|
|
|
|
|
return if( ! defined( $ref->{node} ) ) ; |
90
|
|
|
|
|
|
|
foreach my $refc (@{$ref->{node}}){ |
91
|
|
|
|
|
|
|
my $text = $self->_filterText( $refc ) ; |
92
|
|
|
|
|
|
|
# text |
93
|
|
|
|
|
|
|
if( $self->_format() eq 'text' ){ |
94
|
|
|
|
|
|
|
$self->{result} .= qq(\t) x $self->{depth} . "$text\n" ; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
# MediaWiki |
97
|
|
|
|
|
|
|
elsif( $self->_format() eq 'mediawiki' ){ |
98
|
|
|
|
|
|
|
if( $self->{depth} <= 1 ){ |
99
|
|
|
|
|
|
|
my $simbol = '=' x ( $self->{depth} + 2 ) ; |
100
|
|
|
|
|
|
|
$self->{result} .= "$simbol $text $simbol\n" ; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else{ |
103
|
|
|
|
|
|
|
my $simbol = '*' x ( $self->{depth} - 1 ) ; |
104
|
|
|
|
|
|
|
$self->{result} .= "$simbol $text\n" ; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$self->{depth} ++ ; |
109
|
|
|
|
|
|
|
$self->_checkNode( $refc ) ; |
110
|
|
|
|
|
|
|
$self->{depth} -- ; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1 ; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |