| 1 | #!/usr/local/bin/perl | ||||||||||||||||||||||||||||
| 2 | # Copyright 2022 Jeffrey Kegler | ||||||||||||||||||||||||||||
| 3 | # This file is part of Marpa::R2. Marpa::R2 is free software: you can | ||||||||||||||||||||||||||||
| 4 | # redistribute it and/or modify it under the terms of the GNU Lesser | ||||||||||||||||||||||||||||
| 5 | # General Public License as published by the Free Software Foundation, | ||||||||||||||||||||||||||||
| 6 | # either version 3 of the License, or (at your option) any later version. | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # Marpa::R2 is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||||||||||||||||||||||||||
| 11 | # Lesser General Public License for more details. | ||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||
| 13 | # You should have received a copy of the GNU Lesser | ||||||||||||||||||||||||||||
| 14 | # General Public License along with Marpa::R2. If not, see | ||||||||||||||||||||||||||||
| 15 | # http://www.gnu.org/licenses/. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 13 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 13 | ▶ | use English qw( -no_match_vars ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 13 | ▶ | use Marpa::R2::HTML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 13 | ▶ | use Fatal qw(open close); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 13 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub usage | ||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | say {*STDERR} "$PROGRAM_NAME html_fmt [uri|file]" or die "say failed: $ERRNO"; | ||||||||||||||||||||||||||
|
Subroutine
usage: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | exit 1; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 13 | my $help_flag = 0; | |||||||||||||||||||||||||||
| 32 | 13 | my $allowed_avoid_whitespace_flags = { map { ( $_, 1) } qw(comment yes no) }; | |||||||||||||||||||||||||||
| 33 | 13 | my $avoid_whitespace_flag = 'yes'; | |||||||||||||||||||||||||||
| 34 | 13 | local $main::ADDED_TAG_COMMENT_FLAG = 1; | |||||||||||||||||||||||||||
| 35 | 13 | my $ws_ok_before_end_tag_flag = 0; | |||||||||||||||||||||||||||
| 36 | 13 | my $ws_ok_after_start_tag_flag = 1; | |||||||||||||||||||||||||||
| 37 | 13 | my $dump_config_flag = 0; | |||||||||||||||||||||||||||
| 38 | 13 | my $dump_AHFA_flag = 0; | |||||||||||||||||||||||||||
| 39 | 13 | my $trace_terminals_flag = 0; | |||||||||||||||||||||||||||
| 40 | 13 | my $trace_cruft_flag = 0; | |||||||||||||||||||||||||||
| 41 | 13 | my $trace_values_flag = 0; | |||||||||||||||||||||||||||
| 42 | 13 | my $compile_flag; | |||||||||||||||||||||||||||
| 43 | 13 | ▶ | usage() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | if not Getopt::Long::GetOptions( | ||||||||||||||||||||||||||||
| 45 | 'help' => \$help_flag, | ||||||||||||||||||||||||||||
| 46 | 'avoid-whitespace=s' => \$avoid_whitespace_flag, | ||||||||||||||||||||||||||||
| 47 | 'ws-ok-before-end-tag!' => \$ws_ok_before_end_tag_flag, | ||||||||||||||||||||||||||||
| 48 | 'ws-ok-after-start-tag!' => \$ws_ok_after_start_tag_flag, | ||||||||||||||||||||||||||||
| 49 | 'added-tag-comment!' => \$main::ADDED_TAG_COMMENT_FLAG, | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # undocumented | ||||||||||||||||||||||||||||
| 52 | 'dump-config' => \$dump_config_flag, | ||||||||||||||||||||||||||||
| 53 | 'dump-AHFA' => \$dump_AHFA_flag, | ||||||||||||||||||||||||||||
| 54 | 'compile=s' => \$compile_flag, | ||||||||||||||||||||||||||||
| 55 | 'trace-terminals' => \$trace_terminals_flag, | ||||||||||||||||||||||||||||
| 56 | 'trace-cruft' => \$trace_cruft_flag, | ||||||||||||||||||||||||||||
| 57 | 'trace-values' => \$trace_values_flag, | ||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||
| 59 | 13 | ▶ | usage() if $help_flag or scalar @ARGV > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$help_flag or scalar @ARGV > 1
MC/DC0%0/2
$help_flag or scalar @ARGV > 1
$help_flag
scalar @ARGV > 1
Truth table33%1/3
A or B
A= $help_flagB= scalar @ARGV > 1
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 13 | ▶ | if ( not $allowed_avoid_whitespace_flags->{$avoid_whitespace_flag} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | die "Bad avoid-whitespace flag\n", | ||||||||||||||||||||||||||||
| 63 | 'avoid-whitespace must be one of the following: ', join q{ }, | ||||||||||||||||||||||||||||
| 64 | 0 | keys %{$allowed_avoid_whitespace_flags}; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 13 | my $locator = shift; | |||||||||||||||||||||||||||
| 68 | 13 | my $document; | |||||||||||||||||||||||||||
| 69 | GET_DOCUMENT: { | ||||||||||||||||||||||||||||
| 70 | 13 | ▶ | if ( not defined $locator ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | local $RS = undef; | |||||||||||||||||||||||||||
| 72 | ## no critic(InputOutput::ProhibitExplicitStdin) | ||||||||||||||||||||||||||||
| 73 | 0 | $document = <STDIN>; | |||||||||||||||||||||||||||
| 74 | 0 | last GET_DOCUMENT; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 13 | ▶ | if ( $locator =~ /\A [[:alnum:]]+ [:] /xms ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | require WWW::Mechanize; | |||||||||||||||||||||||||||
| 78 | 0 | my $mech = WWW::Mechanize->new( autocheck => 1 ); | |||||||||||||||||||||||||||
| 79 | 0 | $mech->get($locator); | |||||||||||||||||||||||||||
| 80 | 0 | $document = $mech->content; | |||||||||||||||||||||||||||
| 81 | 0 | undef $mech; | |||||||||||||||||||||||||||
| 82 | 0 | last GET_DOCUMENT; | |||||||||||||||||||||||||||
| 83 | } ## end if ( $locator =~ /\A [[:alnum:]]+ [:] /xms ) | ||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||
| 85 | 13 | local $RS = undef; | |||||||||||||||||||||||||||
| 86 | 13 | open my $fh, q{<}, $locator; | |||||||||||||||||||||||||||
| 87 | 13 | $document = <$fh>; | |||||||||||||||||||||||||||
| 88 | 13 | close $fh; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } ## end GET_DOCUMENT: | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub post_process { | ||||||||||||||||||||||||||||
| 93 | 13 | ▶ | my ($value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
post_process: called CC=56 SCAR=45.4
| |||||||||||||||||||||||||||||
| 94 | 13 | my @text_pieces = (); | |||||||||||||||||||||||||||
| 95 | 13 | DATUM: for my $line_data ( map { @{$_} } @{$value} ) { | |||||||||||||||||||||||||||
| 96 | 287 | my ( $type, $indent ) = @{$line_data}; | |||||||||||||||||||||||||||
| 97 | 287 | ▶ | if ( $type eq 'text' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 56 | my $text = $line_data->[2]; | |||||||||||||||||||||||||||
| 99 | 56 | my $has_trailing_ws = $text =~ s/ \s+ \z//xms; | |||||||||||||||||||||||||||
| 100 | 56 | ▶ | if ( $text =~ s/ \A \s+ //xms ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 2 | push @text_pieces, [ 'whitespace', $indent ]; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 56 | my @lines = grep { $_ =~ /\S/xms } split /\n/xms, $text; | |||||||||||||||||||||||||||
| 104 | 56 | for my $line_no ( 0 .. $#lines ) { | |||||||||||||||||||||||||||
| 105 | 41 | my $line = $lines[$line_no]; | |||||||||||||||||||||||||||
| 106 | 41 | $line =~ s/\A[ \t]+//xms; | |||||||||||||||||||||||||||
| 107 | 41 | $line =~ s/[ \t]+\z//xms; | |||||||||||||||||||||||||||
| 108 | 41 | $line =~ s/[ \t]+/ /xms; | |||||||||||||||||||||||||||
| 109 | 41 | ▶ | push @text_pieces, [ 'whitespace', $indent ] if $line_no; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 41 | push @text_pieces, [ 'text', $indent, $line ]; | |||||||||||||||||||||||||||
| 111 | } ## end for my $line_no ( 0 .. $#lines ) | ||||||||||||||||||||||||||||
| 112 | 56 | ▶ | push @text_pieces, [ 'whitespace', $indent ] if $has_trailing_ws; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 56 | next DATUM; | |||||||||||||||||||||||||||
| 114 | } ## end if ( $type eq 'text' ) | ||||||||||||||||||||||||||||
| 115 | 231 | ▶ | if ( $type eq 'msg: missing start tag' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 14 | my $location = $line_data->[2]; | |||||||||||||||||||||||||||
| 117 | 14 | my $tagname = $line_data->[3]; | |||||||||||||||||||||||||||
| 118 | GIVEN_LOCATION: { | ||||||||||||||||||||||||||||
| 119 | 14 | ▶ | if ( $location eq 'preceeding' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 14 | push @text_pieces, | |||||||||||||||||||||||||||
| 121 | [ | ||||||||||||||||||||||||||||
| 122 | 'html_fmt comment', | ||||||||||||||||||||||||||||
| 123 | $indent + 1, | ||||||||||||||||||||||||||||
| 124 | 'Preceeding start tag is replacement for a missing one' | ||||||||||||||||||||||||||||
| 125 | ]; | ||||||||||||||||||||||||||||
| 126 | 14 | last GIVEN_LOCATION; | |||||||||||||||||||||||||||
| 127 | } ## end if ( $location eq 'preceeding' ) | ||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if ( $location eq 'following pre' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 0 | push @text_pieces, | |||||||||||||||||||||||||||
| 130 | [ | ||||||||||||||||||||||||||||
| 131 | 'html_fmt comment', | ||||||||||||||||||||||||||||
| 132 | $indent, | ||||||||||||||||||||||||||||
| 133 | "Inside following <pre>, a start tag is missing: <$tagname>" | ||||||||||||||||||||||||||||
| 134 | ]; | ||||||||||||||||||||||||||||
| 135 | 0 | last GIVEN_LOCATION; | |||||||||||||||||||||||||||
| 136 | } ## end if ( $location eq 'following pre' ) | ||||||||||||||||||||||||||||
| 137 | Carp::croak( | ||||||||||||||||||||||||||||
| 138 | 0 | "Internal error: unprovided-for missing start tag location: $_" | |||||||||||||||||||||||||||
| 139 | ); | ||||||||||||||||||||||||||||
| 140 | } ## end GIVEN_LOCATION: | ||||||||||||||||||||||||||||
| 141 | 14 | next DATUM; | |||||||||||||||||||||||||||
| 142 | } ## end if ( $type eq 'msg: missing start tag' ) | ||||||||||||||||||||||||||||
| 143 | 217 | ▶ | if ( $type eq 'msg: missing end tag' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 21 | my $location = $line_data->[2]; | |||||||||||||||||||||||||||
| 145 | 21 | my $tagname = $line_data->[3]; | |||||||||||||||||||||||||||
| 146 | GIVEN_LOCATION: { | ||||||||||||||||||||||||||||
| 147 | 21 | ▶ | if ( $location eq 'following' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 21 | push @text_pieces, | |||||||||||||||||||||||||||
| 149 | [ | ||||||||||||||||||||||||||||
| 150 | 'html_fmt comment', | ||||||||||||||||||||||||||||
| 151 | $indent + 1, | ||||||||||||||||||||||||||||
| 152 | 'Following end tag is replacement for a missing one' | ||||||||||||||||||||||||||||
| 153 | ]; | ||||||||||||||||||||||||||||
| 154 | 21 | last GIVEN_LOCATION; | |||||||||||||||||||||||||||
| 155 | } ## end if ( $location eq 'following' ) | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if ( $location eq 'following pre' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 0 | push @text_pieces, | |||||||||||||||||||||||||||
| 158 | [ | ||||||||||||||||||||||||||||
| 159 | 'html_fmt comment', | ||||||||||||||||||||||||||||
| 160 | $indent, | ||||||||||||||||||||||||||||
| 161 | "Inside following <pre>, an end tag is missing: </$tagname>" | ||||||||||||||||||||||||||||
| 162 | ]; | ||||||||||||||||||||||||||||
| 163 | 0 | last GIVEN_LOCATION; | |||||||||||||||||||||||||||
| 164 | } ## end if ( $location eq 'following pre' ) | ||||||||||||||||||||||||||||
| 165 | Carp::croak( | ||||||||||||||||||||||||||||
| 166 | 0 | "Internal error: unprovided-for missing end tag location: $_" | |||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||
| 168 | } ## end GIVEN_LOCATION: | ||||||||||||||||||||||||||||
| 169 | 21 | next DATUM; | |||||||||||||||||||||||||||
| 170 | } ## end if ( $type eq 'msg: missing end tag' ) | ||||||||||||||||||||||||||||
| 171 | 196 | ▶ | if ( $type eq 'msg: missing pre end tag' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 2 | push @text_pieces, | |||||||||||||||||||||||||||
| 173 | [ | ||||||||||||||||||||||||||||
| 174 | 'html_fmt comment', | ||||||||||||||||||||||||||||
| 175 | $indent, | ||||||||||||||||||||||||||||
| 176 | 'An missing end tag was added to close the preceding <pre> element' | ||||||||||||||||||||||||||||
| 177 | ]; | ||||||||||||||||||||||||||||
| 178 | 2 | next DATUM; | |||||||||||||||||||||||||||
| 179 | } ## end if ( $type eq 'msg: missing pre end tag' ) | ||||||||||||||||||||||||||||
| 180 | 194 | ▶ | if ( $type eq 'msg: missing pre start tag' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 0 | push @text_pieces, | |||||||||||||||||||||||||||
| 182 | [ | ||||||||||||||||||||||||||||
| 183 | 'html_fmt comment', | ||||||||||||||||||||||||||||
| 184 | $indent, | ||||||||||||||||||||||||||||
| 185 | 'A missing start tag was added in front of the following <pre> element' | ||||||||||||||||||||||||||||
| 186 | ]; | ||||||||||||||||||||||||||||
| 187 | 0 | next DATUM; | |||||||||||||||||||||||||||
| 188 | } ## end if ( $type eq 'msg: missing pre start tag' ) | ||||||||||||||||||||||||||||
| 189 | 194 | ▶ | if ( $type eq 'msg: cruft' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 9 | my $location = $line_data->[2]; | |||||||||||||||||||||||||||
| 191 | 9 | my $cruft = $line_data->[3]; | |||||||||||||||||||||||||||
| 192 | 9 | my $token_type = $line_data->[4]; | |||||||||||||||||||||||||||
| 193 | 9 | ▶ | my $node_desc = | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 194 | $token_type eq 'S' ? 'start tag' | ||||||||||||||||||||||||||||
| 195 | : $token_type eq 'E' ? 'end tag' | ||||||||||||||||||||||||||||
| 196 | : $token_type eq 'T' ? 'text' | ||||||||||||||||||||||||||||
| 197 | : 'node'; | ||||||||||||||||||||||||||||
| 198 | GIVEN_LOCATION: { | ||||||||||||||||||||||||||||
| 199 | 9 | ▶ | if ( $location eq 'following' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 9 | push @text_pieces, | |||||||||||||||||||||||||||
| 201 | [ | ||||||||||||||||||||||||||||
| 202 | 'html_fmt comment', | ||||||||||||||||||||||||||||
| 203 | $indent, | ||||||||||||||||||||||||||||
| 204 | "Next $node_desc is cruft" | ||||||||||||||||||||||||||||
| 205 | ]; | ||||||||||||||||||||||||||||
| 206 | 9 | last GIVEN_LOCATION; | |||||||||||||||||||||||||||
| 207 | } ## end if ( $location eq 'following' ) | ||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ( $location eq 'following pre' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | # Make sure the cruft quoted inside | ||||||||||||||||||||||||||||
| 211 | # the HTML comment does not | ||||||||||||||||||||||||||||
| 212 | # disrupt the comment. | ||||||||||||||||||||||||||||
| 213 | 0 | ( my $safe_cruft = $cruft ) =~ s/--/- -/xms; | |||||||||||||||||||||||||||
| 214 | 0 | push @text_pieces, | |||||||||||||||||||||||||||
| 215 | [ | ||||||||||||||||||||||||||||
| 216 | 'html_fmt comment', | ||||||||||||||||||||||||||||
| 217 | $indent, | ||||||||||||||||||||||||||||
| 218 | qq{Inside the following <pre>, $node_desc is cruft:\n$safe_cruft} | ||||||||||||||||||||||||||||
| 219 | ]; | ||||||||||||||||||||||||||||
| 220 | 0 | last GIVEN_LOCATION; | |||||||||||||||||||||||||||
| 221 | } ## end if ( $location eq 'following pre' ) | ||||||||||||||||||||||||||||
| 222 | Carp::croak( | ||||||||||||||||||||||||||||
| 223 | 0 | "Internal error: unprovided-for cruft location: $_"); | |||||||||||||||||||||||||||
| 224 | } ## end GIVEN_LOCATION: | ||||||||||||||||||||||||||||
| 225 | 9 | next DATUM; | |||||||||||||||||||||||||||
| 226 | } ## end if ( $type eq 'msg: cruft' ) | ||||||||||||||||||||||||||||
| 227 | 185 | push @text_pieces, [ $type, $indent, $line_data->[2] ]; | |||||||||||||||||||||||||||
| 228 | } ## end for my $line_data ( map { @{$_} } @{$value} ) | ||||||||||||||||||||||||||||
| 229 | 13 | my @ws_unsafe; | |||||||||||||||||||||||||||
| 230 | 13 | $ws_unsafe[ scalar @text_pieces ] = 0; # size the array | |||||||||||||||||||||||||||
| 231 | 13 | $ws_unsafe[0] = 0; | |||||||||||||||||||||||||||
| 232 | 13 | my $last_non_comment_ix = scalar @text_pieces; | |||||||||||||||||||||||||||
| 233 | 13 | my $safe_after_piece = 0; | |||||||||||||||||||||||||||
| 234 | 13 | my $first_body_tag; | |||||||||||||||||||||||||||
| 235 | my $last_body_tag; | ||||||||||||||||||||||||||||
| 236 | 13 | TEXT_PIECE: for my $text_piece_ix ( 0 .. $#text_pieces ) { | |||||||||||||||||||||||||||
| 237 | 308 | my ( $type, $indent, $text ) = @{ $text_pieces[$text_piece_ix] }; | |||||||||||||||||||||||||||
| 238 | 308 | my $safe_before_piece = 0; | |||||||||||||||||||||||||||
| 239 | WHITESPACE_BY_TYPE: { | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | # If a comment, after-piece is whatever current value | ||||||||||||||||||||||||||||
| 242 | # of $safe_after_piece, | ||||||||||||||||||||||||||||
| 243 | # leave before as-is | ||||||||||||||||||||||||||||
| 244 | 308 | ▶ | last WHITESPACE_BY_TYPE if $type eq 'html_fmt comment'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | 262 | ▶ | last WHITESPACE_BY_TYPE if $type eq 'comment'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 259 | ▶ | if ( $type eq 'whitespace' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | # Safe before and after other whitespace | ||||||||||||||||||||||||||||
| 249 | 36 | $safe_before_piece = $safe_after_piece = 1; | |||||||||||||||||||||||||||
| 250 | 36 | last WHITESPACE_BY_TYPE; | |||||||||||||||||||||||||||
| 251 | } ## end if ( $type eq 'whitespace' ) | ||||||||||||||||||||||||||||
| 252 | 223 | ▶ | if ( $type eq 'end tag' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 85 | ▶ | if ( $text =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /xmsi ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | { | ||||||||||||||||||||||||||||
| 256 | 12 | $last_body_tag = $text_piece_ix; | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | # Unsafe after an end tag, but safe before it | ||||||||||||||||||||||||||||
| 260 | 85 | $safe_before_piece = $ws_ok_before_end_tag_flag; | |||||||||||||||||||||||||||
| 261 | 85 | $safe_after_piece = 0; | |||||||||||||||||||||||||||
| 262 | 85 | last WHITESPACE_BY_TYPE; | |||||||||||||||||||||||||||
| 263 | } ## end if ( $type eq 'end tag' ) | ||||||||||||||||||||||||||||
| 264 | 138 | ▶ | if ( $type eq 'start tag' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 83 | ▶ | if ( not defined $first_body_tag | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $first_body_tag and $text =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /imsx
MC/DC100%2/2
not defined $first_body_tag and $text =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /imsx
not defined $first_body_tag
$text =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /imsx
Truth table100%3/3
not(A) and B
A= not defined $first_body_tagB= $text =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /imsx
| |||||||||||||||||||||||||||||
| 267 | and $text | ||||||||||||||||||||||||||||
| 268 | =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /xmsi ) | ||||||||||||||||||||||||||||
| 269 | { | ||||||||||||||||||||||||||||
| 270 | 12 | $first_body_tag = $text_piece_ix; | |||||||||||||||||||||||||||
| 271 | } ## end if ( not defined $first_body_tag and $text =~ ...) | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | # Leave safe status as-is before start tag | ||||||||||||||||||||||||||||
| 274 | # Whitespace safe after a start tag | ||||||||||||||||||||||||||||
| 275 | 83 | $safe_after_piece = $ws_ok_after_start_tag_flag; | |||||||||||||||||||||||||||
| 276 | 83 | last WHITESPACE_BY_TYPE; | |||||||||||||||||||||||||||
| 277 | } ## end if ( $type eq 'start tag' ) | ||||||||||||||||||||||||||||
| 278 | 55 | ▶ | if ( $type eq 'text' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | # Leave safe status as-is before text | ||||||||||||||||||||||||||||
| 281 | # Whitespace not safe after text | ||||||||||||||||||||||||||||
| 282 | 41 | $safe_after_piece = 0; | |||||||||||||||||||||||||||
| 283 | 41 | last WHITESPACE_BY_TYPE; | |||||||||||||||||||||||||||
| 284 | } ## end if ( $type eq 'text' ) | ||||||||||||||||||||||||||||
| 285 | # Blocks can occur inline, etc. | ||||||||||||||||||||||||||||
| 286 | # So with everything else, be conservative. | ||||||||||||||||||||||||||||
| 287 | # Whitespace is unsafe after, and left as-is before. | ||||||||||||||||||||||||||||
| 288 | 14 | $safe_after_piece = 0; | |||||||||||||||||||||||||||
| 289 | } ## end WHITESPACE_BY_TYPE: | ||||||||||||||||||||||||||||
| 290 | 308 | ▶ | $ws_unsafe[ $text_piece_ix + 1 ] = $safe_after_piece ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | 308 | ▶ | if ($safe_before_piece) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | 36 | for my $ix ( $last_non_comment_ix + 1 .. $text_piece_ix ) { | |||||||||||||||||||||||||||
| 293 | 41 | $ws_unsafe[$ix] = 0; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | 308 | ▶ | if ( $type ne 'comment' and $type ne 'html_fmt comment' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$type ne "comment" and $type ne "html_fmt comment"
MC/DC100%2/2
$type ne "comment" and $type ne "html_fmt comment"
$type ne "comment"
$type ne "html_fmt comment"
Truth table100%3/3
A and B
A= $type ne "comment"B= $type ne "html_fmt comment"
| |||||||||||||||||||||||||||||
| 297 | 259 | $last_non_comment_ix = $text_piece_ix; | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | } ## end TEXT_PIECE: for my $text_piece_ix ( 0 .. $#text_pieces ) | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | # Whitespace safe before the body | ||||||||||||||||||||||||||||
| 302 | 13 | ▶ | $first_body_tag //= -1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$first_body_tag //= -1
MC/DC100%1/1
$first_body_tag //= -1
$first_body_tag
Truth table100%2/2
A
A= $first_body_tag
| |||||||||||||||||||||||||||||
| 303 | 13 | ▶ | for ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | my $text_piece_ix = 0; | ||||||||||||||||||||||||||||
| 305 | $text_piece_ix <= $first_body_tag; | ||||||||||||||||||||||||||||
| 306 | $text_piece_ix++ | ||||||||||||||||||||||||||||
| 307 | ) | ||||||||||||||||||||||||||||
| 308 | { | ||||||||||||||||||||||||||||
| 309 | 63 | $ws_unsafe[$text_piece_ix] = 0; | |||||||||||||||||||||||||||
| 310 | } ## end for ( my $text_piece_ix = 0; $text_piece_ix <= $first_body_tag...) | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | # Whitespace safe after the body, | ||||||||||||||||||||||||||||
| 313 | # or at least at the EOF if no end tag | ||||||||||||||||||||||||||||
| 314 | 13 | ▶ | $last_body_tag //= $#text_pieces; | ||||||||||||||||||||||||||
|
Condition66%2/3
$last_body_tag //= $#text_pieces
MC/DC0%0/2
$last_body_tag //= $#text_pieces
$last_body_tag
$#text_pieces
Truth table66%2/3
A //= B
A= $last_body_tagB= $#text_pieces
| |||||||||||||||||||||||||||||
| 315 | 13 | ▶ | for ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 316 | my $text_piece_ix = scalar @text_pieces; | ||||||||||||||||||||||||||||
| 317 | $text_piece_ix > $last_body_tag; | ||||||||||||||||||||||||||||
| 318 | $text_piece_ix-- | ||||||||||||||||||||||||||||
| 319 | ) | ||||||||||||||||||||||||||||
| 320 | { | ||||||||||||||||||||||||||||
| 321 | 28 | $ws_unsafe[$text_piece_ix] = 0; | |||||||||||||||||||||||||||
| 322 | } ## end for ( my $text_piece_ix = scalar @text_pieces; $text_piece_ix...) | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 13 | my @output = (); | |||||||||||||||||||||||||||
| 325 | CREATE_OUTPUT: { | ||||||||||||||||||||||||||||
| 326 | 13 | ▶ | if ( $avoid_whitespace_flag eq 'comment' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | 0 | TEXT_PIECE: for my $text_piece_ix ( 0 .. $#text_pieces ) { | |||||||||||||||||||||||||||
| 328 | my ( $type, $indent, $text ) = | ||||||||||||||||||||||||||||
| 329 | 0 | @{ $text_pieces[$text_piece_ix] }; | |||||||||||||||||||||||||||
| 330 | 0 | ▶ | next TEXT_PIECE if $type eq 'whitespace'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 0 | ▶ | my $suffix = $ws_unsafe[ $text_piece_ix + 1 ] ? '<!--' : q{}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 332 | 0 | my $indentation = q{ } x $indent; | |||||||||||||||||||||||||||
| 333 | 0 | ▶ | if ( $type eq 'html_fmt comment' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | 0 | push @output, | |||||||||||||||||||||||||||
| 335 | $indentation | ||||||||||||||||||||||||||||
| 336 | . ' html_fmt: ' | ||||||||||||||||||||||||||||
| 337 | . $text . ' -->' | ||||||||||||||||||||||||||||
| 338 | . $suffix; | ||||||||||||||||||||||||||||
| 339 | 0 | next TEXT_PIECE; | |||||||||||||||||||||||||||
| 340 | } ## end if ( $type eq 'html_fmt comment' ) | ||||||||||||||||||||||||||||
| 341 | 0 | ▶ | if ( $ws_unsafe[$text_piece_ix] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | 0 | $indentation = | |||||||||||||||||||||||||||
| 343 | $indentation | ||||||||||||||||||||||||||||
| 344 | . ' html_fmt: this comment is to avoid introducing whitespace' | ||||||||||||||||||||||||||||
| 345 | . "\n" | ||||||||||||||||||||||||||||
| 346 | . $indentation . '-->'; | ||||||||||||||||||||||||||||
| 347 | } ## end if ( $ws_unsafe[$text_piece_ix] ) | ||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if ( $type eq 'text' and $text =~ /\S/xms ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type eq "text" and $text =~ /\S/msx
MC/DC0%0/2
$type eq "text" and $text =~ /\S/msx
$type eq "text"
$text =~ /\S/msx
Truth table0%0/3
A and B
A= $type eq "text"B= $text =~ /\S/msx
| |||||||||||||||||||||||||||||
| 349 | 0 | push @output, $indentation . $text . $suffix; | |||||||||||||||||||||||||||
| 350 | 0 | next TEXT_PIECE; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | 0 | push @output, $indentation . $text . $suffix; | |||||||||||||||||||||||||||
| 353 | } ## end TEXT_PIECE: for my $text_piece_ix ( 0 .. $#text_pieces ) | ||||||||||||||||||||||||||||
| 354 | 0 | last CREATE_OUTPUT; | |||||||||||||||||||||||||||
| 355 | } ## end if ( $avoid_whitespace_flag eq 'comment' ) | ||||||||||||||||||||||||||||
| 356 | { | ||||||||||||||||||||||||||||
| 357 | # $avoid_whitespace eq 'yes' or $avoid_whitespace eq 'no' | ||||||||||||||||||||||||||||
| 358 | 13 | my $avoid_whitespace_is_yes = $avoid_whitespace_flag ne 'no'; | |||||||||||||||||||||||||||
| 359 | 13 | TEXT_PIECE: for my $text_piece_ix ( 0 .. $#text_pieces ) { | |||||||||||||||||||||||||||
| 360 | my ( $type, $indent, $text ) = | ||||||||||||||||||||||||||||
| 361 | 308 | @{ $text_pieces[$text_piece_ix] }; | |||||||||||||||||||||||||||
| 362 | 308 | ▶ | next TEXT_PIECE if $type eq 'whitespace'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | 272 | ▶ | if ( $avoid_whitespace_is_yes and $ws_unsafe[$text_piece_ix] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$avoid_whitespace_is_yes and $ws_unsafe[$text_piece_ix]
MC/DC50%1/2
$avoid_whitespace_is_yes and $ws_unsafe[$text_piece_ix]
$avoid_whitespace_is_yes
$ws_unsafe[$text_piece_ix]
Truth table66%2/3
A and B
A= $avoid_whitespace_is_yesB= $ws_unsafe[$text_piece_ix]
| |||||||||||||||||||||||||||||
| 364 | { | ||||||||||||||||||||||||||||
| 365 | 95 | my $indentation = q{ } x ($indent); | |||||||||||||||||||||||||||
| 366 | 95 | ▶ | if ( $type eq 'html_fmt comment' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | 19 | $text = | |||||||||||||||||||||||||||
| 368 | qq{<!--\n} | ||||||||||||||||||||||||||||
| 369 | . $indentation | ||||||||||||||||||||||||||||
| 370 | . ' html_fmt: ' | ||||||||||||||||||||||||||||
| 371 | . $text . "\n" | ||||||||||||||||||||||||||||
| 372 | . $indentation . ' -->'; | ||||||||||||||||||||||||||||
| 373 | } ## end if ( $type eq 'html_fmt comment' ) | ||||||||||||||||||||||||||||
| 374 | 95 | $output[-1] .= $text; | |||||||||||||||||||||||||||
| 375 | 95 | next TEXT_PIECE; | |||||||||||||||||||||||||||
| 376 | } ## end if ( $avoid_whitespace_is_yes and $ws_unsafe[...]) | ||||||||||||||||||||||||||||
| 377 | 177 | my $indentation = q{ } x $indent; | |||||||||||||||||||||||||||
| 378 | 177 | ▶ | if ( $type eq 'text' and $text =~ /\S/xms ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "text" and $text =~ /\S/msx
MC/DC50%1/2
$type eq "text" and $text =~ /\S/msx
$type eq "text"
$text =~ /\S/msx
Truth table66%2/3
A and B
A= $type eq "text"B= $text =~ /\S/msx
| |||||||||||||||||||||||||||||
| 379 | 39 | push @output, $indentation . $text; | |||||||||||||||||||||||||||
| 380 | 39 | next TEXT_PIECE; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | 138 | ▶ | if ( $type eq 'html_fmt comment' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 383 | 27 | push @output, | |||||||||||||||||||||||||||
| 384 | $indentation . '<!-- html_fmt: ' . $text . ' -->'; | ||||||||||||||||||||||||||||
| 385 | 27 | next TEXT_PIECE; | |||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | 111 | push @output, $indentation . $text; | |||||||||||||||||||||||||||
| 388 | } ## end TEXT_PIECE: for my $text_piece_ix ( 0 .. $#text_pieces ) | ||||||||||||||||||||||||||||
| 389 | 13 | last CREATE_OUTPUT; | |||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | } ## end CREATE_OUTPUT: | ||||||||||||||||||||||||||||
| 392 | 13 | return join "\n", @output, q{}; | |||||||||||||||||||||||||||
| 393 | } ## end sub post_process | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | sub do_pre { | ||||||||||||||||||||||||||||
| 396 | 2 | ▶ | my @new_line_data = (); | ||||||||||||||||||||||||||
|
Subroutine
do_pre: called CC=8 SCAR=27.7
| |||||||||||||||||||||||||||||
| 397 | 2 | my $start_tag = Marpa::R2::HTML::start_tag(); | |||||||||||||||||||||||||||
| 398 | 2 | my $end_tag = Marpa::R2::HTML::end_tag(); | |||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | CHILD: | ||||||||||||||||||||||||||||
| 401 | 2 | for my $value ( @{ Marpa::R2::HTML::values() } ) { | |||||||||||||||||||||||||||
| 402 | 0 | for my $line_data ( @{$value} ) { | |||||||||||||||||||||||||||
| 403 | 0 | ▶ | if ( $line_data->[0] =~ /\A msg [:] /xms ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | push @new_line_data, | ||||||||||||||||||||||||||||
| 405 | [ | ||||||||||||||||||||||||||||
| 406 | $line_data->[0], 0, | ||||||||||||||||||||||||||||
| 407 | 0 | 'following pre', @{$line_data}[ 3 .. $#{$line_data} ] | |||||||||||||||||||||||||||
| 408 | ]; | ||||||||||||||||||||||||||||
| 409 | } ## end if ( $line_data->[0] =~ /\A msg [:] /xms ) | ||||||||||||||||||||||||||||
| 410 | } ## end for my $line_data ( @{$value} ) | ||||||||||||||||||||||||||||
| 411 | } ## end CHILD: for my $value ( @{ Marpa::R2::HTML::values() } ) | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 2 | ▶ | if ( not defined $start_tag ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 414 | 0 | ▶ | push @new_line_data, [ 'msg: missing pre start tag', 0 ] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 415 | if $main::ADDED_TAG_COMMENT_FLAG; | ||||||||||||||||||||||||||||
| 416 | 0 | push @new_line_data, [ 'start tag', 0, '<pre>' ]; | |||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | 2 | my $original = Marpa::R2::HTML::original(); | |||||||||||||||||||||||||||
| 420 | 2 | push @new_line_data, [ 'pre', 0, $original ]; | |||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | 2 | ▶ | if ( not defined $end_tag ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 423 | 2 | ▶ | push @new_line_data, [ 'end tag', 0, '</pre>' ] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 424 | if $main::ADDED_TAG_COMMENT_FLAG; | ||||||||||||||||||||||||||||
| 425 | 2 | push @new_line_data, [ 'msg: missing pre end tag', 0 ]; | |||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||
| 427 | 2 | return \@new_line_data; | |||||||||||||||||||||||||||
| 428 | } ## end sub do_pre | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | sub do_cruft { | ||||||||||||||||||||||||||||
| 431 | 9 | ▶ | my $literal = Marpa::R2::HTML::literal(); | ||||||||||||||||||||||||||
|
Subroutine
do_cruft: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 432 | 9 | my @new_line_data = ( [ 'msg: cruft', 0, 'following', $literal, Marpa::R2::HTML::token_type() ] ); | |||||||||||||||||||||||||||
| 433 | 9 | push @new_line_data, [ 'cruft', 0, $literal ]; | |||||||||||||||||||||||||||
| 434 | 9 | return \@new_line_data; | |||||||||||||||||||||||||||
| 435 | } ## end sub do_cruft | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | sub do_comment { | ||||||||||||||||||||||||||||
| 438 | 3 | ▶ | my $literal = Marpa::R2::HTML::literal(); | ||||||||||||||||||||||||||
|
Subroutine
do_comment: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 439 | 3 | return [ [ 'comment', 0, $literal ] ]; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | sub do_default { | ||||||||||||||||||||||||||||
| 443 | 86 | ▶ | my $tagname = Marpa::R2::HTML::tagname(); | ||||||||||||||||||||||||||
|
Subroutine
do_default: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||
| 444 | 86 | my @new_line_data = (); | |||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | 86 | my $start_tag = Marpa::R2::HTML::start_tag(); | |||||||||||||||||||||||||||
| 447 | 86 | my $end_tag = Marpa::R2::HTML::end_tag(); | |||||||||||||||||||||||||||
| 448 | 86 | my $is_empty_element = Marpa::R2::HTML::is_empty_element(); | |||||||||||||||||||||||||||
| 449 | 86 | ▶ | if ($is_empty_element) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 450 | 3 | ▶ | if ( defined $start_tag ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | 2 | push @new_line_data, [ 'empty element', 0, $start_tag ]; | |||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||
| 453 | else { | ||||||||||||||||||||||||||||
| 454 | 1 | push @new_line_data, [ 'empty element', 0, '<' . $tagname . '>' ]; | |||||||||||||||||||||||||||
| 455 | 1 | ▶ | push @new_line_data, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 456 | [ 'msg: empty element missing start tag', 0, 'preceeding', $tagname ] | ||||||||||||||||||||||||||||
| 457 | if $main::ADDED_TAG_COMMENT_FLAG; | ||||||||||||||||||||||||||||
| 458 | } ## end else [ if ( defined $start_tag ) ] | ||||||||||||||||||||||||||||
| 459 | 3 | return \@new_line_data; | |||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | { | ||||||||||||||||||||||||||||
| 463 | 83 | my $tag_type = 'start tag'; | |||||||||||||||||||||||||||
| 464 | 83 | ▶ | if ( defined $start_tag ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 465 | 35 | push @new_line_data, [ $tag_type, 0, $start_tag ]; | |||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||
| 467 | else { | ||||||||||||||||||||||||||||
| 468 | 48 | push @new_line_data, [ $tag_type, 0, '<' . $tagname . '>' ]; | |||||||||||||||||||||||||||
| 469 | 48 | ▶ | push @new_line_data, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 470 | [ 'msg: missing start tag', 0, 'preceeding', $tagname ] | ||||||||||||||||||||||||||||
| 471 | if $main::ADDED_TAG_COMMENT_FLAG; | ||||||||||||||||||||||||||||
| 472 | } ## end else [ if ( defined $start_tag ) ] | ||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | 83 | my @descendant_data = @{ Marpa::R2::HTML::descendants('value,original') }; | |||||||||||||||||||||||||||
| 476 | 83 | ▶ | my $first_content_child = defined $start_tag ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 477 | 83 | ▶ | my $last_content_child = $#descendant_data - ( defined $end_tag ? 1 : 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 478 | CHILD: | ||||||||||||||||||||||||||||
| 479 | 83 | for my $descendant_data_ix ( $first_content_child .. $last_content_child ) | |||||||||||||||||||||||||||
| 480 | { | ||||||||||||||||||||||||||||
| 481 | 143 | my ( $value, $original ) = @{ $descendant_data[$descendant_data_ix] }; | |||||||||||||||||||||||||||
| 482 | 143 | ▶ | if ( defined $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 483 | 87 | for my $line_data ( @{$value} ) { | |||||||||||||||||||||||||||
| 484 | 520 | my ( $type, $indent, @data ) = @{$line_data}; | |||||||||||||||||||||||||||
| 485 | 520 | push @new_line_data, [ $type, $indent + 1, @data ]; | |||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||
| 487 | 87 | next CHILD; | |||||||||||||||||||||||||||
| 488 | } ## end if ( defined $value ) | ||||||||||||||||||||||||||||
| 489 | 56 | push @new_line_data, [ 'text', 1, $original ]; | |||||||||||||||||||||||||||
| 490 | } ## end CHILD: for my $descendant_data_ix ( $first_content_child .. ...) | ||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | 83 | ▶ | if ( not $is_empty_element ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 493 | 83 | ▶ | if ( defined $end_tag ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 494 | 9 | push @new_line_data, [ 'end tag', 0, $end_tag ]; | |||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | else { | ||||||||||||||||||||||||||||
| 497 | 74 | ▶ | push @new_line_data, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 498 | [ 'msg: missing end tag', 0, 'following', $tagname ] | ||||||||||||||||||||||||||||
| 499 | if $main::ADDED_TAG_COMMENT_FLAG; | ||||||||||||||||||||||||||||
| 500 | 74 | push @new_line_data, [ 'end tag', 0, '</' . $tagname . '>' ]; | |||||||||||||||||||||||||||
| 501 | } ## end else [ if ( defined $end_tag ) ] | ||||||||||||||||||||||||||||
| 502 | } ## end if ( not $is_empty_element ) | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | 83 | return \@new_line_data; | |||||||||||||||||||||||||||
| 505 | } ## end sub do_default | ||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | my %html_args = ( | ||||||||||||||||||||||||||||
| 508 | 'script' => sub { | ||||||||||||||||||||||||||||
| 509 | 0 | ▶ | return [ [ 'script', 0, Marpa::R2::HTML::original() ] ]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 510 | }, | ||||||||||||||||||||||||||||
| 511 | ':CRUFT' => \&do_cruft, | ||||||||||||||||||||||||||||
| 512 | ':COMMENT' => \&do_comment, | ||||||||||||||||||||||||||||
| 513 | 'pre' => \&do_pre, | ||||||||||||||||||||||||||||
| 514 | q{*} => \&do_default, | ||||||||||||||||||||||||||||
| 515 | 13 | ▶ | ':TOP' => sub { return Marpa::R2::HTML::values(); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 516 | 13 | ); | |||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | 13 | my %flags = ( | |||||||||||||||||||||||||||
| 519 | trace_terminals => $trace_terminals_flag, | ||||||||||||||||||||||||||||
| 520 | trace_cruft => $trace_cruft_flag, | ||||||||||||||||||||||||||||
| 521 | trace_values => $trace_values_flag, | ||||||||||||||||||||||||||||
| 522 | dump_config => $dump_config_flag, | ||||||||||||||||||||||||||||
| 523 | dump_AHFA => $dump_AHFA_flag, | ||||||||||||||||||||||||||||
| 524 | ); | ||||||||||||||||||||||||||||
| 525 | 13 | ▶ | if (defined $compile_flag) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 526 | 10 | open my $fh, q{<}, $compile_flag; | |||||||||||||||||||||||||||
| 527 | 10 | my $source = join q{}, <$fh>; | |||||||||||||||||||||||||||
| 528 | 10 | close $fh; | |||||||||||||||||||||||||||
| 529 | 10 | $flags{compile} = \$source; | |||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | 13 | my $value_ref = Marpa::R2::HTML::html( \$document, \%html_args, \\%flags ); | |||||||||||||||||||||||||||
| 533 | 13 | ▶ | die 'Internal error: no parse' if not defined $value_ref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 534 | 13 | ▶ | if ($dump_config_flag or $dump_AHFA_flag) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$dump_config_flag or $dump_AHFA_flag
MC/DC0%0/2
$dump_config_flag or $dump_AHFA_flag
$dump_config_flag
$dump_AHFA_flag
Truth table33%1/3
A or B
A= $dump_config_flagB= $dump_AHFA_flag
| |||||||||||||||||||||||||||||
| 535 | 0 | print ${$value_ref}; | |||||||||||||||||||||||||||
| 536 | 0 | exit 0; | |||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | 13 | ▶ | print post_process($value_ref) or die "print failed: $ERRNO"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | 13 | exit 0; | |||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | # vim: set expandtab shiftwidth=4: | ||||||||||||||||||||||||||||