blib/lib/App/Asciio/Markup.pm

filter: Statementstmt 35.4% 33 / 93 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 42.1% 8 / 19 Podpod 0.0% 0 / 6 totaltotal 27.7% 41 / 148 CC 16 SCAR 30.4
CC
16
Cov
28%
get_markup_coordinates
56.0
get_markup_characters_array
42.0
use_markup
6.0
CRAP 20.9
« blib/lib/App/Asciio/stripes/exec_box.pm ↑ Summary blib/lib/App/Asciio/stripes/triangle_up.pm »
1  
2 package App::Asciio::Markup ;
3  
4 4 require Exporter ;
5 4 @ISA = qw(Exporter) ;
6 4 @EXPORT = qw(
7 $USE_MARKUP_CLASS
8 ) ;
9  
10 4 $|++ ;
11  
12 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 ▶use App::Asciio::String ;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 4 our ($USE_MARKUP_CLASS) ;
20 4 $USE_MARKUP_CLASS = App::Asciio::Markup->new() ;
21  
22 #-----------------------------------------------------------------------------
23  
24 4 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
25 4 my $class = shift ;
26 4 my $self = {} ;
27 4 bless $self, $class ;
28 4 return $self ;
29 }
30  
31 #-----------------------------------------------------------------------------
32  
33 sub use_markup
34 0 ▶{
Subroutine use_markup: not called CC=2 SCAR=17.9
Pod undocumented
35 0 my ($use_it) = @_ ;
36  
37 0 ▶if($use_it eq 'zimwiki')
Branch: 1 branch
BranchTrueFalseTotal
if ($use_it eq 'zimwiki') { } 0 0 0
38 {
39 0 $USE_MARKUP_CLASS = App::Asciio::Zimwiki->new() ;
40 }
41 else
42 {
43 0 $USE_MARKUP_CLASS = App::Asciio::Markup->new() ;
44 }
45 }
46  
47 #-----------------------------------------------------------------------------
48  
49 1169 ▶sub delete_markup_characters { my ($self, $string) = @_ ; return $string ; }
Subroutine delete_markup_characters: called CC=1 SCAR=0.0
Pod undocumented
50  
51 #-----------------------------------------------------------------------------
52  
53 0 ▶sub get_markup_coordinates { ; }
Subroutine get_markup_coordinates: not called CC=1 SCAR=0.0
Pod undocumented
54  
55 #-----------------------------------------------------------------------------
56  
57 sub get_markup_characters_array
58 0 ▶{
Subroutine get_markup_characters_array: not called CC=1 SCAR=6.9
Pod undocumented
59 0 my ($self, $markup_coordinate, @lines) = @_ ;
60  
61 0 return (@lines) ;
62 }
63  
64 #-----------------------------------------------------------------------------
65  
66 sub ui_show_markup_characters
67 0 ▶{
Subroutine ui_show_markup_characters: not called CC=1 SCAR=6.9
Pod undocumented
68 0 my ($self, $layout, $font_size, $line) = @_ ;
69  
70 0 $layout->set_text($line) ;
71 }
72  
73 #-----------------------------------------------------------------------------
74 #-----------------------------------------------------------------------------
75  
76 package App::Asciio::Zimwiki ;
77 4 ▶use base qw/App::Asciio::Markup/ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
78  
79 4 ▶use Memoize ;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 4 memoize('convert_markup_string') ;
81 4 memoize('del_markup_characters') ;
82  
83 #-----------------------------------------------------------------------------
84  
85 sub is_markup_string
86 0 ▶{
Subroutine is_markup_string: not called CC=2 SCAR=17.9
87 0 my ($string) = @_;
88  
89 0 ▶return ( $string =~ /(<[bius]>)+([^<]+)(<\/[bius]>)+/
Condition0%0/3
$string =~ m[(<[bius]>)+([^<]+)(</[bius]>)+] || $string =~ m[<span link="[^<]+">([^<]+)</span>]
l!l&&r!l&&!r
000
MC/DC0%0/2
$string =~ m[(<[bius]>)+([^<]+)(</[bius]>)+] || $string =~ m[<span link="[^<]+">([^<]+)</span>]
$string =~ m[(<[bius]>)+([^<]+)(</[bius]>)+] $string =~ m[<span link="[^<]+">([^<]+)</span>]
Truth table0%0/3
A || B
A= $string =~ m[(<[bius]>)+([^<]+)(</[bius]>)+]B= $string =~ m[<span link="[^<]+">([^<]+)</span>]
ABresult
1X1
011
000
90 || $string =~ /<span link="[^<]+">([^<]+)<\/span>/) ;
91 }
92  
93 #-----------------------------------------------------------------------------
94  
95 sub del_markup_characters
96 0 ▶{
Subroutine del_markup_characters: not called CC=1 SCAR=6.9
97 0 my ($string) = @_;
98  
99 0 $string =~ s/<span link="[^<]+">|<\/span>|<\/?[bius]>//g ;
100  
101 0 return $string;
102 }
103  
104 #-----------------------------------------------------------------------------
105  
106 sub delete_markup_characters
107 0 ▶{
Subroutine delete_markup_characters: not called CC=1 SCAR=6.9
108 0 my ($self, $string) = @_;
109  
110 0 return del_markup_characters($string);
111 }
112  
113 #-----------------------------------------------------------------------------
114 sub get_markup_coordinates
115 0 ▶{
Subroutine get_markup_coordinates: not called CC=7 SCAR=40.3
116 0 my ($self, $element_x, $strip_line, $strip_x, $y) = @_ ;
117  
118 0 my %markup_coordinate ;
119  
120 0 ▶if(is_markup_string($strip_line))
Branch: 1 branch
BranchTrueFalseTotal
if (is_markup_string($strip_line)) 0 0 0
121 {
122 0 my $ori_x = 0;
123 0 ▶ while($strip_line =~ /(<\/?[bius]>)+|<\/span>|<span link="[^<]+">/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($strip_line =~ m[(</?[bius]>)+|</span>|<span link="[^<]+">]g) 0 0 0
124 {
125 0 my $sub_str = substr($strip_line, 0, pos($strip_line));
126 0 $ori_x = $element_x + $strip_x + App::Asciio::String::unicode_length($sub_str) ;
127 0 my $fit_str = $&;
128 0 $fit_str =~ s/<\/?b>/\*\*/g;
129 0 $fit_str =~ s/<\/?u>/__/g;
130 0 $fit_str =~ s/<\/?i>/\/\//g;
131 0 $fit_str =~ s/<\/?s>/~~/g;
132 # link [[link|link description]]
133 0 ▶ if($fit_str =~ /<span link="[^<]+">/)
Branch: 1 branch
BranchTrueFalseTotal
if ($fit_str =~ /<span link="[^<]+">/) 0 0 0
134 {
135 0 $fit_str =~ s/<span link="([^<]+)">/$1/g;
136 0 $fit_str = '[[' . $fit_str . '|';
137 }
138 0 ▶ if($fit_str =~ /<\/span>/)
Branch: 1 branch
BranchTrueFalseTotal
if ($fit_str =~ m[</span>]) 0 0 0
139 {
140 0 $fit_str = ']]';
141 }
142 0 ▶ $markup_coordinate{$y . '-' . $ori_x} = $fit_str if($ori_x >= 0 && $y >=0);
Branch: 1 branch
BranchTrueFalseTotal
if $ori_x >= 0 and $y >= 0 0 0 0
Condition0%0/3
$ori_x >= 0 and $y >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$ori_x >= 0 and $y >= 0
$ori_x >= 0 $y >= 0
Truth table0%0/3
A and B
A= $ori_x >= 0B= $y >= 0
ABresult
0X0
100
111
143 }
144 }
145  
146 0 return %markup_coordinate ;
147  
148 }
149  
150 #-----------------------------------------------------------------------------
151 sub get_markup_characters_array
152 0 ▶{
Subroutine get_markup_characters_array: not called CC=6 SCAR=37.4
153 0 my ($self, $markup_coordinate, @lines) = @_ ;
154 0 my (@new_lines, $new_col) ;
155  
156 0 for my $row (0 .. $#lines)
157 {
158 0 $new_col = 0;
159 0 for my $col (0 .. ($#{$lines[$row]} + 2))
160 {
161 0 ▶ if(exists($markup_coordinate->{$row . '-' . $col}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$markup_coordinate{$row . '-' . $col}) 0 0 0
162 {
163 0 for my $single_char (split '', $markup_coordinate->{$row . '-' . $col})
164 {
165 0 $new_lines[$row][$new_col] = [$single_char];
166 # single char
167 0 $new_col += App::Asciio::String::unicode_length($single_char);
168 }
169 }
170 0 ▶ $new_lines[$row][$new_col] = $lines[$row][$col] if(defined($lines[$row][$col]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $lines[$row][$col] 0 0 0
171 0 $new_col += 1;
172 }
173 }
174 0 return(@new_lines);
175 }
176  
177 #-----------------------------------------------------------------------------
178 #~ link fomart: <span link="">something</span>
179 #~ convert to: <span underline="double">something</span>
180 #~ bold fomart: <b>something</b>
181 #~ convert to: <span font_desc="$font_size - 1" weight="bold">something</span>
182 #~ the above just for display,not really change
183 # :TODO: At present, some font sizes cannot be aligned even if they are reduced by 1. The specific rules have not yet been clarified. Currently, we only solve the problem under certain font sizes.
184 sub convert_markup_string
185 0 ▶{
Subroutine convert_markup_string: not called CC=2 SCAR=17.9
186 0 my ($font_size, $string) = @_ ;
187  
188 0 my $use_markup_formart = 0 ;
189  
190 0 ▶if(is_markup_string($string))
Branch: 1 branch
BranchTrueFalseTotal
if (is_markup_string($string)) 0 0 0
191 {
192 0 $use_markup_formart = 1 ;
193 0 $string =~ s/<span link="[^<]+">([^<]+)<\/span>/<span underline="double">$1<\/span>/g;
194 # convert bold fonts to precise size control
195 0 $font_size -= 1 ;
196 0 $string =~ s/(<b>)((<[ius]>)*)([^<]+)((<\/[ius]>)*)(<\/b>)/<span font_desc="$font_size" weight="bold">$2$4$5<\/span>/g ;
197 }
198  
199 0 return ($use_markup_formart, $string) ;
200 }
201  
202 #-----------------------------------------------------------------------------
203  
204 sub ui_show_markup_characters
205 0 ▶{
Subroutine ui_show_markup_characters: not called CC=2 SCAR=17.9
206 0 my ($self, $layout, $font_size, $line) = @_ ;
207  
208 0 my ($use_mark_up, $markup_line) = convert_markup_string($font_size, $line) ;
209  
210 0 ▶if($use_mark_up)
Branch: 1 branch
BranchTrueFalseTotal
if ($use_mark_up) { } 0 0 0
211 {
212 0 $layout->set_markup($markup_line) ;
213 }
214 else
215 {
216 0 $layout->set_text($line) ;
217 }
218 }
219  
220  
221 #-----------------------------------------------------------------------------
222  
223 4 1 ;
224  
« blib/lib/App/Asciio/stripes/exec_box.pm ↑ Summary blib/lib/App/Asciio/stripes/triangle_up.pm »