blib/lib/HTML/TextToHTML.pm

filter: Statementstmt 86.6% 1606 / 1854 Branchbran 75.2% 551 / 732 Conditioncond 73.3% 306 / 417 MC/DCmcdc 51.5% 116 / 225 Subroutinesub 95.5% 65 / 68 Podpod 100% 64 / 64 totaltotal 80.6% 2708 / 3360 CC 530 SCAR 34.7
CC
530
Cov
82%
paragraph
86.8
process_para
85.9
txt2html
78.7
CRAP 32.2
↑ Summary
1 package HTML::TextToHTML;
2 {
3 7 $HTML::TextToHTML::VERSION = '2.5201';
4 }
5 7 ▶use 5.8.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 #------------------------------------------------------------------------
8  
9 =head1 NAME
10  
11 HTML::TextToHTML - convert plain text file to HTML.
12  
13 =head1 VERSION
14  
15 version 2.5201
16  
17 =head1 SYNOPSIS
18  
19 From the command line:
20  
21 txt2html I<arguments>
22  
23 From Scripts:
24  
25 use HTML::TextToHTML;
26
27 # create a new object
28 my $conv = new HTML::TextToHTML();
29  
30 # convert a file
31 $conv->txt2html(infile=>[$text_file],
32 outfile=>$html_file,
33 title=>"Wonderful Things",
34 mail=>1,
35 ]);
36  
37 # reset arguments
38 $conv->args(infile=>[], mail=>0);
39  
40 # convert a string
41 $newstring = $conv->process_chunk($mystring)
42  
43 =head1 DESCRIPTION
44  
45 HTML::TextToHTML converts plain text files to HTML. The txt2html script
46 uses this module to do the same from the command-line.
47  
48 It supports headings, tables, lists, simple character markup, and
49 hyperlinking, and is highly customizable. It recognizes some of the
50 apparent structure of the source document (mostly whitespace and
51 typographic layout), and attempts to mark that structure explicitly
52 using HTML. The purpose for this tool is to provide an easier way of
53 converting existing text documents to HTML format, giving something nicer
54 than just whapping the text into a big PRE block.
55  
56 =head2 History
57  
58 The original txt2html script was written by Seth Golub (see
59 http://www.aigeek.com/txt2html/), and converted to a perl module by
60 Kathryn Andersen (see http://www.katspace.com/tools/text_to_html/) and
61 made into a sourceforge project by Sun Tong (see
62 http://sourceforge.net/projects/txt2html/). Earlier versions of the
63 HTML::TextToHTML module called the included script texthyper so as not
64 to clash with the original txt2html script, but now the projects have
65 all been merged.
66  
67 =head1 OPTIONS
68  
69 All arguments can be set when the object is created, and further options
70 can be set when calling the actual txt2html method. Arguments
71 to methods can take a hash of arguments.
72  
73 Note that all option-names must match exactly -- no abbreviations are
74 allowed. The argument-keys are expected to have values matching those
75 required for that argument -- whether that be a boolean, a string, a
76 reference to an array or a reference to a hash. These will replace any
77 value for that argument that might have been there before.
78  
79 =over
80  
81 =item append_file
82  
83 append_file=>I<filename>
84  
85 If you want something appended by default, put the filename here.
86 The appended text will not be processed at all, so make sure it's
87 plain text or correct HTML. i.e. do not have things like:
88 Mary Andersen E<lt>kitty@example.comE<gt>
89 but instead, have:
90 Mary Andersen &lt;kitty@example.com&gt;
91  
92 (default: nothing)
93  
94 =item append_head
95  
96 append_head=>I<filename>
97  
98 If you want something appended to the head by default, put the filename here.
99 The appended text will not be processed at all, so make sure it's
100 plain text or correct HTML. i.e. do not have things like:
101 Mary Andersen E<lt>kitty@example.comE<gt>
102 but instead, have:
103 Mary Andersen &lt;kitty@example.com&gt;
104  
105 (default: nothing)
106  
107 =item body_deco
108  
109 body_deco=>I<string>
110  
111 Body decoration string: a string to be added to the BODY tag so that
112 one can set attributes to the BODY (such as class, style, bgcolor etc)
113 For example, "class='withimage'".
114  
115 =item bold_delimiter
116  
117 bold_delimiter=>I<string>
118  
119 This defines what character (or string) is taken to be the delimiter of
120 text which is to be interpreted as bold (that is, to be given a STRONG
121 tag). If this is empty, then no bolding of text will be done.
122 (default: #)
123  
124 =item bullets
125  
126 bullets=>I<string>
127  
128 This defines what single characters are taken to be "bullet" characters
129 for unordered lists. Note that because this is used as a character
130 class, if you use '-' it must come first.
131 (default:-=o*\267)
132  
133 =item bullets_ordered
134  
135 bullets_ordered=>I<string>
136  
137 This defines what single characters are taken to be "bullet" placeholder
138 characters for ordered lists. Ordered lists are normally marked by
139 a number or letter followed by '.' or ')' or ']' or ':'. If an ordered
140 bullet is used, then it simply indicates that this is an ordered list,
141 without giving explicit numbers.
142  
143 Note that because this is used as a character class, if you use '-' it
144 must come first.
145 (default:nothing)
146  
147 =item caps_tag
148  
149 caps_tag=>I<tag>
150  
151 Tag to put around all-caps lines
152 (default: STRONG)
153 If an empty tag is given, then no tag will be put around all-caps lines.
154  
155 =item custom_heading_regexp
156  
157 custom_heading_regexp=>\@custom_headings
158  
159 Add patterns for headings. Header levels are assigned by regexp in the
160 order seen in the input text. When a line matches a custom header
161 regexp, it is tagged as a header. If it's the first time that
162 particular regexp has matched, the next available header level is
163 associated with it and applied to the line. Any later matches of that
164 regexp will use the same header level. Therefore, if you want to match
165 numbered header lines, you could use something like this:
166  
167 my @custom_headings = ('^ *\d+\. \w+',
168 '^ *\d+\.\d+\. \w+',
169 '^ *\d+\.\d+\.\d+\. \w+');
170  
171 ...
172 custom_heading_regexp=>\@custom_headings,
173 ...
174  
175 Then lines like
176  
177 " 1. Examples "
178 " 1.1. Things"
179 and " 4.2.5. Cold Fusion"
180  
181 Would be marked as H1, H2, and H3 (assuming they were found in that
182 order, and that no other header styles were encountered).
183 If you prefer that the first one specified always be H1, the second
184 always be H2, the third H3, etc, then use the "explicit_headings"
185 option.
186  
187 This expects a reference to an array of strings.
188  
189 (default: none)
190  
191 =item default_link_dict
192  
193 default_link_dict=>I<filename>
194  
195 The name of the default "user" link dictionary.
196 (default: "$ENV{'HOME'}/.txt2html.dict" -- this is the same as for
197 the txt2html script. If there is no $ENV{HOME} then it is just '.txt2html.dict')
198  
199 =item demoronize
200  
201 demoronize=>1
202  
203 Convert Microsoft-generated character codes that are non-ISO codes into
204 something more reasonable.
205 (default:true)
206  
207 =item doctype
208  
209 doctype=>I<doctype>
210  
211 This gets put in the DOCTYPE field at the top of the document, unless it's
212 empty.
213  
214 Default :
215 '-//W3C//DTD HTML 4.01//EN"
216 "http://www.w3.org/TR/html4/strict.dtd'
217  
218 If B<xhtml> is true, the contents of this is ignored, unless it's
219 empty, in which case no DOCTYPE declaration is output.
220  
221 =item eight_bit_clean
222  
223 eight_bit_clean=>1
224  
225 If false, convert Latin-1 characters to HTML entities.
226 If true, this conversion is disabled; also "demoronize" is set to
227 false, since this also changes 8-bit characters.
228 (default: false)
229  
230 =item escape_HTML_chars
231  
232 escape_HTML_chars=>1
233  
234 turn & E<lt> E<gt> into &amp; &gt; &lt;
235 (default: true)
236  
237 =item explicit_headings
238  
239 explicit_headings=>1
240  
241 Don't try to find any headings except the ones specified in the
242 --custom_heading_regexp option.
243 Also, the custom headings will not be assigned levels in the order they
244 are encountered in the document, but in the order they are specified on
245 the custom_heading_regexp option.
246 (default: false)
247  
248 =item extract
249  
250 extract=>1
251  
252 Extract Mode; don't put HTML headers or footers on the result, just
253 the plain HTML (thus making the result suitable for inserting into
254 another document (or as part of the output of a CGI script).
255 (default: false)
256  
257 =item hrule_min
258  
259 hrule_min=>I<n>
260  
261 Min number of ---s for an HRule.
262 (default: 4)
263  
264 =item indent_width
265  
266 indent_width=>I<n>
267  
268 Indents this many spaces for each level of a list.
269 (default: 2)
270  
271 =item indent_par_break
272  
273 indent_par_break=>1
274  
275 Treat paragraphs marked solely by indents as breaks with indents.
276 That is, instead of taking a three-space indent as a new paragraph,
277 put in a <BR> and three non-breaking spaces instead.
278 (see also --preserve_indent)
279 (default: false)
280  
281 =item infile
282  
283 infile=>\@my_files
284 infile=>['chapter1.txt', 'chapter2.txt']
285  
286 The name of the input file(s).
287 This expects a reference to an array of filenames.
288  
289 The special filename '-' designates STDIN.
290  
291 See also L</inhandle> and L</instring>.
292  
293 (default:-)
294  
295 =item inhandle
296  
297 inhandle=>\@my_handles
298 inhandle=>[\*MYINHANDLE, \*STDIN]
299  
300 An array of input filehandles; use this instead of
301 L</infile> or L</instring> to use a filehandle or filehandles
302 as input.
303  
304 =item instring
305  
306 instring=>\@my_strings
307 instring=>[$string1, $string2]
308  
309 An array of input strings; use this instead of
310 L</infile> or L</inhandle> to use a string or strings
311 as input.
312  
313 =item italic_delimiter
314  
315 italic_delimiter=>I<string>
316  
317 This defines what character (or string) is taken to be the delimiter of
318 text which is to be interpreted as italic (that is, to be given a EM
319 tag). If this is empty, no italicising of text will be done.
320 (default: *)
321  
322 =item underline_delimiter
323  
324 underline_delimiter=>I<string>
325  
326 This defines what character (or string) is taken to be the delimiter of
327 text which is to be interpreted as underlined (that is, to be given a U
328 tag). If this is empty, no underlining of text will be done.
329 (default: _)
330  
331 =item links_dictionaries
332  
333 links_dictionaries=>\@my_link_dicts
334 links_dictionaries=>['url_links.dict', 'format_links.dict']
335  
336 File(s) to use as a link-dictionary. There can be more than one of
337 these. These are in addition to the Global Link Dictionary and the User
338 Link Dictionary. This expects a reference to an array of filenames.
339  
340 =item link_only
341  
342 link_only=>1
343  
344 Do no escaping or marking up at all, except for processing the links
345 dictionary file and applying it. This is useful if you want to use
346 the linking feature on an HTML document. If the HTML is a
347 complete document (includes HTML,HEAD,BODY tags, etc) then you'll
348 probably want to use the --extract option also.
349 (default: false)
350  
351 =item lower_case_tags
352  
353 lower_case_tags=>1
354  
355 Force all tags to be in lower-case.
356  
357 =item mailmode
358  
359 mailmode=>1
360  
361 Deal with mail headers & quoted text. The mail header paragraph is
362 given the class 'mail_header', and mail-quoted text is given the class
363 'quote_mail'.
364 (default: false)
365  
366 =item make_anchors
367  
368 make_anchors=>0
369  
370 Should we try to make anchors in headings?
371 (default: true)
372  
373 =item make_links
374  
375 make_links=>0
376  
377 Should we try to build links? If this is false, then the links
378 dictionaries are not consulted and only structural text-to-HTML
379 conversion is done. (default: true)
380  
381 =item make_tables
382  
383 make_tables=>1
384  
385 Should we try to build tables? If true, spots tables and marks them up
386 appropriately. See L</Input File Format> for information on how tables
387 should be formatted.
388  
389 This overrides the detection of lists; if something looks like a table,
390 it is taken as a table, and list-checking is not done for that
391 paragraph.
392  
393 (default: false)
394  
395 =item min_caps_length
396  
397 min_caps_length=>I<n>
398  
399 min sequential CAPS for an all-caps line
400 (default: 3)
401  
402 =item outfile
403  
404 outfile=>I<filename>
405  
406 The name of the output file. If it is "-" then the output goes
407 to Standard Output.
408 (default: - )
409  
410 =item outhandle
411  
412 The output filehandle; if this is given then the output goes
413 to this filehandle instead of to the file given in L</outfile>.
414  
415 =item par_indent
416  
417 par_indent=>I<n>
418  
419 Minumum number of spaces indented in first lines of paragraphs.
420 Only used when there's no blank line
421 preceding the new paragraph.
422 (default: 2)
423  
424 =item preformat_trigger_lines
425  
426 preformat_trigger_lines=>I<n>
427  
428 How many lines of preformatted-looking text are needed to switch to <PRE>
429 <= 0 : Preformat entire document
430 1 : one line triggers
431 >= 2 : two lines trigger
432  
433 (default: 2)
434  
435 =item endpreformat_trigger_lines
436  
437 endpreformat_trigger_lines=>I<n>
438  
439 How many lines of unpreformatted-looking text are needed to switch from <PRE>
440 <= 0 : Never preformat within document
441 1 : one line triggers
442 >= 2 : two lines trigger
443 (default: 2)
444  
445 NOTE for preformat_trigger_lines and endpreformat_trigger_lines:
446 A zero takes precedence. If one is zero, the other is ignored.
447 If both are zero, entire document is preformatted.
448  
449 =item preformat_start_marker
450  
451 preformat_start_marker=>I<regexp>
452  
453 What flags the start of a preformatted section if --use_preformat_marker
454 is true.
455  
456 (default: "^(:?(:?&lt;)|<)PRE(:?(:?&gt;)|>)\$")
457  
458 =item preformat_end_marker
459  
460 preformat_end_marker=>I<regexp>
461  
462 What flags the end of a preformatted section if --use_preformat_marker
463 is true.
464  
465 (default: "^(:?(:?&lt;)|<)/PRE(:?(:?&gt;)|>)\$")
466  
467 =item preformat_whitespace_min
468  
469 preformat_whitespace_min=>I<n>
470  
471 Minimum number of consecutive whitespace characters to trigger
472 normal preformatting.
473 NOTE: Tabs are expanded to spaces before this check is made.
474 That means if B<tab_width> is 8 and this is 5, then one tab may be
475 expanded to 8 spaces, which is enough to trigger preformatting.
476 (default: 5)
477  
478 =item prepend_file
479  
480 prepend_file=>I<filename>
481  
482 If you want something prepended to the processed body text, put the
483 filename here. The prepended text will not be processed at all, so make
484 sure it's plain text or correct HTML.
485  
486 (default: nothing)
487  
488 =item preserve_indent
489  
490 preserve_indent=>1
491  
492 Preserve the first-line indentation of paragraphs marked with indents
493 by replacing the spaces of the first line with non-breaking spaces.
494 (default: false)
495  
496 =item short_line_length
497  
498 short_line_length=>I<n>
499  
500 Lines this short (or shorter) must be intentionally broken and are kept
501 that short.
502 (default: 40)
503  
504 =item style_url
505  
506 style_url=>I<url>
507  
508 This gives the URL of a stylesheet; a LINK tag will be added to the
509 output.
510  
511 =item tab_width
512  
513 tab_width=>I<n>
514  
515 How many spaces equal a tab?
516 (default: 8)
517  
518 =item table_type
519
520 table_type=>{ ALIGN=>0, PGSQL=>0, BORDER=>1, DELIM=>0 }
521  
522 This determines which types of tables will be recognised when "make_tables"
523 is true. The possible types are ALIGN, PGSQL, BORDER and DELIM.
524 (default: all types are true)
525  
526 =item title
527  
528 title=>I<title>
529  
530 You can specify a title. Otherwise it will use a blank one.
531 (default: nothing)
532  
533 =item titlefirst
534  
535 titlefirst=>1
536  
537 Use the first non-blank line as the title. (See also "title")
538  
539 =item underline_length_tolerance
540  
541 underline_length_tolerance=>I<n>
542  
543 How much longer or shorter can underlines be and still be underlines?
544 (default: 1)
545  
546 =item underline_offset_tolerance
547  
548 underline_offset_tolerance=>I<n>
549  
550 How far offset can underlines be and still be underlines?
551 (default: 1)
552  
553 =item unhyphenation
554  
555 unhyphenation=>0
556  
557 Enables unhyphenation of text.
558 (default: true)
559  
560 =item use_mosaic_header
561  
562 use_mosaic_header=>1
563  
564 Use this option if you want to force the heading styles to match what Mosaic
565 outputs. (Underlined with "***"s is H1,
566 with "==="s is H2, with "+++" is H3, with "---" is H4, with "~~~" is H5
567 and with "..." is H6)
568 This was the behavior of txt2html up to version 1.10.
569 (default: false)
570  
571 =item use_preformat_marker
572  
573 use_preformat_marker=>1
574  
575 Turn on preformatting when encountering "<PRE>" on a line by itself, and turn
576 it off when there's a line containing only "</PRE>".
577 When such preformatted text is detected, the PRE tag will be given the
578 class 'quote_explicit'.
579 (default: off)
580  
581 =item xhtml
582  
583 xhtml=>1
584  
585 Try to make the output conform to the XHTML standard, including
586 closing all open tags and marking empty tags correctly. This
587 turns on --lower_case_tags and overrides the --doctype option.
588 Note that if you add a header or a footer file, it is up to you
589 to make it conform; the header/footer isn't touched by this.
590 Likewise, if you make link-dictionary entries that break XHTML,
591 then this won't fix them, except to the degree of putting all tags
592 into lower-case.
593  
594 (default: true)
595  
596 =back
597  
598 =head1 DEBUGGING
599  
600 There are global variables for setting types and levels
601 of debugging. These should only be used by developers.
602  
603 =over
604  
605 =item $HTML::TextToHTML::Debug
606  
607 $HTML::TextToHTML::Debug = 1;
608
609 Enable copious debugging output.
610 (default: false)
611  
612 =item $HTML::TextToHTML::DictDebug
613  
614 $HTML::TextToHTML::DictDebug = I<n>;
615  
616 Debug mode for link dictionaries. Bitwise-Or what you want to see:
617  
618 1: The parsing of the dictionary
619 2: The code that will make the links
620 4: When each rule matches something
621 8: When each tag is created
622  
623 (default: 0)
624  
625 =back
626  
627 =cut
628  
629 7 our $Debug = 0;
630 7 our $DictDebug = 0;
631  
632 =head1 METHODS
633  
634 =cut
635  
636 #------------------------------------------------------------------------
637 7 ▶use YAML::Syck;
Subroutine BEGIN: called CC=1 SCAR=0.0
638  
639 7 our $PROG = 'HTML::TextToHTML';
640  
641 #------------------------------------------------------------------------
642  
643 ########################################
644 # Definitions (Don't change these)
645 #
646  
647 # These are just constants I use for making bit vectors to keep track
648 # of what modes I'm in and what actions I've taken on the current and
649 # previous lines.
650  
651 7 our $NONE = 0;
652 7 our $LIST = 1;
653 7 our $HRULE = 2;
654 7 our $PAR = 4;
655 7 our $PRE = 8;
656 7 our $END = 16;
657 7 our $BREAK = 32;
658 7 our $HEADER = 64;
659 7 our $MAILHEADER = 128;
660 7 our $MAILQUOTE = 256;
661 7 our $CAPS = 512;
662 7 our $LINK = 1024;
663 7 our $PRE_EXPLICIT = 2048;
664 7 our $TABLE = 4096;
665 7 our $IND_BREAK = 8192;
666 7 our $LIST_START = 16384;
667 7 our $LIST_ITEM = 32768;
668  
669 # Constants for Link-processing
670 # bit-vectors for what to do with a particular link-dictionary entry
671 7 our $LINK_NOCASE = 1;
672 7 our $LINK_EVAL = 2;
673 7 our $LINK_HTML = 4;
674 7 our $LINK_ONCE = 8;
675 7 our $LINK_SECT_ONCE = 16;
676  
677 # Constants for Ordered Lists and Unordered Lists.
678 # And Definition Lists.
679 # I use this in the list stack to keep track of what's what.
680  
681 7 our $OL = 1;
682 7 our $UL = 2;
683 7 our $DL = 3;
684  
685 # Constants for table types
686 7 our $TAB_ALIGN = 1;
687 7 our $TAB_PGSQL = 2;
688 7 our $TAB_BORDER = 3;
689 7 our $TAB_DELIM = 4;
690  
691 # Constants for tags
692 7 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
693 7 TAG_START => 1,
694 TAG_END => 2,
695 TAG_EMPTY => 3,
696 7 };
697  
698 # Character entity names
699 # characters to replace with entities
700 7 our %char_entities = (
701 "\241", "&iexcl;", "\242", "&cent;", "\243", "&pound;",
702 "\244", "&curren;", "\245", "&yen;", "\246", "&brvbar;",
703 "\247", "&sect;", "\250", "&uml;", "\251", "&copy;",
704 "\252", "&ordf;", "\253", "&laquo;", "\254", "&not;",
705 "\255", "&shy;", "\256", "&reg;", "\257", "&hibar;",
706 "\260", "&deg;", "\261", "&plusmn;", "\262", "&sup2;",
707 "\263", "&sup3;", "\264", "&acute;", "\265", "&micro;",
708 "\266", "&para;", "\270", "&cedil;", "\271", "&sup1;",
709 "\272", "&ordm;", "\273", "&raquo;", "\274", "&frac14;",
710 "\275", "&frac12;", "\276", "&frac34;", "\277", "&iquest;",
711 "\300", "&Agrave;", "\301", "&Aacute;", "\302", "&Acirc;",
712 "\303", "&Atilde;", "\304", "&Auml;", "\305", "&Aring;",
713 "\306", "&AElig;", "\307", "&Ccedil;", "\310", "&Egrave;",
714 "\311", "&Eacute;", "\312", "&Ecirc;", "\313", "&Euml;",
715 "\314", "&Igrave;", "\315", "&Iacute;", "\316", "&Icirc;",
716 "\317", "&Iuml;", "\320", "&ETH;", "\321", "&Ntilde;",
717 "\322", "&Ograve;", "\323", "&Oacute;", "\324", "&Ocirc;",
718 "\325", "&Otilde;", "\326", "&Ouml;", "\327", "&times;",
719 "\330", "&Oslash;", "\331", "&Ugrave;", "\332", "&Uacute;",
720 "\333", "&Ucirc;", "\334", "&Uuml;", "\335", "&Yacute;",
721 "\336", "&THORN;", "\337", "&szlig;", "\340", "&agrave;",
722 "\341", "&aacute;", "\342", "&acirc;", "\343", "&atilde;",
723 "\344", "&auml;", "\345", "&aring;", "\346", "&aelig;",
724 "\347", "&ccedil;", "\350", "&egrave;", "\351", "&eacute;",
725 "\352", "&ecirc;", "\353", "&euml;", "\354", "&igrave;",
726 "\355", "&iacute;", "\356", "&icirc;", "\357", "&iuml;",
727 "\360", "&eth;", "\361", "&ntilde;", "\362", "&ograve;",
728 "\363", "&oacute;", "\364", "&ocirc;", "\365", "&otilde;",
729 "\366", "&ouml;", "\367", "&divide;", "\370", "&oslash;",
730 "\371", "&ugrave;", "\372", "&uacute;", "\373", "&ucirc;",
731 "\374", "&uuml;", "\375", "&yacute;", "\376", "&thorn;",
732 "\377", "&yuml;", "\267", "&middot;",
733 );
734  
735 # alignments for tables
736 7 our @alignments = ('', '', ' ALIGN="RIGHT"', ' ALIGN="CENTER"');
737 7 our @lc_alignments = ('', '', ' align="right"', ' align="center"');
738 7 our @xhtml_alignments =
739 ('', '', ' style="text-align: right;"', ' style="text-align: center;"');
740  
741 #---------------------------------------------------------------#
742 # Object interface
743 #---------------------------------------------------------------#
744  
745 =head2 new
746  
747 $conv = new HTML::TextToHTML()
748  
749 $conv = new HTML::TextToHTML(titlefirst=>1,
750 ...
751 );
752  
753 Create a new object with new. If arguments are given, these arguments
754 will be used in invocations of other methods.
755  
756 See L</OPTIONS> for the possible values of the arguments.
757  
758 =cut
759  
760 sub new
761 26 ▶{
Subroutine new: called CC=2 SCAR=7.1
Pod documented
762 26 my $invocant = shift;
763 26 my $self = {};
764  
765 26 ▶ my $class = ref($invocant) || $invocant; # Object or class name
Condition33%1/3
ref $invocant || $invocant
l!l&&r!l&&!r
0260
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant $invocant
Truth table33%1/3
A || B
A= ref $invocantB= $invocant
ABresult
1X1
011
000
766 26 init_our_data($self);
767  
768 # bless self
769 26 bless($self, $class);
770  
771 26 $self->args(@_);
772  
773 26 return $self;
774 } # new
775  
776 =head2 args
777  
778 $conv->args(short_line_length=>60,
779 titlefirst=>1,
780 ....
781 );
782  
783 Updates the current arguments/options of the HTML::TextToHTML object.
784 Takes hash of arguments, which will be used in invocations of other
785 methods.
786 See L</OPTIONS> for the possible values of the arguments.
787  
788 =cut
789  
790 sub args
791 96 ▶{
Subroutine args: called CC=9 SCAR=25.3
Pod documented
792 96 my $self = shift;
793 96 my %args = @_;
794  
795 96 ▶ if (%args)
Branch: 1 branch
BranchTrueFalseTotal
if (%args) 71 25 96
796 {
797 71 ▶ if ($Debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($HTML::TextToHTML::Debug) 0 71 71
798 {
799 0 print STDERR "========args(hash)========\n";
800 0 print STDERR Dump(%args);
801 }
802 71 my $arg;
803 my $val;
804 71 ▶ while (($arg, $val) = each %args)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 281 71 352
805 {
806 281 ▶ if (defined $val)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 281 0 281
807 {
808 281 ▶ if ($arg =~ /^-/)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^-/) 0 281 281
809 {
810 0 $arg =~ s/^-//; # get rid of first dash
811 0 $arg =~ s/^-//; # get rid of possible second dash
812 }
813 281 ▶ if ($Debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($HTML::TextToHTML::Debug) 0 281 281
814 {
815 0 print STDERR "--", $arg;
816 }
817 281 $self->{$arg} = $val;
818 281 ▶ if ($Debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($HTML::TextToHTML::Debug) 0 281 281
819 {
820 0 print STDERR " ", $val, "\n";
821 }
822 }
823 }
824 }
825 96 $self->deal_with_options();
826 96 ▶ if ($Debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($HTML::TextToHTML::Debug) 0 96 96
827 {
828 0 print STDERR Dump($self);
829 }
830  
831 96 return 1;
832 } # args
833  
834 =head2 process_chunk
835  
836 $newstring = $conv->process_chunk($mystring);
837  
838 Convert a string to a HTML fragment. This assumes that this string is
839 at the least, a single paragraph, but it can contain more than that.
840 This returns the processed string. If you want to pass arguments to
841 alter the behaviour of this conversion, you need to do that earlier,
842 either when you create the object, or with the L</args> method.
843  
844 $newstring = $conv->process_chunk($mystring,
845 close_tags=>0);
846  
847 If there are open tags (such as lists) in the input string,
848 process_chunk will automatically close them, unless you specify not
849 to, with the close_tags option.
850  
851 $newstring = $conv->process_chunk($mystring,
852 is_fragment=>1);
853  
854 If you want this string to be treated as a fragment, and not assumed to
855 be a paragraph, set is_fragment to true. If there is more than one
856 paragraph in the string (ie it contains blank lines) then this option
857 will be ignored.
858  
859 =cut
860  
861 sub process_chunk ($$;%)
862 345 ▶{
Subroutine process_chunk: called CC=5 SCAR=16.1
Pod documented
863 345 my $self = shift;
864 345 my $chunk = shift;
865 345 my %args = (
866 close_tags => 1,
867 is_fragment => 0,
868 @_
869 );
870  
871 345 my $ret_str = '';
872 345 my @paras = split(/\r?\n\r?\n/, $chunk);
873 345 my $ind = 0;
874 345 ▶ if (@paras == 1) # just one paragraph
Branch: 1 branch
BranchTrueFalseTotal
if (@paras == 1) { } 342 3 345
875 {
876 $ret_str .= $self->process_para(
877 $chunk,
878 close_tags => $args{close_tags},
879 is_fragment => $args{is_fragment}
880 342 );
881 }
882 else
883 {
884 3 my $ind = 0;
885 3 foreach my $para (@paras)
886 {
887 # if the paragraph doesn't end with a newline, add one
888 96 ▶ $para .= "\n" if ($para !~ /\n$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $para =~ /\n$/ 95 1 96
889 96 ▶ if ($ind == @paras - 1) # last one
Branch: 1 branch
BranchTrueFalseTotal
if ($ind == @paras - 1) { } 2 94 96
890 {
891 $ret_str .= $self->process_para(
892 $para,
893 close_tags => $args{close_tags},
894 2 is_fragment => 0
895 );
896 }
897 else
898 {
899 94 $ret_str .= $self->process_para(
900 $para,
901 close_tags => 0,
902 is_fragment => 0
903 );
904 }
905 96 $ind++;
906 }
907 }
908 345 $ret_str;
909 } # process_chunk
910  
911 =head2 process_para
912  
913 $newstring = $conv->process_para($mystring);
914  
915 Convert a string to a HTML fragment. This assumes that this string is
916 at the most a single paragraph, with no blank lines in it. If you don't
917 know whether your string will contain blank lines or not, use the
918 L</process_chunk> method instead.
919  
920 This returns the processed string. If you want to pass arguments to
921 alter the behaviour of this conversion, you need to do that earlier,
922 either when you create the object, or with the L</args> method.
923  
924 $newstring = $conv->process_para($mystring,
925 close_tags=>0);
926  
927 If there are open tags (such as lists) in the input string, process_para
928 will automatically close them, unless you specify not to, with the
929 close_tags option.
930  
931 $newstring = $conv->process_para($mystring,
932 is_fragment=>1);
933  
934 If you want this string to be treated as a fragment, and not assumed to be
935 a paragraph, set is_fragment to true.
936  
937 =cut
938  
939 sub process_para ($$;%)
940 440 ▶{
Subroutine process_para: called CC=81 SCAR=44.5
Pod documented
941 440 my $self = shift;
942 440 my $para = shift;
943 440 my %args = (
944 close_tags => 1,
945 is_fragment => 0,
946 @_
947 );
948  
949 # if this is an external call, do certain initializations
950 440 $self->do_init_call();
951  
952 440 my $para_action = $NONE;
953  
954 # tables and mailheaders don't carry over from one para to the next
955 440 ▶ if ($self->{__mode} & $TABLE)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__mode"} & $HTML::TextToHTML::TABLE) 6 434 440
956 {
957 6 $self->{__mode} ^= $TABLE;
958 }
959 440 ▶ if ($self->{__mode} & $MAILHEADER)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__mode"} & $HTML::TextToHTML::MAILHEADER) 11 429 440
960 {
961 11 $self->{__mode} ^= $MAILHEADER;
962 }
963  
964 # convert Microsoft character codes into sensible characters
965 440 ▶ if ($self->{demoronize})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"demoronize"}) 440 0 440
966 {
967 440 demoronize_char($para);
968 }
969  
970 # if we are not just linking, we are discerning structure
971 440 ▶ if (!$self->{link_only})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"link_only"}) 440 0 440
972 {
973  
974 # Chop trailing whitespace and DOS CRs
975 440 $para =~ s/[ \011]*\015$//;
976 # Chop leading whitespace and DOS CRs
977 440 $para =~ s/^[ \011]*\015//;
978 440 $para =~ s/\r//g; # remove any stray carriage returns
979  
980 440 my @done_lines = (); # lines which have been processed
981  
982 # The PRE_EXPLICIT structure can carry over from one
983 # paragraph to the next, but it is ended with the
984 # explicit end-tag designated for it.
985 # Therefore we can shortcut for this by checking
986 # for the end of the PRE_EXPLICIT and chomping off
987 # the preformatted string part of this para before
988 # we have to split it into lines.
989 # Note that after this check, we could *still* be
990 # in PRE_EXPLICIT mode.
991 440 ▶ if ($self->{__mode} & $PRE_EXPLICIT)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT) 0 440 440
992 {
993 0 my $pre_str =
994 $self->split_end_explicit_preformat(para_ref => \$para);
995 0 ▶ if ($pre_str)
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_str) 0 0 0
996 {
997 0 push @done_lines, $pre_str;
998 }
999 }
1000  
1001 440 ▶ if (defined $para && $para ne "")
Branch: 1 branch
BranchTrueFalseTotal
if (defined $para and $para ne "") 440 0 440
Condition33%1/3
defined $para and $para ne ""
!ll&&!rl&&r
00440
MC/DC0%0/2
defined $para and $para ne ""
defined $para $para ne ""
Truth table33%1/3
A and B
A= defined $paraB= $para ne ""
ABresult
0X0
100
111
1002 {
1003 #
1004 # Now we split the paragraph into lines
1005 #
1006 440 my $para_len = length($para);
1007 440 my @para_lines = split(/^/, $para);
1008 440 my @para_line_len = ();
1009 440 my @para_line_indent = ();
1010 440 my @para_line_action = ();
1011 440 my $i = 0;
1012 440 foreach my $line (@para_lines)
1013 {
1014 # Change all tabs to spaces
1015 1603 ▶ while ($line =~ /\011/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\011/) 124 1603 1727
1016 {
1017 124 my $tw = $self->{tab_width};
1018 124 $line =~ s/\011/" " x ($tw - (length($`) % $tw))/e;
1019 }
1020 1603 push @para_line_len, length($line);
1021 1603 ▶ if ($line =~ /^\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*$/) { } 26 1577 1603
1022 {
1023 # if the line is blank, use the previous indent
1024 # if there is one
1025 26 ▶ push @para_line_indent,
Branch: 1 branch
BranchTrueFalseTotal
$i == 0 ? : 2 24 26
1026 ($i == 0 ? 0 : $para_line_indent[$i - 1]);
1027 }
1028 else
1029 {
1030 # count the number of leading spaces
1031 1577 my ($ws) = $line =~ /^( *)[^ ]/;
1032 1577 push @para_line_indent, length($ws);
1033 }
1034 1603 push @para_line_action, $NONE;
1035 1603 $i++;
1036 }
1037  
1038 # There are two more structures which carry over from one
1039 # paragraph to the next: LIST, PRE
1040 # There are also certain things which will immediately end
1041 # multi-paragraph LIST and PRE, if found at the start
1042 # of a paragraph:
1043 # A list will be ended by
1044 # TABLE, MAILHEADER, HEADER, custom-header
1045 # A PRE will be ended by
1046 # TABLE, MAILHEADER and non-pre text
1047  
1048 440 my $is_table = 0;
1049 440 my $table_type = 0;
1050 440 my $is_mailheader = 0;
1051 440 my $is_header = 0;
1052 440 my $is_custom_header = 0;
1053 440 ▶ if (@{$self->{custom_heading_regexp}})
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"custom_heading_regexp"};}) 155 285 440
1054 {
1055 155 $is_custom_header =
1056 $self->is_custom_heading(line => $para_lines[0]);
1057 }
1058 440 ▶ if ( $self->{make_tables}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"make_tables"} and @para_lines > 1) 123 317 440
Condition100%3/3
$self->{"make_tables"} and @para_lines > 1
!ll&&!rl&&r
26849123
MC/DC100%2/2
$self->{"make_tables"} and @para_lines > 1
$self->{"make_tables"} @para_lines > 1
Truth table100%3/3
A and B
A= $self->{"make_tables"}B= @para_lines > 1
ABresult
0X0
100
111
1059 && @para_lines > 1)
1060 {
1061 123 $table_type = $self->get_table_type(
1062 rows_ref => \@para_lines,
1063 para_len => $para_len
1064 );
1065 123 $is_table = ($table_type != 0);
1066 }
1067 440 ▶ if ( !$self->{explicit_headings}
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"explicit_headings"} and @para_lines > 1 and not $is_table) 269 171 440
Condition83%5/6
not $self->{"explicit_headings"} and @para_lines > 1 and not $is_table
!ll&&!rl&&r
14922269
not $self->{"explicit_headings"} and @para_lines > 1
!ll&&!rl&&r
0149291
MC/DC66%2/3
not $self->{"explicit_headings"} and @para_lines > 1 and not $is_table
not $self->{"explicit_headings"} @para_lines > 1 not $is_table
Truth table75%3/4
not(A) and B and not(C)
A= not $self->{"explicit_headings"}B= @para_lines > 1C= not $is_table
ABCresult
0XX0
10X0
1100
1111
1068 && @para_lines > 1
1069 && !$is_table)
1070 {
1071 269 $is_header = $self->is_heading(
1072 line_ref => \$para_lines[0],
1073 next_ref => \$para_lines[1]
1074 );
1075 }
1076 # Note that it is concievable that someone has
1077 # partially disabled mailmode by making a custom header
1078 # which matches the start of mail.
1079 # This is stupid, but allowable, so we check.
1080 440 ▶ if ( $self->{mailmode}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"mailmode"} and not $is_table and not $is_custom_header) 196 244 440
Condition100%6/6
$self->{"mailmode"} and not $is_table and not $is_custom_header
!ll&&!rl&&r
2422196
$self->{"mailmode"} and not $is_table
!ll&&!rl&&r
23012198
MC/DC100%3/3
$self->{"mailmode"} and not $is_table and not $is_custom_header
$self->{"mailmode"} not $is_table not $is_custom_header
Truth table100%4/4
A and not(B) and not(C)
A= $self->{"mailmode"}B= not $is_tableC= not $is_custom_header
ABCresult
0XX0
10X0
1100
1111
1081 && !$is_table
1082 && !$is_custom_header)
1083 {
1084 196 $is_mailheader = $self->is_mailheader(rows_ref => \@para_lines);
1085 }
1086  
1087 # end the list if we can end it
1088 440 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__mode"} & $HTML::TextToHTML::LIST and $is_table || $is_mailheader || $is_header || $is_custom_header) 7 433 440
Condition66%8/12
$self->{"__mode"} & $HTML::TextToHTML::LIST and $is_table || $is_mailheader || $is_header || $is_custom_header
!ll&&!rl&&r
383507
$is_table or $is_mailheader or $is_header or $is_custom_header
l!l&&r!l&&!r
7050
$is_table or $is_mailheader or $is_header
l!l&&r!l&&!r
0750
$is_table or $is_mailheader
l!l&&r!l&&!r
0057
MC/DC40%2/5
$self->{"__mode"} & $HTML::TextToHTML::LIST and $is_table || $is_mailheader || $is_header || $is_custom_header
$self->{"__mode"} & $HTML::TextToHTML::LIST $is_table $is_mailheader $is_header $is_custom_header
Truth table50%3/6
A and B or C or D or E
A= $self->{"__mode"} & $HTML::TextToHTML::LISTB= $is_tableC= $is_mailheaderD= $is_headerE= $is_custom_header
ABCDEresult
0XXXX0
100000
11XXX1
101XX1
1001X1
100011
1089 ($self->{__mode} & $LIST)
1090 && ( $is_table
1091 || $is_mailheader
1092 || $is_header
1093 || $is_custom_header)
1094 )
1095 {
1096 7 my $list_end = '';
1097 7 my $action = 0;
1098 $self->endlist(
1099 num_lists => $self->{__listnum},
1100 7 prev_ref => \$list_end,
1101 line_action_ref => \$action
1102 );
1103 7 push @done_lines, $list_end;
1104 7 $self->{__prev_para_action} |= $END;
1105 }
1106  
1107 # end the PRE if we can end it
1108 440 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__mode"} & $HTML::TextToHTML::PRE and not $self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT and $is_table || $is_mailheader || !$self->is_preformatted($para_lines[0]) and $self->{"preformat_trigger_lines"} != 0) 14 426 440
Condition80%12/15
$self->{"__mode"} & $HTML::TextToHTML::PRE and not $self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT and $is_table || $is_mailheader || !$self->is_preformatted($para_lines[0]) and $self->{"preformat_trigger_lines"} != 0
!ll&&!rl&&r
426014
$self->{"__mode"} & $HTML::TextToHTML::PRE and not $self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT and $is_table || $is_mailheader || !$self->is_preformatted($para_lines[0])
!ll&&!rl&&r
420614
$self->{"__mode"} & $HTML::TextToHTML::PRE and not $self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT
!ll&&!rl&&r
420020
$is_table or $is_mailheader or not $self->is_preformatted($para_lines[0])
l!l&&r!l&&!r
1136
$is_table or $is_mailheader
l!l&&r!l&&!r
0119
MC/DC50%3/6
$self->{"__mode"} & $HTML::TextToHTML::PRE and not $self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT and $is_table || $is_mailheader || !$self->is_preformatted($para_lines[0]) and $self->{"preformat_trigger_lines"} != 0
$self->{"__mode"} & $HTML::TextToHTML::PRE not $self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT $is_table $is_mailheader not $self->is_preformatted($para_lines[0]) $self->{"preformat_trigger_lines"} != 0
Truth table44%4/9
A and not(B) and C or D or not(E) and F
A= $self->{"__mode"} & $HTML::TextToHTML::PREB= not $self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICITC= $is_tableD= $is_mailheaderE= not $self->is_preformatted($para_lines[0])F= $self->{"preformat_trigger_lines"} != 0
ABCDEFresult
0XXXXX0
10XXXX0
11000X0
111XX00
1101X00
1100100
111XX11
1101X11
1100111
1109 ($self->{__mode} & $PRE)
1110 && !($self->{__mode} & $PRE_EXPLICIT)
1111 && ( $is_table
1112 || $is_mailheader
1113 || !$self->is_preformatted($para_lines[0]))
1114 && ($self->{preformat_trigger_lines} != 0)
1115 )
1116 {
1117 14 my $pre_end = '';
1118 14 my $tag = $self->close_tag('pre');
1119 14 $pre_end = "${tag}\n";
1120 14 $self->{__mode} ^= ($PRE & $self->{__mode});
1121 14 push @done_lines, $pre_end;
1122 14 $self->{__prev_para_action} |= $END;
1123 }
1124  
1125 # The PRE and PRE_EXPLICIT structure can carry over
1126 # from one paragraph to the next, but because we don't
1127 # want trailing newlines, such newlines would have been
1128 # gotten rid of in the previous call. However, with
1129 # a preformatted text, we do want the blank lines in it
1130 # to be preserved, so let's add a blank line in here.
1131 440 ▶ if ($self->{__mode} & $PRE)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__mode"} & $HTML::TextToHTML::PRE) 6 434 440
1132 {
1133 6 push @done_lines, "\n";
1134 }
1135  
1136 # Now, we do certain things which are only found at the
1137 # start of a paragraph:
1138 # HEADER, custom-header, TABLE and MAILHEADER
1139 # These could concievably eat the rest of the paragraph.
1140  
1141 440 ▶ if ($is_custom_header)
Branch: 2 branches
BranchTrueFalseTotal
if ($is_custom_header) { } 9 431 440
elsif ($is_header) { } 54 377 431
1142 {
1143 # custom header eats the first line
1144 9 my $header = shift @para_lines;
1145 9 shift @para_line_len;
1146 9 shift @para_line_indent;
1147 9 shift @para_line_action;
1148 9 $self->custom_heading(line_ref => \$header);
1149 9 push @done_lines, $header;
1150 9 $self->{__prev_para_action} |= $HEADER;
1151 }
1152 elsif ($is_header)
1153 {
1154 # normal header eats the first two lines
1155 54 my $header = shift @para_lines;
1156 54 shift @para_line_len;
1157 54 shift @para_line_indent;
1158 54 shift @para_line_action;
1159 54 my $underline = shift @para_lines;
1160 54 shift @para_line_len;
1161 54 shift @para_line_indent;
1162 54 shift @para_line_action;
1163 54 $self->heading(
1164 line_ref => \$header,
1165 next_ref => \$underline
1166 );
1167 54 push @done_lines, $header;
1168 54 $self->{__prev_para_action} |= $HEADER;
1169 }
1170  
1171 # do the table stuff on the array of lines
1172 440 ▶ if ($self->{make_tables} && $is_table)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"make_tables"} and $is_table) 22 418 440
Condition100%3/3
$self->{"make_tables"} and $is_table
!ll&&!rl&&r
26815022
MC/DC100%2/2
$self->{"make_tables"} and $is_table
$self->{"make_tables"} $is_table
Truth table100%3/3
A and B
A= $self->{"make_tables"}B= $is_table
ABresult
0X0
100
111
1173 {
1174 22 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tablestuff("table_type", $table_type, "rows_ref", \@para_lines, "para_len", $para_len)) 22 0 22
1175 $self->tablestuff(
1176 table_type => $table_type,
1177 rows_ref => \@para_lines,
1178 para_len => $para_len
1179 )
1180 )
1181 {
1182 # this has used up all the lines
1183 22 push @done_lines, @para_lines;
1184 22 @para_lines = ();
1185 }
1186 }
1187  
1188 # check of this para is a mail-header
1189 440 ▶ if ( $is_mailheader
Branch: 1 branch
BranchTrueFalseTotal
if ($is_mailheader and not $self->{"__mode"} & $HTML::TextToHTML::TABLE and @para_lines) 11 429 440
Condition66%4/6
$is_mailheader and not $self->{"__mode"} & $HTML::TextToHTML::TABLE and @para_lines
!ll&&!rl&&r
429011
$is_mailheader and not $self->{"__mode"} & $HTML::TextToHTML::TABLE
!ll&&!rl&&r
429011
MC/DC33%1/3
$is_mailheader and not $self->{"__mode"} & $HTML::TextToHTML::TABLE and @para_lines
$is_mailheader not $self->{"__mode"} & $HTML::TextToHTML::TABLE @para_lines
Truth table50%2/4
A and not(B) and C
A= $is_mailheaderB= not $self->{"__mode"} & $HTML::TextToHTML::TABLEC= @para_lines
ABCresult
0XX0
10X0
1100
1111
1190 && !($self->{__mode} & $TABLE)
1191 && @para_lines)
1192 {
1193 11 $self->mailheader(rows_ref => \@para_lines);
1194 # this has used up all the lines
1195 11 push @done_lines, @para_lines;
1196 11 @para_lines = ();
1197 }
1198  
1199 #
1200 # Now go through the paragraph lines one at a time
1201 # Note that we won't have TABLE, MAILHEADER, HEADER modes
1202 # because they would have eaten the lines
1203 #
1204 440 my $prev = '';
1205 440 my $prev_action = $self->{__prev_para_action};
1206 440 ▶ for (my $i = 0; $i < @para_lines; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @para_lines) 1166 440 1606
1207 {
1208 1166 my $prev_ref;
1209 my $prev_action_ref;
1210 1166 my $prev_line_indent;
1211 1166 my $prev_line_len;
1212 1166 ▶ if ($i == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) { } 350 816 1166
1213 {
1214 350 $prev_ref = \$prev;
1215 350 $prev_action_ref = \$prev_action;
1216 350 $prev_line_indent = 0;
1217 350 $prev_line_len = 0;
1218 }
1219 else
1220 {
1221 816 $prev_ref = \$para_lines[$i - 1];
1222 816 $prev_action_ref = \$para_line_action[$i - 1];
1223 816 $prev_line_indent = $para_line_indent[$i - 1];
1224 816 $prev_line_len = $para_line_len[$i - 1];
1225 }
1226 1166 my $next_ref;
1227 1166 ▶ if ($i == $#para_lines)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $#para_lines) { } 350 816 1166
1228 {
1229 350 $next_ref = undef;
1230 }
1231 else
1232 {
1233 816 $next_ref = \$para_lines[$i + 1];
1234 }
1235  
1236 $para_lines[$i] = escape($para_lines[$i])
1237 1166 ▶ if ($self->{escape_HTML_chars});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"escape_HTML_chars"} 1166 0 1166
1238  
1239 1166 ▶ if ($self->{mailmode}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"mailmode"} and not $self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT) 519 647 1166
Condition100%3/3
$self->{"mailmode"} and not $self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT
!ll&&!rl&&r
6425519
MC/DC100%2/2
$self->{"mailmode"} and not $self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT
$self->{"mailmode"} not $self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT
Truth table100%3/3
A and not(B)
A= $self->{"mailmode"}B= not $self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT
ABresult
0X0
100
111
1240 && !($self->{__mode} & ($PRE_EXPLICIT)))
1241 {
1242 519 $self->mailquote(
1243 line_ref => \$para_lines[$i],
1244 line_action_ref => \$para_line_action[$i],
1245 prev_ref => $prev_ref,
1246 prev_action_ref => $prev_action_ref,
1247 next_ref => $next_ref
1248 );
1249 }
1250  
1251 1166 ▶ if ( ($self->{__mode} & $PRE)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__mode"} & $HTML::TextToHTML::PRE and $self->{"preformat_trigger_lines"} != 0) 85 1081 1166
Condition66%2/3
$self->{"__mode"} & $HTML::TextToHTML::PRE and $self->{"preformat_trigger_lines"} != 0
!ll&&!rl&&r
1081085
MC/DC50%1/2
$self->{"__mode"} & $HTML::TextToHTML::PRE and $self->{"preformat_trigger_lines"} != 0
$self->{"__mode"} & $HTML::TextToHTML::PRE $self->{"preformat_trigger_lines"} != 0
Truth table66%2/3
A and B
A= $self->{"__mode"} & $HTML::TextToHTML::PREB= $self->{"preformat_trigger_lines"} != 0
ABresult
0X0
100
111
1252 && ($self->{preformat_trigger_lines} != 0))
1253 {
1254 85 $self->endpreformat(
1255 para_lines_ref => \@para_lines,
1256 para_action_ref => \@para_line_action,
1257 ind => $i,
1258 prev_ref => $prev_ref
1259 );
1260 }
1261  
1262 1166 ▶ if (!($self->{__mode} & $PRE))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"__mode"} & $HTML::TextToHTML::PRE) 1086 80 1166
1263 {
1264 1086 $self->hrule(
1265 para_lines_ref => \@para_lines,
1266 para_action_ref => \@para_line_action,
1267 ind => $i
1268 );
1269 }
1270 1166 ▶ if (!($self->{__mode} & ($PRE))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"__mode"} & $HTML::TextToHTML::PRE or $para_lines[$i] =~ /^\s*$/) 1060 106 1166
Condition100%3/3
$self->{"__mode"} & $HTML::TextToHTML::PRE or $para_lines[$i] =~ /^\s*$/
l!l&&r!l&&!r
80261060
MC/DC100%2/2
$self->{"__mode"} & $HTML::TextToHTML::PRE or $para_lines[$i] =~ /^\s*$/
$self->{"__mode"} & $HTML::TextToHTML::PRE $para_lines[$i] =~ /^\s*$/
Truth table100%3/3
A or B
A= $self->{"__mode"} & $HTML::TextToHTML::PREB= $para_lines[$i] =~ /^\s*$/
ABresult
1X1
011
000
1271 && ($para_lines[$i] !~ /^\s*$/))
1272 {
1273 1060 $self->liststuff(
1274 para_lines_ref => \@para_lines,
1275 para_action_ref => \@para_line_action,
1276 para_line_indent_ref => \@para_line_indent,
1277 ind => $i,
1278 prev_ref => $prev_ref
1279 );
1280 }
1281 1166 ▶ if ( !($para_line_action[$i] & ($HEADER | $LIST))
Branch: 1 branch
BranchTrueFalseTotal
if (not $para_line_action[$i] & ($HTML::TextToHTML::HEADER | $HTML::TextToHTML::LIST) || $self->{"__mode"} & ($HTML::TextToHTML::LIST | $HTML::TextToHTML::PRE) and $self->{"__preformat_enabled"}) 823 343 1166
Condition83%5/6
not $para_line_action[$i] & ($HTML::TextToHTML::HEADER | $HTML::TextToHTML::LIST) || $self->{"__mode"} & ($HTML::TextToHTML::LIST | $HTML::TextToHTML::PRE) and $self->{"__preformat_enabled"}
!ll&&!rl&&r
3430823
$para_line_action[$i] & ($HTML::TextToHTML::HEADER | $HTML::TextToHTML::LIST) || $self->{'__mode'} & ($HTML::TextToHTML::LIST | $HTML::TextToHTML::PRE)
l!l&&r!l&&!r
158185823
MC/DC66%2/3
not $para_line_action[$i] & ($HTML::TextToHTML::HEADER | $HTML::TextToHTML::LIST) || $self->{"__mode"} & ($HTML::TextToHTML::LIST | $HTML::TextToHTML::PRE) and $self->{"__preformat_enabled"}
$para_line_action[$i] & ($HTML::TextToHTML::HEADER | $HTML::TextToHTML::LIST) $self->{'__mode'} & ($HTML::TextToHTML::LIST | $HTML::TextToHTML::PRE) $self->{"__preformat_enabled"}
Truth table75%3/4
not(A || B) and C
A= $para_line_action[$i] & ($HTML::TextToHTML::HEADER | $HTML::TextToHTML::LIST)B= $self->{'__mode'} & ($HTML::TextToHTML::LIST | $HTML::TextToHTML::PRE)C= $self->{"__preformat_enabled"}
ABCresult
1XX0
01X0
0000
0011
1282 && !($self->{__mode} & ($LIST | $PRE))
1283 && $self->{__preformat_enabled})
1284 {
1285 $self->preformat(
1286 mode_ref => \$self->{__mode},
1287 823 line_ref => \$para_lines[$i],
1288 line_action_ref => \$para_line_action[$i],
1289 prev_ref => $prev_ref,
1290 next_ref => $next_ref,
1291 prev_action_ref => $prev_action_ref
1292 );
1293 }
1294 1166 ▶ if (!($self->{__mode} & ($PRE)))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"__mode"} & $HTML::TextToHTML::PRE) 1065 101 1166
1295 {
1296 $self->paragraph(
1297 line_ref => \$para_lines[$i],
1298 line_action_ref => \$para_line_action[$i],
1299 prev_ref => $prev_ref,
1300 prev_action_ref => $prev_action_ref,
1301 line_indent => $para_line_indent[$i],
1302 prev_indent => $prev_line_indent,
1303 is_fragment => $args{is_fragment},
1304 1065 ind => $i,
1305 );
1306 }
1307 1166 ▶ if (!($self->{__mode} & ($PRE | $LIST)))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::LIST)) 802 364 1166
1308 {
1309 802 $self->shortline(
1310 line_ref => \$para_lines[$i],
1311 line_action_ref => \$para_line_action[$i],
1312 prev_ref => $prev_ref,
1313 prev_action_ref => $prev_action_ref,
1314 prev_line_len => $prev_line_len
1315 );
1316 }
1317 1166 ▶ if (!($self->{__mode} & ($PRE)))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"__mode"} & $HTML::TextToHTML::PRE) 1065 101 1166
1318 {
1319 1065 $self->caps(
1320 line_ref => \$para_lines[$i],
1321 line_action_ref => \$para_line_action[$i]
1322 );
1323 }
1324  
1325 # put the "prev" line in front of the first line
1326 1166 ▶ $para_lines[$i] = $prev . $para_lines[$i]
Branch: 1 branch
BranchTrueFalseTotal
if $i == 0 and not $prev =~ /^\s*$/ 301 865 1166
Condition100%3/3
$i == 0 and not $prev =~ /^\s*$/
!ll&&!rl&&r
81649301
MC/DC100%2/2
$i == 0 and not $prev =~ /^\s*$/
$i == 0 not $prev =~ /^\s*$/
Truth table100%3/3
A and not(B)
A= $i == 0B= not $prev =~ /^\s*$/
ABresult
0X0
100
111
1327 if ($i == 0 && ($prev !~ /^\s*$/));
1328 }
1329  
1330 # para action is the action of the last line of the para
1331 440 $para_action = $para_line_action[$#para_line_action];
1332 440 ▶ $para_action = $NONE if (!defined $para_action);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $para_action 57 383 440
1333  
1334 # push them on the done lines
1335 440 push @done_lines, @para_lines;
1336 440 @para_lines = ();
1337  
1338 }
1339 # now put the para back together as one string
1340 440 $para = join('', @done_lines);
1341  
1342 # if this is a paragraph, and we are in XHTML mode,
1343 # close an open paragraph.
1344 440 ▶ if ($self->{xhtml})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"xhtml"}) 367 73 440
1345 {
1346 367 my $open_tag = @{$self->{__tags}}[$#{$self->{__tags}}];
1347 367 ▶ if (defined $open_tag && $open_tag eq 'p')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $open_tag and $open_tag eq "p") 233 134 367
Condition100%3/3
defined $open_tag and $open_tag eq "p"
!ll&&!rl&&r
27107233
MC/DC100%2/2
defined $open_tag and $open_tag eq "p"
defined $open_tag $open_tag eq "p"
Truth table100%3/3
A and B
A= defined $open_tagB= $open_tag eq "p"
ABresult
0X0
100
111
1348 {
1349 233 $para .= $self->close_tag('p');
1350 }
1351 }
1352  
1353 440 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"unhyphenation"} and $para =~ /[^\W\d_]\-\n\s*[^\W\d_]/s and not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::MAILHEADER | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::BREAK)) 8 432 440
Condition66%4/6
$self->{"unhyphenation"} and $para =~ /[^\W\d_]\-\n\s*[^\W\d_]/s and not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::MAILHEADER | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::BREAK)
!ll&&!rl&&r
43208
$self->{"unhyphenation"} and $para =~ /[^\W\d_]\-\n\s*[^\W\d_]/s
!ll&&!rl&&r
04328
MC/DC33%1/3
$self->{"unhyphenation"} and $para =~ /[^\W\d_]\-\n\s*[^\W\d_]/s and not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::MAILHEADER | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::BREAK)
$self->{"unhyphenation"} $para =~ /[^\W\d_]\-\n\s*[^\W\d_]/s not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::MAILHEADER | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::BREAK)
Truth table50%2/4
A and B and not(C)
A= $self->{"unhyphenation"}B= $para =~ /[^\W\d_]\-\n\s*[^\W\d_]/sC= not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::MAILHEADER | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::BREAK)
ABCresult
0XX0
10X0
1100
1111
1354 $self->{unhyphenation}
1355  
1356 # ends in hyphen & next line starts w/letters
1357 && ($para =~ /[^\W\d_]\-\n\s*[^\W\d_]/s) && !(
1358 $self->{__mode} &
1359 ($PRE | $HEADER | $MAILHEADER | $TABLE | $BREAK)
1360 )
1361 )
1362 {
1363 8 $self->unhyphenate_para(\$para);
1364 }
1365 # chop trailing newlines for continuing lists and PRE
1366 440 ▶ if ( $self->{__mode} & $LIST
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__mode"} & $HTML::TextToHTML::LIST or $self->{"__mode"} & $HTML::TextToHTML::PRE) 86 354 440
Condition100%3/3
$self->{"__mode"} & $HTML::TextToHTML::LIST or $self->{"__mode"} & $HTML::TextToHTML::PRE
l!l&&r!l&&!r
6422354
MC/DC100%2/2
$self->{"__mode"} & $HTML::TextToHTML::LIST or $self->{"__mode"} & $HTML::TextToHTML::PRE
$self->{"__mode"} & $HTML::TextToHTML::LIST $self->{"__mode"} & $HTML::TextToHTML::PRE
Truth table100%3/3
A or B
A= $self->{"__mode"} & $HTML::TextToHTML::LISTB= $self->{"__mode"} & $HTML::TextToHTML::PRE
ABresult
1X1
011
000
1367 || $self->{__mode} & $PRE)
1368 {
1369 86 $para =~ s/\n$//g;
1370 }
1371 }
1372  
1373 # apply links and bold/italic/underline formatting
1374 440 ▶ if ($para !~ /^\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($para =~ /^\s*$/) 440 0 440
1375 {
1376 440 $self->apply_links(
1377 para_ref => \$para,
1378 para_action_ref => \$para_action
1379 );
1380 }
1381  
1382 # close any open lists if required to
1383 440 ▶ if ( $args{close_tags}
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"close_tags"} and $self->{"__mode"} & $HTML::TextToHTML::LIST) 1 439 440
Condition100%3/3
$args{"close_tags"} and $self->{"__mode"} & $HTML::TextToHTML::LIST
!ll&&!rl&&r
43361
MC/DC100%2/2
$args{"close_tags"} and $self->{"__mode"} & $HTML::TextToHTML::LIST
$args{"close_tags"} $self->{"__mode"} & $HTML::TextToHTML::LIST
Truth table100%3/3
A and B
A= $args{"close_tags"}B= $self->{"__mode"} & $HTML::TextToHTML::LIST
ABresult
0X0
100
111
1384 && $self->{__mode} & $LIST) # End all lists
1385 {
1386 $self->endlist(
1387 num_lists => $self->{__listnum},
1388 1 prev_ref => \$para,
1389 line_action_ref => \$para_action
1390 );
1391 }
1392 # close any open tags
1393 440 ▶ if ($args{close_tags} && $self->{xhtml})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"close_tags"} and $self->{"xhtml"}) 7 433 440
Condition66%2/3
$args{"close_tags"} and $self->{"xhtml"}
!ll&&!rl&&r
43307
MC/DC50%1/2
$args{"close_tags"} and $self->{"xhtml"}
$args{"close_tags"} $self->{"xhtml"}
Truth table66%2/3
A and B
A= $args{"close_tags"}B= $self->{"xhtml"}
ABresult
0X0
100
111
1394 {
1395 7 ▶ while (@{$self->{__tags}})
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"__tags"};}) 0 7 7
1396 {
1397 0 $para .= $self->close_tag('');
1398 }
1399 }
1400  
1401 # convert remaining Microsoft character codes into sensible HTML
1402 440 ▶ if ($self->{demoronize} && !$self->{eight_bit_clean})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"demoronize"} and not $self->{"eight_bit_clean"}) 433 7 440
Condition66%2/3
$self->{"demoronize"} and not $self->{"eight_bit_clean"}
!ll&&!rl&&r
07433
MC/DC50%1/2
$self->{"demoronize"} and not $self->{"eight_bit_clean"}
$self->{"demoronize"} not $self->{"eight_bit_clean"}
Truth table66%2/3
A and not(B)
A= $self->{"demoronize"}B= not $self->{"eight_bit_clean"}
ABresult
0X0
100
111
1403 {
1404 433 $para = demoronize_code($para);
1405 }
1406 # All the matching and formatting is done. Now we can
1407 # replace non-ASCII characters with character entities.
1408 440 ▶ if (!$self->{eight_bit_clean})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"eight_bit_clean"}) 433 7 440
1409 {
1410 433 my @chars = split(//, $para);
1411 433 foreach $_ (@chars)
1412 {
1413 100265 ▶ $_ = $char_entities{$_} if defined($char_entities{$_});
Branch: 1 branch
BranchTrueFalseTotal
if defined $HTML::TextToHTML::char_entities{$_} 78 100187 100265
1414 }
1415 433 $para = join('', @chars);
1416 }
1417  
1418 440 $self->{__prev_para_action} = $para_action;
1419  
1420 440 return $para;
1421 } # process_para
1422  
1423 =head2 txt2html
1424  
1425 $conv->txt2html(%args);
1426  
1427 Convert a text file to HTML. Takes a hash of arguments. See
1428 L</OPTIONS> for the possible values of the arguments. Arguments which
1429 have already been set with B<new> or B<args> will remain as they are,
1430 unless they are overridden.
1431  
1432 =cut
1433  
1434 sub txt2html ($;$)
1435 38 ▶{
Subroutine txt2html: called CC=38 SCAR=43.7
Pod documented
1436 38 my $self = shift;
1437  
1438 38 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 38 0 38
1439 {
1440 38 $self->args(@_);
1441 }
1442  
1443 38 $self->do_init_call();
1444  
1445 38 my $outhandle;
1446 my $outhandle_needs_closing;
1447  
1448 # set up the output
1449 38 ▶ if ($self->{outhandle})
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'outhandle'}) { } 1 37 38
elsif ($self->{'outfile'} eq '-') { } 0 37 37
1450 {
1451 1 $outhandle = $self->{outhandle};
1452 1 $outhandle_needs_closing = 1;
1453 }
1454 elsif ($self->{outfile} eq "-")
1455 {
1456 0 $outhandle = *STDOUT;
1457 0 $outhandle_needs_closing = 0;
1458 }
1459 else
1460 {
1461 open($outhandle, "> " . $self->{outfile})
1462 37 ▶ || die "Error: unable to open ", $self->{outfile}, ": $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $outhandle, '> ' . $self->{"outfile"} or die "Error: unable to open ", $self->{"outfile"}, ": $!\n" 37 0 37
1463 37 $outhandle_needs_closing = 1;
1464 }
1465  
1466 # slurp up a paragraph at a time, a file at a time
1467 38 local $/ = "";
1468 38 my $para = '';
1469 38 my $count = 0;
1470 38 my $print_count = 0;
1471 38 my @sources = ();
1472 38 my $source_type;
1473 38 ▶ if ($self->{infile} and @{$self->{infile}})
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'infile'} and @{$self->{'infile'};}) { } 36 2 38
elsif ($self->{'inhandle'} and @{$self->{'inhandle'};}) { } 2 0 2
elsif ($self->{'instring'} and @{$self->{'instring'};}) { } 0 0 0
Condition66%2/3
$self->{"infile"} and @{$self->{"infile"};}
!ll&&!rl&&r
0236
MC/DC50%1/2
$self->{"infile"} and @{$self->{"infile"};}
$self->{"infile"} @{$self->{"infile"};}
Truth table66%2/3
A and B
A= $self->{"infile"}B= @{$self->{"infile"};}
ABresult
0X0
100
111
1474 {
1475 36 @sources = @{$self->{infile}};
1476 36 $source_type = 'file';
1477 }
1478 2 ▶ elsif ($self->{inhandle} and @{$self->{inhandle}})
Condition33%1/3
$self->{"inhandle"} and @{$self->{"inhandle"};}
!ll&&!rl&&r
002
MC/DC0%0/2
$self->{"inhandle"} and @{$self->{"inhandle"};}
$self->{"inhandle"} @{$self->{"inhandle"};}
Truth table33%1/3
A and B
A= $self->{"inhandle"}B= @{$self->{"inhandle"};}
ABresult
0X0
100
111
1479 {
1480 2 @sources = @{$self->{inhandle}};
1481 2 $source_type = 'filehandle';
1482 }
1483 0 ▶ elsif ($self->{instring} and @{$self->{instring}})
Condition0%0/3
$self->{"instring"} and @{$self->{"instring"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"instring"} and @{$self->{"instring"};}
$self->{"instring"} @{$self->{"instring"};}
Truth table0%0/3
A and B
A= $self->{"instring"}B= @{$self->{"instring"};}
ABresult
0X0
100
111
1484 {
1485 0 @sources = @{$self->{instring}};
1486 0 $source_type = 'string';
1487 }
1488 38 my $inhandle;
1489 38 my $inhandle_needs_closing = 0;
1490 38 foreach my $source (@sources)
1491 {
1492 38 $inhandle = undef;
1493 38 ▶ if ($source_type eq 'file')
Branch: 2 branches
BranchTrueFalseTotal
if ($source_type eq 'file') { } 36 2 38
elsif ($source_type eq 'filehandle') { } 2 0 2
1494 {
1495 36 ▶ if (!$source or $source eq '-')
Branch: 1 branch
BranchTrueFalseTotal
if (not $source or $source eq '-') { } 0 36 36
Condition33%1/3
not $source or $source eq "-"
l!l&&r!l&&!r
0036
MC/DC0%0/2
not $source or $source eq "-"
not $source $source eq "-"
Truth table33%1/3
not(A) or B
A= not $sourceB= $source eq "-"
ABresult
1X1
011
000
1496 {
1497 0 $inhandle = *STDIN;
1498 0 $inhandle_needs_closing = 0;
1499 }
1500 else
1501 {
1502 36 ▶ if (-f $source && open($inhandle, $source))
Branch: 1 branch
BranchTrueFalseTotal
if (-f $source and open $inhandle, $source) { } 36 0 36
Condition33%1/3
-f $source and open $inhandle, $source
!ll&&!rl&&r
0036
MC/DC0%0/2
-f $source and open $inhandle, $source
-f $source open $inhandle, $source
Truth table33%1/3
A and B
A= -f $sourceB= open $inhandle, $source
ABresult
0X0
100
111
1503 {
1504 36 $inhandle_needs_closing = 1;
1505 }
1506 else # error
1507 {
1508 0 warn "Could not open $source\n";
1509 0 next;
1510 }
1511 }
1512 }
1513 elsif ($source_type eq 'filehandle')
1514 {
1515 2 $inhandle = $source;
1516 2 $inhandle_needs_closing = 1;
1517 }
1518 38 ▶ if ($source_type eq 'string')
Branch: 1 branch
BranchTrueFalseTotal
if ($source_type eq 'string') { } 0 38 38
1519 {
1520 # process the string
1521 0 $para = $_;
1522 0 $para =~ s/\n$//; # trim the endline
1523 0 ▶ if ($count == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 0) 0 0 0
1524 {
1525 0 $self->do_file_start($outhandle, $para);
1526 }
1527 0 $self->{__done_with_sect_link} = [];
1528 0 $para = $self->process_chunk($para, close_tags => 0);
1529 0 print $outhandle $para, "\n";
1530 0 $print_count++;
1531 0 $count++;
1532 }
1533 else # file or filehandle
1534 {
1535 38 ▶ while (<$inhandle>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $inhandle)) 339 38 377
1536 {
1537 339 $para = $_;
1538 339 $para =~ s/\n$//; # trim the endline
1539 339 ▶ if ($count == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 0) 34 305 339
1540 {
1541 34 $self->do_file_start($outhandle, $para);
1542 }
1543 339 $self->{__done_with_sect_link} = [];
1544 339 $para = $self->process_chunk($para, close_tags => 0);
1545 339 print $outhandle $para, "\n";
1546 339 $print_count++;
1547 339 $count++;
1548 }
1549 38 ▶ if ($inhandle_needs_closing)
Branch: 1 branch
BranchTrueFalseTotal
if ($inhandle_needs_closing) 38 0 38
1550 {
1551 38 close($inhandle);
1552 }
1553 }
1554 } # for each file
1555  
1556 38 $self->{__prev} = "";
1557 38 ▶ if ($self->{__mode} & $LIST) # End all lists
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__mode"} & $HTML::TextToHTML::LIST) 6 32 38
1558 {
1559 $self->endlist(
1560 num_lists => $self->{__listnum},
1561 prev_ref => \$self->{__prev},
1562 line_action_ref => \$self->{__line_action}
1563 6 );
1564 }
1565 38 print $outhandle $self->{__prev};
1566  
1567 # end open preformats
1568 38 ▶ if ($self->{__mode} & $PRE)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__mode"} & $HTML::TextToHTML::PRE) 2 36 38
1569 {
1570 2 my $tag = $self->close_tag('pre');
1571 2 print $outhandle $tag;
1572 }
1573  
1574 # close all open tags
1575 38 ▶ if ( $self->{xhtml}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"xhtml"} and not $self->{"extract"} and @{$self->{"__tags"};}) 12 26 38
Condition100%6/6
$self->{"xhtml"} and not $self->{"extract"} and @{$self->{"__tags"};}
!ll&&!rl&&r
25112
$self->{"xhtml"} and not $self->{"extract"}
!ll&&!rl&&r
32213
MC/DC100%3/3
$self->{"xhtml"} and not $self->{"extract"} and @{$self->{"__tags"};}
$self->{"xhtml"} not $self->{"extract"} @{$self->{"__tags"};}
Truth table100%4/4
A and not(B) and C
A= $self->{"xhtml"}B= not $self->{"extract"}C= @{$self->{"__tags"};}
ABCresult
0XX0
10X0
1100
1111
1576 && !$self->{extract}
1577 13 && @{$self->{__tags}})
1578 {
1579 12 ▶ if ($DictDebug & 8)
Branch: 1 branch
BranchTrueFalseTotal
if ($HTML::TextToHTML::DictDebug & 8) 0 12 12
1580 {
1581 0 print STDERR "closing all tags at end\n";
1582 }
1583 # close any open tags (until we get to the body)
1584 12 my $open_tag = @{$self->{__tags}}[$#{$self->{__tags}}];
1585 12 ▶ while (@{$self->{__tags}}
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"__tags"};} and $open_tag ne "body" and $open_tag ne "html") 0 12 12
Condition33%2/6
@{$self->{"__tags"};} and $open_tag ne "body" and $open_tag ne "html"
!ll&&!rl&&r
1200
@{$self->{"__tags"};} and $open_tag ne "body"
!ll&&!rl&&r
0120
MC/DC0%0/3
@{$self->{"__tags"};} and $open_tag ne "body" and $open_tag ne "html"
@{$self->{"__tags"};} $open_tag ne "body" $open_tag ne "html"
Truth table25%1/4
A and B and C
A= @{$self->{"__tags"};}B= $open_tag ne "body"C= $open_tag ne "html"
ABCresult
0XX0
10X0
1100
1111
1586 && $open_tag ne 'body'
1587 && $open_tag ne 'html')
1588 {
1589 0 print $outhandle $self->close_tag('');
1590 0 $open_tag = @{$self->{__tags}}[$#{$self->{__tags}}];
1591 }
1592 12 print $outhandle "\n";
1593 }
1594  
1595 38 ▶ if ($self->{append_file})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"append_file"}) 2 36 38
1596 {
1597 2 ▶ if (-r $self->{append_file})
Branch: 1 branch
BranchTrueFalseTotal
if (-r $self->{'append_file'}) { } 2 0 2
1598 {
1599 2 open(APPEND, $self->{append_file});
1600 2 ▶ while (<APPEND>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline APPEND)) 2 2 4
1601 {
1602 2 print $outhandle $_;
1603 2 $print_count++;
1604 }
1605 2 close(APPEND);
1606 }
1607 else
1608 {
1609 print STDERR "Can't find or read file ", $self->{append_file},
1610 0 " to append.\n";
1611 }
1612 }
1613  
1614 # print the closing tags (if we have printed stuff at all)
1615 38 ▶ if ($print_count && !$self->{extract})
Branch: 1 branch
BranchTrueFalseTotal
if ($print_count and not $self->{"extract"}) 13 25 38
Condition100%3/3
$print_count and not $self->{"extract"}
!ll&&!rl&&r
42113
MC/DC100%2/2
$print_count and not $self->{"extract"}
$print_count not $self->{"extract"}
Truth table100%3/3
A and not(B)
A= $print_countB= not $self->{"extract"}
ABresult
0X0
100
111
1616 {
1617 13 print $outhandle $self->close_tag('body'), "\n";
1618 13 print $outhandle $self->close_tag('html'), "\n";
1619 }
1620 38 ▶ if ($outhandle_needs_closing)
Branch: 1 branch
BranchTrueFalseTotal
if ($outhandle_needs_closing) 38 0 38
1621 {
1622 38 close($outhandle);
1623 }
1624 38 return 1;
1625 }
1626  
1627 =head1 PRIVATE METHODS
1628  
1629 These are methods used internally, only of interest to developers.
1630  
1631 =cut
1632  
1633 #---------------------------------------------------------------#
1634 # Init-related subroutines
1635  
1636 =head2 init_our_data
1637  
1638 $self->init_our_data();
1639  
1640 Initializes the internal object data.
1641  
1642 =cut
1643 sub init_our_data ($)
1644 26 ▶{
Subroutine init_our_data: called CC=2 SCAR=6.9
Pod documented
1645 26 my $self = shift;
1646  
1647 #
1648 # All the options, in alphabetical order
1649 #
1650 26 $self->{append_file} = '';
1651 26 $self->{append_head} = '';
1652 26 $self->{body_deco} = '';
1653 26 $self->{bullets} = '-=o*\267';
1654 26 $self->{bullets_ordered} = '';
1655 26 $self->{bold_delimiter} = '#';
1656 26 $self->{caps_tag} = 'STRONG';
1657 26 $self->{custom_heading_regexp} = [];
1658 $self->{default_link_dict} =
1659 26 ▶ ($ENV{HOME} ? "$ENV{HOME}/.txt2html.dict" : '.txt2html.dict');
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'HOME'} ? : 26 0 26
1660 26 $self->{doctype} = '-//W3C//DTD HTML 4.01//EN"
1661 "http://www.w3.org/TR/html4/strict.dtd';
1662 26 $self->{demoronize} = 1;
1663 26 $self->{eight_bit_clean} = 0;
1664 26 $self->{escape_HTML_chars} = 1;
1665 26 $self->{explicit_headings} = 0;
1666 26 $self->{extract} = 0;
1667 26 $self->{hrule_min} = 4;
1668 26 $self->{indent_width} = 2;
1669 26 $self->{indent_par_break} = 0;
1670 26 $self->{infile} = [];
1671 26 $self->{inhandle} = [];
1672 26 $self->{instring} = [];
1673 26 $self->{italic_delimiter} = '*';
1674 26 $self->{links_dictionaries} = [];
1675 26 $self->{link_only} = 0;
1676 26 $self->{lower_case_tags} = 0;
1677 26 $self->{mailmode} = 0;
1678 26 $self->{make_anchors} = 1;
1679 26 $self->{make_links} = 1;
1680 26 $self->{make_tables} = 0;
1681 26 $self->{min_caps_length} = 3;
1682 26 $self->{outfile} = '-';
1683 26 $self->{par_indent} = 2;
1684 26 $self->{preformat_trigger_lines} = 2;
1685 26 $self->{endpreformat_trigger_lines} = 2;
1686 26 $self->{preformat_start_marker} = "^(:?(:?&lt;)|<)PRE(:?(:?&gt;)|>)\$";
1687 26 $self->{preformat_end_marker} = "^(:?(:?&lt;)|<)/PRE(:?(:?&gt;)|>)\$";
1688 26 $self->{preformat_whitespace_min} = 5;
1689 26 $self->{prepend_file} = '';
1690 26 $self->{preserve_indent} = 0;
1691 26 $self->{short_line_length} = 40;
1692 26 $self->{style_url} = '';
1693 26 $self->{tab_width} = 8;
1694 $self->{table_type} = {
1695 26 ALIGN => 1,
1696 PGSQL => 1,
1697 BORDER => 1,
1698 DELIM => 1,
1699 };
1700 26 $self->{title} = '';
1701 26 $self->{titlefirst} = 0;
1702 26 $self->{underline_delimiter} = '_';
1703 26 $self->{underline_length_tolerance} = 1;
1704 26 $self->{underline_offset_tolerance} = 1;
1705 26 $self->{unhyphenation} = 1;
1706 26 $self->{use_mosaic_header} = 0;
1707 26 $self->{use_preformat_marker} = 0;
1708 26 $self->{xhtml} = 1;
1709  
1710 # accumulation variables
1711 26 $self->{__file} = ""; # Current file being processed
1712 26 $self->{__heading_styles} = {};
1713 26 $self->{__num_heading_styles} = 0;
1714 26 $self->{__links_table} = {};
1715 26 $self->{__links_table_order} = [];
1716 26 $self->{__links_table_patterns} = {};
1717 26 $self->{__search_patterns} = [];
1718 26 $self->{__repl_code} = [];
1719 26 $self->{__prev_para_action} = 0;
1720 26 $self->{__non_header_anchor} = 0;
1721 26 $self->{__mode} = 0;
1722 26 $self->{__listnum} = 0;
1723 26 $self->{__list_nice_indent} = "";
1724 26 $self->{__list_indent} = [];
1725  
1726 26 $self->{__call_init_done} = 0;
1727  
1728 #
1729 # The global links data
1730 #
1731 26 my $system_dict = <<'EOT';
1732 #
1733 # Global links dictionary file for HTML::TextToHTML
1734 # http://www.katspace.com/tools/text_to_html
1735 # http://txt2html.sourceforge.net/
1736 # based on links dictionary for Seth Golub's txt2html
1737 # http://www.aigeek.com/txt2html/
1738 #
1739 # This dictionary contains some patterns for converting obvious URLs,
1740 # ftp sites, hostnames, email addresses and the like to hrefs.
1741 #
1742 # Original adapted from the html.pl package by Oscar Nierstrasz in
1743 # the Software Archive of the Software Composition Group
1744 # http://iamwww.unibe.ch/~scg/Src/
1745 #
1746  
1747 # Some people even like to mark the URL label explicitly <URL:foo:label>
1748 /&lt;URL:([-\w\.\/:~_\@]+):([a-zA-Z0-9'() ]+)&gt;/ -h-> <A HREF="$1">$2</A>
1749  
1750 # Some people like to mark URLs explicitly <URL:foo>
1751 /&lt;URL:\s*(\S+?)\s*&gt;/ -h-> <A HREF="$1">$1</A>
1752  
1753 # <http://site>
1754 /&lt;(http:\S+?)\s*&gt;/ -h-> &lt;<A HREF="$1">$1</A>&gt;
1755  
1756 # Urls: <service>:<rest-of-url>
1757  
1758 |snews:[\w\.]+| -> $&
1759 |news:[\w\.]+| -> $&
1760 |nntp:[\w/\.:+\-]+| -> $&
1761 |http:[\w/\.:\@+\-~\%#?=&;,]+[\w/]| -> $&
1762 |shttp:[\w/\.:+\-~\%#?=&;,]+| -> $&
1763 |https:[\w/\.:+\-~\%#?=&;,]+| -> $&
1764 |file:[\w/\.:+\-]+| -> $&
1765 |ftp:[\w/\.:+\-]+| -> $&
1766 |wais:[\w/\.:+\-]+| -> $&
1767 |gopher:[\w/\.:+\-]+| -> $&
1768 |telnet:[\w/\@\.:+\-]+| -> $&
1769  
1770  
1771 # catch some newsgroups to avoid confusion with sites:
1772 |([^\w\-/\.:\@>])(alt\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1773 |([^\w\-/\.:\@>])(bionet\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1774 |([^\w\-/\.:\@>])(bit\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1775 |([^\w\-/\.:\@>])(biz\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1776 |([^\w\-/\.:\@>])(clari\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1777 |([^\w\-/\.:\@>])(comp\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1778 |([^\w\-/\.:\@>])(gnu\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1779 |([^\w\-/\.:\@>])(humanities\.[\w\.+\-]+[\w+\-]+)|
1780 -h-> $1<A HREF="news:$2">$2</A>
1781 |([^\w\-/\.:\@>])(k12\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1782 |([^\w\-/\.:\@>])(misc\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1783 |([^\w\-/\.:\@>])(news\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1784 |([^\w\-/\.:\@>])(rec\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1785 |([^\w\-/\.:\@>])(soc\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1786 |([^\w\-/\.:\@>])(talk\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1787 |([^\w\-/\.:\@>])(us\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1788 |([^\w\-/\.:\@>])(ch\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1789 |([^\w\-/\.:\@>])(de\.[\w\.+\-]+[\w+\-]+)| -h-> $1<A HREF="news:$2">$2</A>
1790  
1791 # FTP locations (with directory):
1792 # anonymous@<site>:<path>
1793 |(anonymous\@)([[:alpha:]][\w\.+\-]+\.[[:alpha:]]{2,}):(\s*)([\w\d+\-/\.]+)|
1794 -h-> $1<A HREF="ftp://$2/$4">$2:$4</A>$3
1795  
1796 # ftp@<site>:<path>
1797 |(ftp\@)([[:alpha:]][\w\.+\-]+\.[[:alpha:]]{2,}):(\s*)([\w\d+\-/\.]+)|
1798 -h-> $1<A HREF="ftp://$2/$4">$2:$4</A>$3
1799  
1800 # Email address
1801 |[[:alnum:]_\+\-\.]+\@([[:alnum:]][\w\.+\-]+\.[[:alpha:]]{2,})|
1802 -> mailto:$&
1803  
1804 # <site>:<path>
1805 |([^\w\-/\.:\@>])([[:alpha:]][\w\.+\-]+\.[[:alpha:]]{2,}):(\s*)([\w\d+\-/\.]+)|
1806 -h-> $1<A HREF="ftp://$2/$4">$2:$4</A>$3
1807  
1808 # NB: don't confuse an http server with a port number for
1809 # an FTP location!
1810 # internet number version: <internet-num>:<path>
1811 |([^\w\-/\.:\@])(\d{2,}\.\d{2,}\.\d+\.\d+):([\w\d+\-/\.]+)|
1812 -h-> $1<A HREF="ftp://$2/$3">$2:$3</A>
1813  
1814 # telnet <site> <port>
1815 |telnet ([[:alpha:]][\w+\-]+(\.[\w\.+\-]+)+\.[[:alpha:]]{2,})\s+(\d{2,4})|
1816 -h-> telnet <A HREF="telnet://$1:$3/">$1 $3</A>
1817  
1818 # ftp <site>
1819 |ftp ([[:alpha:]][\w+\-]+(\.[\w\.+\-]+)+\.[[:alpha:]]{2,})|
1820 -h-> ftp <A HREF="ftp://$1/">$1</A>
1821  
1822 # host with "ftp" in the machine name
1823 |\b([[:alpha:]][\w])*ftp[\w]*(\.[\w+\-]+){2,}| -h-> ftp <A HREF="ftp://$&/">$&</A>
1824  
1825 # ftp.foo.net/blah/
1826 |ftp(\.[\w\@:-]+)+/\S+| -> ftp://$&
1827  
1828 # www.thehouse.org/txt2html/
1829 |www(\.[\w\@:-]+)+/\S+| -> http://$&
1830  
1831 # host with "www" in the machine name
1832 |\b([[:alpha:]][\w])*www[\w]*(\.[\w+\-]+){2,}| -> http://$&/
1833  
1834 # <site> <port>
1835 |([[:alpha:]][\w+\-]+\.[\w+\-]+\.[[:alpha:]]{2,})\s+(\d{2,4})|
1836 -h-> <A HREF="telnet://$1:$2/">$1 $2</A>
1837  
1838 # just internet numbers with port:
1839 |([^\w\-/\.:\@])(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\d{1,4})|
1840 -h-> $1<A HREF="telnet://$2:$3">$2 $3</A>
1841  
1842 # just internet numbers:
1843 |([^\w\-/\.:\@])(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|
1844 -h-> $1<A HREF="telnet://$2">$2</A>
1845  
1846 # RFCs
1847 /RFC ?(\d+)/ -i-> http://www.cis.ohio-state.edu/rfc/rfc$1.txt
1848  
1849 # Mark _underlined stuff_ as <U>underlined stuff</U>
1850 # Don't mistake variable names for underlines, and
1851 # take account of possible trailing punctuation
1852 #/([ \t\n])_([[:alpha:]][[:alnum:]\s-]*[[:alpha:]])_([\s\.;:,\!\?])/ -h-> $1<U>$2</U>$3
1853  
1854 # Seth and his amazing conversion program :-)
1855  
1856 "Seth Golub" -o-> http://www.aigeek.com/
1857 "txt2html" -o-> http://txt2html.sourceforge.net/
1858  
1859 # Kathryn and her amazing modules 8-)
1860 "Kathryn Andersen" -o-> http://www.katspace.com/
1861 "HTML::TextToHTML" -o-> http://www.katspace.com/tools/text_to_html/
1862 "hypertoc" -o-> http://www.katspace.com/tools/hypertoc/
1863 "HTML::GenToc" -o-> http://www.katspace.com/tools/hypertoc/
1864  
1865 # End of global dictionary
1866 EOT
1867  
1868 # pre-parse the above data by removing unwanted lines
1869 # skip lines that start with '#'
1870 26 $system_dict =~ s/^\#.*$//mg;
1871 # skip lines that end with unescaped ':'
1872 26 $system_dict =~ s/^.*[^\\]:\s*$//mg;
1873  
1874 26 $self->{__global_links_data} = $system_dict;
1875  
1876 } # init_our_data
1877  
1878 #---------------------------------------------------------------#
1879 # txt2html-related subroutines
1880  
1881 =head2 deal_with_options
1882  
1883 $self->deal_with_options();
1884  
1885 do extra processing related to particular options
1886  
1887 =cut
1888 sub deal_with_options ($)
1889 96 ▶{
Subroutine deal_with_options: called CC=17 SCAR=41.5
Pod documented
1890 96 my $self = shift;
1891  
1892 96 ▶ if (!$self->{make_links})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"make_links"}) 0 96 96
1893 {
1894 0 $self->{'links_dictionaries'} = 0;
1895 }
1896 96 ▶ if ($self->{append_file})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"append_file"}) 4 92 96
1897 {
1898 4 ▶ if (!-r $self->{append_file})
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $self->{"append_file"}) 0 4 4
1899 {
1900 0 print STDERR "Can't find or read ", $self->{append_file}, "\n";
1901 0 $self->{append_file} = '';
1902 }
1903 }
1904 96 ▶ if ($self->{prepend_file})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"prepend_file"}) 0 96 96
1905 {
1906 0 ▶ if (!-r $self->{prepend_file})
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $self->{"prepend_file"}) 0 0 0
1907 {
1908 0 print STDERR "Can't find or read ", $self->{prepend_file}, "\n";
1909 0 $self->{'prepend_file'} = '';
1910 }
1911 }
1912 96 ▶ if ($self->{append_head})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"append_head"}) 0 96 96
1913 {
1914 0 ▶ if (!-r $self->{append_head})
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $self->{"append_head"}) 0 0 0
1915 {
1916 0 print STDERR "Can't find or read ", $self->{append_head}, "\n";
1917 0 $self->{'append_head'} = '';
1918 }
1919 }
1920  
1921 96 ▶ if (!$self->{outfile})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"outfile"}) 0 96 96
1922 {
1923 0 $self->{'outfile'} = "-";
1924 }
1925  
1926 $self->{'preformat_trigger_lines'} = 0
1927 96 ▶ if ($self->{preformat_trigger_lines} < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"preformat_trigger_lines"} < 0 0 96 96
1928 $self->{'preformat_trigger_lines'} = 2
1929 96 ▶ if ($self->{preformat_trigger_lines} > 2);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"preformat_trigger_lines"} > 2 0 96 96
1930  
1931 $self->{'endpreformat_trigger_lines'} = 1
1932 96 ▶ if ($self->{preformat_trigger_lines} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"preformat_trigger_lines"} == 0 0 96 96
1933 $self->{'endpreformat_trigger_lines'} = 0
1934 96 ▶ if ($self->{endpreformat_trigger_lines} < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"endpreformat_trigger_lines"} < 0 0 96 96
1935 $self->{'endpreformat_trigger_lines'} = 2
1936 96 ▶ if ($self->{endpreformat_trigger_lines} > 2);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"endpreformat_trigger_lines"} > 2 0 96 96
1937  
1938 $self->{__preformat_enabled} =
1939 (($self->{endpreformat_trigger_lines} != 0)
1940 96 ▶ || $self->{use_preformat_marker});
Condition33%1/3
$self->{'endpreformat_trigger_lines'} != 0 || $self->{'use_preformat_marker'}
l!l&&r!l&&!r
9600
MC/DC0%0/2
$self->{'endpreformat_trigger_lines'} != 0 || $self->{'use_preformat_marker'}
$self->{'endpreformat_trigger_lines'} != 0 $self->{'use_preformat_marker'}
Truth table33%1/3
A || B
A= $self->{'endpreformat_trigger_lines'} != 0B= $self->{'use_preformat_marker'}
ABresult
1X1
011
000
1941  
1942 96 ▶ if ($self->{use_mosaic_header})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"use_mosaic_header"}) 0 96 96
1943 {
1944 0 my $num_heading_styles = 0;
1945 0 my %heading_styles = ();
1946 0 $heading_styles{"*"} = ++$num_heading_styles;
1947 0 $heading_styles{"="} = ++$num_heading_styles;
1948 0 $heading_styles{"+"} = ++$num_heading_styles;
1949 0 $heading_styles{"-"} = ++$num_heading_styles;
1950 0 $heading_styles{"~"} = ++$num_heading_styles;
1951 0 $heading_styles{"."} = ++$num_heading_styles;
1952 0 $self->{__heading_styles} = \%heading_styles;
1953 0 $self->{__num_heading_styles} = $num_heading_styles;
1954 }
1955 # XHTML implies lower case
1956 96 ▶ $self->{'lower_case_tags'} = 1 if ($self->{xhtml});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"xhtml"} 89 7 96
1957 }
1958  
1959 =head2 escape
1960  
1961 $newtext = escape($text);
1962  
1963 Escape & < and >
1964  
1965 =cut
1966 sub escape ($)
1967 2835 ▶{
Subroutine escape: called CC=1 SCAR=0.0
Pod documented
1968 2835 my ($text) = @_;
1969 2835 $text =~ s/&/&amp;/g;
1970 2835 $text =~ s/>/&gt;/g;
1971 2835 $text =~ s/</&lt;/g;
1972 2835 return $text;
1973 }
1974  
1975 =head2 demoronize_char
1976  
1977 $newtext = demoronize_char($text);
1978  
1979 Convert Microsoft character entities into characters.
1980  
1981 Added by Alan Jackson, alan at ajackson dot org, and based
1982 on the demoronize script by John Walker, http://www.fourmilab.ch/
1983  
1984 =cut
1985 sub demoronize_char($)
1986 440 ▶{
Subroutine demoronize_char: called CC=1 SCAR=0.0
Pod documented
1987 440 my $s = shift;
1988 # Map strategically incompatible non-ISO characters in the
1989 # range 0x82 -- 0x9F into plausible substitutes where
1990 # possible.
1991  
1992 440 $s =~ s/\x82/,/g;
1993 440 $s =~ s/\x84/,,/g;
1994 440 $s =~ s/\x85/.../g;
1995  
1996 440 $s =~ s/\x88/^/g;
1997  
1998 440 $s =~ s/\x8B/</g;
1999 440 $s =~ s/\x8C/Oe/g;
2000  
2001 440 $s =~ s/\x91/`/g;
2002 440 $s =~ s/\x92/'/g;
2003 440 $s =~ s/\x93/"/g;
2004 440 $s =~ s/\x94/"/g;
2005 440 $s =~ s/\x95/*/g;
2006 440 $s =~ s/\x96/-/g;
2007 440 $s =~ s/\x97/--/g;
2008  
2009 440 $s =~ s/\x9B/>/g;
2010 440 $s =~ s/\x9C/oe/g;
2011  
2012 440 return $s;
2013 }
2014  
2015 =head2 demoronize_code
2016  
2017 $newtext = demoronize_code($text);
2018  
2019 convert Microsoft character entities into HTML code
2020  
2021 =cut
2022 sub demoronize_code($)
2023 433 ▶{
Subroutine demoronize_code: called CC=1 SCAR=0.0
Pod documented
2024 433 my $s = shift;
2025 # Map strategically incompatible non-ISO characters in the
2026 # range 0x82 -- 0x9F into plausible substitutes where
2027 # possible.
2028  
2029 433 $s =~ s-\x83-<em>f</em>-g;
2030  
2031 433 $s =~ s-\x98-<sup>~</sup>-g;
2032 433 $s =~ s-\x99-<sup>TM</sup>-g;
2033  
2034 433 return $s;
2035 }
2036  
2037 =head2 get_tag
2038  
2039 $tag = $self->get_tag($in_tag);
2040  
2041 $tag = $self->get_tag($in_tag,
2042 tag_type=>TAG_START,
2043 inside_tag=>'');
2044  
2045 output the tag wanted (add the <> and the / if necessary)
2046 - output in lower or upper case
2047 - do tag-related processing
2048 options:
2049 tag_type=>TAG_START | tag_type=>TAG_END | tag_type=>TAG_EMPTY
2050 (default start)
2051 inside_tag=>string (default empty)
2052  
2053 =cut
2054 sub get_tag ($$;%)
2055 3522 ▶{
Subroutine get_tag: called CC=29 SCAR=33.9
Pod documented
2056 3522 my $self = shift;
2057 3522 my $in_tag = shift;
2058 3522 my %args = (
2059 tag_type => TAG_START,
2060 inside_tag => '',
2061 @_
2062 );
2063 3522 my $inside_tag = $args{inside_tag};
2064  
2065 3522 my $open_tag = @{$self->{__tags}}[$#{$self->{__tags}}];
2066 3522 ▶ if (!defined $open_tag)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $open_tag) 116 3406 3522
2067 {
2068 116 $open_tag = '';
2069 }
2070 # close any open tags that need closing
2071 # Note that we only have to check for the structural tags we make,
2072 # not every possible HTML tag
2073 3522 my $tag_prefix = '';
2074 3522 ▶ if ($self->{xhtml})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"xhtml"}) 3219 303 3522
2075 {
2076 3219 ▶ if ( $open_tag eq 'p'
Branch: 7 branches
BranchTrueFalseTotal
if ($open_tag eq 'p' and $in_tag eq 'p' and $args{'tag_type'} != 2) { } 14 3205 3219
elsif ($open_tag eq 'p' and $in_tag =~ /^(hr|ul|ol|dl|pre|table|h)/) { } 9 3196 3205
elsif ($open_tag eq 'li' and $in_tag eq 'li' and $args{'tag_type'} != 2) { } 70 3126 3196
elsif ($open_tag eq 'li' and $in_tag =~ /^(ul|ol)$/ and $args{'tag_type'} == 2) { } 47 3079 3126
elsif ($open_tag eq 'dt' and $in_tag eq 'dd' and $args{'tag_type'} != 2) { } 0 3079 3079
elsif ($open_tag eq 'dd' and $in_tag eq 'dt' and $args{'tag_type'} != 2) { } 2 3077 3079
elsif ($open_tag eq 'dd' and $in_tag eq 'dl' and $args{'tag_type'} == 2) { } 5 6144 6149
Condition100%6/6
$open_tag eq "p" and $in_tag eq "p" and $args{"tag_type"} != 2
!ll&&!rl&&r
3202314
$open_tag eq "p" and $in_tag eq "p"
!ll&&!rl&&r
243976317
MC/DC100%3/3
$open_tag eq "p" and $in_tag eq "p" and $args{"tag_type"} != 2
$open_tag eq "p" $in_tag eq "p" $args{"tag_type"} != 2
Truth table100%4/4
A and B and C
A= $open_tag eq "p"B= $in_tag eq "p"C= $args{"tag_type"} != 2
ABCresult
0XX0
10X0
1100
1111
2077 and $in_tag eq 'p'
2078 and $args{tag_type} != TAG_END)
2079 {
2080 14 $tag_prefix = $self->close_tag('p');
2081 }
2082 ▶ elsif ( $open_tag eq 'p'
Condition100%3/3
$open_tag eq "p" and $in_tag =~ /^(hr|ul|ol|dl|pre|table|h)/
!ll&&!rl&&r
24397579
MC/DC100%2/2
$open_tag eq "p" and $in_tag =~ /^(hr|ul|ol|dl|pre|table|h)/
$open_tag eq "p" $in_tag =~ /^(hr|ul|ol|dl|pre|table|h)/
Truth table100%3/3
A and B
A= $open_tag eq "p"B= $in_tag =~ /^(hr|ul|ol|dl|pre|table|h)/
ABresult
0X0
100
111
2083 and $in_tag =~ /^(hr|ul|ol|dl|pre|table|h)/)
2084 {
2085 9 $tag_prefix = $self->close_tag('p');
2086 }
2087 ▶ elsif ( $open_tag eq 'li'
Condition83%5/6
$open_tag eq "li" and $in_tag eq "li" and $args{"tag_type"} != 2
!ll&&!rl&&r
3126070
$open_tag eq "li" and $in_tag eq "li"
!ll&&!rl&&r
30408670
MC/DC66%2/3
$open_tag eq "li" and $in_tag eq "li" and $args{"tag_type"} != 2
$open_tag eq "li" $in_tag eq "li" $args{"tag_type"} != 2
Truth table75%3/4
A and B and C
A= $open_tag eq "li"B= $in_tag eq "li"C= $args{"tag_type"} != 2
ABCresult
0XX0
10X0
1100
1111
2088 and $in_tag eq 'li'
2089 and $args{tag_type} != TAG_END)
2090 {
2091 # close a LI before the next LI
2092 70 $tag_prefix = $self->close_tag('li');
2093 }
2094 ▶ elsif ( $open_tag eq 'li'
Condition100%6/6
$open_tag eq "li" and $in_tag =~ /^(ul|ol)$/ and $args{"tag_type"} == 2
!ll&&!rl&&r
30562347
$open_tag eq "li" and $in_tag =~ /^(ul|ol)$/
!ll&&!rl&&r
30401670
MC/DC100%3/3
$open_tag eq "li" and $in_tag =~ /^(ul|ol)$/ and $args{"tag_type"} == 2
$open_tag eq "li" $in_tag =~ /^(ul|ol)$/ $args{"tag_type"} == 2
Truth table100%4/4
A and B and C
A= $open_tag eq "li"B= $in_tag =~ /^(ul|ol)$/C= $args{"tag_type"} == 2
ABCresult
0XX0
10X0
1100
1111
2095 and $in_tag =~ /^(ul|ol)$/
2096 and $args{tag_type} == TAG_END)
2097 {
2098 # close the LI before the list closes
2099 47 $tag_prefix = $self->close_tag('li');
2100 }
2101 ▶ elsif ( $open_tag eq 'dt'
Condition50%3/6
$open_tag eq "dt" and $in_tag eq "dd" and $args{"tag_type"} != 2
!ll&&!rl&&r
307900
$open_tag eq "dt" and $in_tag eq "dd"
!ll&&!rl&&r
307270
MC/DC0%0/3
$open_tag eq "dt" and $in_tag eq "dd" and $args{"tag_type"} != 2
$open_tag eq "dt" $in_tag eq "dd" $args{"tag_type"} != 2
Truth table50%2/4
A and B and C
A= $open_tag eq "dt"B= $in_tag eq "dd"C= $args{"tag_type"} != 2
ABCresult
0XX0
10X0
1100
1111
2102 and $in_tag eq 'dd'
2103 and $args{tag_type} != TAG_END)
2104 {
2105 # close a DT before the next DD
2106 0 $tag_prefix = $self->close_tag('dt');
2107 }
2108 ▶ elsif ( $open_tag eq 'dd'
Condition83%5/6
$open_tag eq "dd" and $in_tag eq "dt" and $args{"tag_type"} != 2
!ll&&!rl&&r
307702
$open_tag eq "dd" and $in_tag eq "dt"
!ll&&!rl&&r
306982
MC/DC66%2/3
$open_tag eq "dd" and $in_tag eq "dt" and $args{"tag_type"} != 2
$open_tag eq "dd" $in_tag eq "dt" $args{"tag_type"} != 2
Truth table75%3/4
A and B and C
A= $open_tag eq "dd"B= $in_tag eq "dt"C= $args{"tag_type"} != 2
ABCresult
0XX0
10X0
1100
1111
2109 and $in_tag eq 'dt'
2110 and $args{tag_type} != TAG_END)
2111 {
2112 # close a DD before the next DT
2113 2 $tag_prefix = $self->close_tag('dd');
2114 }
2115 ▶ elsif ( $open_tag eq 'dd'
Condition83%5/6
$open_tag eq "dd" and $in_tag eq "dl" and $args{"tag_type"} == 2
!ll&&!rl&&r
307205
$open_tag eq "dd" and $in_tag eq "dl"
!ll&&!rl&&r
306935
MC/DC66%2/3
$open_tag eq "dd" and $in_tag eq "dl" and $args{"tag_type"} == 2
$open_tag eq "dd" $in_tag eq "dl" $args{"tag_type"} == 2
Truth table75%3/4
A and B and C
A= $open_tag eq "dd"B= $in_tag eq "dl"C= $args{"tag_type"} == 2
ABCresult
0XX0
10X0
1100
1111
2116 and $in_tag eq 'dl'
2117 and $args{tag_type} == TAG_END)
2118 {
2119 # close the DD before the list closes
2120 5 $tag_prefix = $self->close_tag('dd');
2121 }
2122 }
2123  
2124 3522 my $out_tag = $in_tag;
2125 3522 ▶ if ($args{tag_type} == TAG_END)
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'tag_type'} == 2) { } 91 3431 3522
2126 {
2127 91 $out_tag = $self->close_tag($in_tag);
2128 }
2129 else
2130 {
2131 3431 ▶ if ($self->{lower_case_tags})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'lower_case_tags'}) { } 3146 285 3431
2132 {
2133 3146 $out_tag =~ tr/A-Z/a-z/;
2134 }
2135 else # upper case
2136 {
2137 285 $out_tag =~ tr/a-z/A-Z/;
2138 }
2139 3431 ▶ if ($args{tag_type} == TAG_EMPTY)
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'tag_type'} == 3) { } 901 2530 3431
2140 {
2141 901 ▶ if ($self->{xhtml})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'xhtml'}) { } 821 80 901
2142 {
2143 821 $out_tag = "<${out_tag}${inside_tag}/>";
2144 }
2145 else
2146 {
2147 80 $out_tag = "<${out_tag}${inside_tag}>";
2148 }
2149 }
2150 else
2151 {
2152 2530 push @{$self->{__tags}}, $in_tag;
2153 2530 $out_tag = "<${out_tag}${inside_tag}>";
2154 }
2155 }
2156 3522 ▶ $out_tag = $tag_prefix . $out_tag if $tag_prefix;
Branch: 1 branch
BranchTrueFalseTotal
if $tag_prefix 147 3375 3522
2157 3522 ▶ if ($DictDebug & 8)
Branch: 1 branch
BranchTrueFalseTotal
if ($HTML::TextToHTML::DictDebug & 8) 0 3522 3522
2158 {
2159 print STDERR
2160 "open_tag = '${open_tag}', in_tag = '${in_tag}', tag_type = ",
2161 $args{tag_type},
2162 0 ", inside_tag = '${inside_tag}', out_tag = '$out_tag'\n";
2163 }
2164  
2165 3522 return $out_tag;
2166 } # get_tag
2167  
2168 =head2 close_tag
2169  
2170 $tag = $self->close_tag($in_tag);
2171  
2172 close the open tag
2173  
2174 =cut
2175 sub close_tag ($$)
2176 2459 ▶{
Subroutine close_tag: called CC=6 SCAR=18.3
Pod documented
2177 2459 my $self = shift;
2178 2459 my $in_tag = shift;
2179  
2180 2459 my $open_tag = pop @{$self->{__tags}};
2181 2459 ▶ $in_tag ||= $open_tag;
Condition33%1/3
$in_tag ||= $open_tag
l!l&&r!l&&!r
245900
MC/DC0%0/2
$in_tag ||= $open_tag
$in_tag $open_tag
Truth table33%1/3
A ||= B
A= $in_tagB= $open_tag
ABresult
1X1
011
000
2182 # put the open tag back on the stack if the in-tag is not the same
2183 2459 ▶ if (defined $open_tag && $open_tag ne $in_tag)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $open_tag and $open_tag ne $in_tag) 15 2444 2459
Condition66%2/3
defined $open_tag and $open_tag ne $in_tag
!ll&&!rl&&r
0244415
MC/DC50%1/2
defined $open_tag and $open_tag ne $in_tag
defined $open_tag $open_tag ne $in_tag
Truth table66%2/3
A and B
A= defined $open_tagB= $open_tag ne $in_tag
ABresult
0X0
100
111
2184 {
2185 15 push @{$self->{__tags}}, $open_tag;
2186 }
2187 2459 my $out_tag = $in_tag;
2188 2459 ▶ if ($self->{lower_case_tags})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'lower_case_tags'}) { } 2324 135 2459
2189 {
2190 2324 $out_tag =~ tr/A-Z/a-z/;
2191 }
2192 else # upper case
2193 {
2194 135 $out_tag =~ tr/a-z/A-Z/;
2195 }
2196 2459 $out_tag = "<\/${out_tag}>";
2197 2459 ▶ if ($DictDebug & 8)
Branch: 1 branch
BranchTrueFalseTotal
if ($HTML::TextToHTML::DictDebug & 8) 0 2459 2459
2198 {
2199 0 print STDERR
2200 "close_tag: open_tag = '${open_tag}', in_tag = '${in_tag}', out_tag = '$out_tag'\n";
2201 }
2202  
2203 2459 return $out_tag;
2204 }
2205  
2206 =head2 hrule
2207  
2208 $self->hrule(para_lines_ref=>$para_lines,
2209 para_action_ref=>$para_action,
2210 ind=>0);
2211  
2212 Deal with horizontal rules.
2213  
2214 =cut
2215 sub hrule ($%)
2216 1086 ▶{
Subroutine hrule: called CC=3 SCAR=11.0
Pod documented
2217 1086 my $self = shift;
2218 1086 my %args = (
2219 para_lines_ref => undef,
2220 para_action_ref => undef,
2221 ind => 0,
2222 @_
2223 );
2224 1086 my $para_lines_ref = $args{para_lines_ref};
2225 1086 my $para_action_ref = $args{para_action_ref};
2226 1086 my $ind = $args{ind};
2227  
2228 1086 my $hrmin = $self->{hrule_min};
2229 1086 ▶ if ($para_lines_ref->[$ind] =~ /^\s*([-_~=\*]\s*){$hrmin,}$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($para_lines_ref->[$ind] =~ /^\s*([-_~=\*]\s*){$hrmin,}$/) { } 18 1068 1086
elsif ($para_lines_ref->[$ind] =~ /\014/) { } 1 1067 1068
2230 {
2231 18 my $tag = $self->get_tag("hr", tag_type => TAG_EMPTY);
2232 18 $para_lines_ref->[$ind] = "$tag\n";
2233 18 $para_action_ref->[$ind] |= $HRULE;
2234 }
2235 elsif ($para_lines_ref->[$ind] =~ /\014/)
2236 {
2237 # Linefeeds become horizontal rules
2238 1 $para_action_ref->[$ind] |= $HRULE;
2239 1 my $tag = $self->get_tag("hr", tag_type => TAG_EMPTY);
2240 1 $para_lines_ref->[$ind] =~ s/\014/\n${tag}\n/g;
2241 }
2242 }
2243  
2244 =head2 shortline
2245  
2246 $self->shortline(line_ref=>$line_ref,
2247 line_action_ref=>$line_action_ref,
2248 prev_ref=>$prev_ref,
2249 prev_action_ref=>$prev_action_ref,
2250 prev_line_len=>$prev_line_len);
2251  
2252 Deal with short lines.
2253  
2254 =cut
2255 sub shortline ($%)
2256 802 ▶{
Subroutine shortline: called CC=6 SCAR=17.9
Pod documented
2257 802 my $self = shift;
2258 802 my %args = (
2259 line_ref => undef,
2260 line_action_ref => undef,
2261 prev_ref => undef,
2262 prev_action_ref => undef,
2263 prev_line_len => 0,
2264 @_
2265 );
2266 802 my $mode_ref = $args{mode_ref};
2267 802 my $line_ref = $args{line_ref};
2268 802 my $line_action_ref = $args{line_action_ref};
2269 802 my $prev_ref = $args{prev_ref};
2270 802 my $prev_action_ref = $args{prev_action_ref};
2271 802 my $prev_line_len = $args{prev_line_len};
2272  
2273 # Short lines should be broken even on list item lines iff the
2274 # following line is more text. I haven't figured out how to do
2275 # that yet. For now, I'll just not break on short lines in lists.
2276 # (sorry)
2277  
2278 802 my $tag = $self->get_tag('br', tag_type => TAG_EMPTY);
2279 802 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not ${$line_ref;} =~ /^\s*$/ || ${$prev_ref;} =~ /^\s*$/ and $prev_line_len < $self->{"short_line_length"} and not ${$line_action_ref;} & ($HTML::TextToHTML::END | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::HRULE | $HTML::TextToHTML::LIST | $HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR) and not ${$prev_action_ref;} & ($HTML::TextToHTML::HEADER | $HTML::TextToHTML::HRULE | $HTML::TextToHTML::BREAK | $HTML::TextToHTML::IND_BREAK)) 48 754 802
Condition100%12/12
not ${$line_ref;} =~ /^\s*$/ || ${$prev_ref;} =~ /^\s*$/ and $prev_line_len < $self->{"short_line_length"} and not ${$line_action_ref;} & ($HTML::TextToHTML::END | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::HRULE | $HTML::TextToHTML::LIST | $HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR) and not ${$prev_action_ref;} & ($HTML::TextToHTML::HEADER | $HTML::TextToHTML::HRULE | $HTML::TextToHTML::BREAK | $HTML::TextToHTML::IND_BREAK)
!ll&&!rl&&r
748648
not ${$line_ref;} =~ /^\s*$/ || ${$prev_ref;} =~ /^\s*$/ and $prev_line_len < $self->{"short_line_length"} and not ${$line_action_ref;} & ($HTML::TextToHTML::END | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::HRULE | $HTML::TextToHTML::LIST | $HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR)
!ll&&!rl&&r
48226654
not ${$line_ref;} =~ /^\s*$/ || ${$prev_ref;} =~ /^\s*$/ and $prev_line_len < $self->{"short_line_length"}
!ll&&!rl&&r
38444320
${$line_ref;} =~ /^\s*$/ || ${$prev_ref;} =~ /^\s*$/
l!l&&r!l&&!r
2018764
MC/DC100%5/5
not ${$line_ref;} =~ /^\s*$/ || ${$prev_ref;} =~ /^\s*$/ and $prev_line_len < $self->{"short_line_length"} and not ${$line_action_ref;} & ($HTML::TextToHTML::END | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::HRULE | $HTML::TextToHTML::LIST | $HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR) and not ${$prev_action_ref;} & ($HTML::TextToHTML::HEADER | $HTML::TextToHTML::HRULE | $HTML::TextToHTML::BREAK | $HTML::TextToHTML::IND_BREAK)
${$line_ref;} =~ /^\s*$/ ${$prev_ref;} =~ /^\s*$/ $prev_line_len < $self->{"short_line_length"} not ${$line_action_ref;} & ($HTML::TextToHTML::END | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::HRULE | $HTML::TextToHTML::LIST | $HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR) not ${$prev_action_ref;} & ($HTML::TextToHTML::HEADER | $HTML::TextToHTML::HRULE | $HTML::TextToHTML::BREAK | $HTML::TextToHTML::IND_BREAK)
Truth table100%6/6
not(A || B) and C and not(D) and not(E)
A= ${$line_ref;} =~ /^\s*$/B= ${$prev_ref;} =~ /^\s*$/C= $prev_line_len < $self->{"short_line_length"}D= not ${$line_action_ref;} & ($HTML::TextToHTML::END | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::HRULE | $HTML::TextToHTML::LIST | $HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR)E= not ${$prev_action_ref;} & ($HTML::TextToHTML::HEADER | $HTML::TextToHTML::HRULE | $HTML::TextToHTML::BREAK | $HTML::TextToHTML::IND_BREAK)
ABCDEresult
1XXXX0
01XXX0
000XX0
0010X0
001100
001111
2280 802 ${$line_ref} !~ /^\s*$/
2281 782 && ${$prev_ref} !~ /^\s*$/
2282 && ($prev_line_len < $self->{short_line_length})
2283 && !(
2284 320 ${$line_action_ref} &
2285 ($END | $HEADER | $HRULE | $LIST | $IND_BREAK | $PAR)
2286 )
2287 54 && !(${$prev_action_ref} & ($HEADER | $HRULE | $BREAK | $IND_BREAK))
2288 )
2289 {
2290 48 ${$prev_ref} .= $tag . chop(${$prev_ref});
2291 48 ${$prev_action_ref} |= $BREAK;
2292 }
2293 }
2294  
2295 =head2 is_mailheader
2296  
2297 if ($self->is_mailheader(rows_ref=>$rows_ref))
2298 {
2299 ...
2300 }
2301  
2302 Is this a mailheader line?
2303  
2304 =cut
2305 sub is_mailheader ($%)
2306 207 ▶{
Subroutine is_mailheader: called CC=2 SCAR=6.9
Pod documented
2307 207 my $self = shift;
2308 207 my %args = (
2309 rows_ref => undef,
2310 @_
2311 );
2312 207 my $rows_ref = $args{rows_ref};
2313  
2314 # a mail header is assumed to be the whole
2315 # paragraph which starts with a From , From: or Newsgroups: line
2316  
2317 207 ▶ if ($rows_ref->[0] =~ /^(From:?)|(Newsgroups:) /)
Branch: 1 branch
BranchTrueFalseTotal
if ($rows_ref->[0] =~ /^(From:?)|(Newsgroups:) /) 22 185 207
2318 {
2319 22 return 1;
2320 }
2321 185 return 0;
2322  
2323 } # is_mailheader
2324  
2325 =head2 mailheader
2326  
2327 $self->mailheader(rows_ref=>$rows_ref);
2328  
2329 Deal with a mailheader.
2330  
2331 =cut
2332 sub mailheader ($%)
2333 11 ▶{
Subroutine mailheader: called CC=6 SCAR=18.0
Pod documented
2334 11 my $self = shift;
2335 11 my %args = (
2336 rows_ref => undef,
2337 @_
2338 );
2339 11 my $rows_ref = $args{rows_ref};
2340  
2341 # a mail header is assumed to be the whole
2342 # paragraph which starts with a From: or Newsgroups: line
2343 11 my $tag = '';
2344 11 my @rows = @{$rows_ref};
2345  
2346 11 ▶ if ($self->is_mailheader(%args))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_mailheader(%args)) 11 0 11
2347 {
2348 11 $self->{__mode} |= $MAILHEADER;
2349 11 ▶ if ($self->{escape_HTML_chars})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"escape_HTML_chars"}) 11 0 11
2350 {
2351 11 $rows[0] = escape($rows[0]);
2352 }
2353 11 $self->anchor_mail(\$rows[0]);
2354 11 chomp ${rows}[0];
2355 11 $tag = $self->get_tag('p', inside_tag => " class='mail_header'");
2356 11 my $tag2 = $self->get_tag('br', tag_type => TAG_EMPTY);
2357 11 $rows[0] =
2358 join('', "<!-- New Message -->\n", $tag, $rows[0], $tag2, "\n");
2359 # now put breaks on the rest of the paragraph
2360 # apart from the last line
2361 11 ▶ for (my $rn = 1; $rn < @rows; $rn++)
Branch: 1 branch
BranchTrueFalseTotal
if ($rn < @rows) 43 11 54
2362 {
2363 43 ▶ if ($self->{escape_HTML_chars})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"escape_HTML_chars"}) 43 0 43
2364 {
2365 43 $rows[$rn] = escape($rows[$rn]);
2366 }
2367 43 ▶ if ($rn != (@rows - 1))
Branch: 1 branch
BranchTrueFalseTotal
if ($rn != @rows - 1) 32 11 43
2368 {
2369 32 $tag = $self->get_tag('br', tag_type => TAG_EMPTY);
2370 32 chomp $rows[$rn];
2371 32 $rows[$rn] =~ s/$/${tag}\n/;
2372 }
2373 }
2374 }
2375 11 @{$rows_ref} = @rows;
2376  
2377 } # mailheader
2378  
2379 =head2 mailquote
2380  
2381 $self->mailquote(line_ref=>$line_ref,
2382 line_action_ref=>$line_action_ref,
2383 prev_ref=>$prev_ref,
2384 prev_action_ref=>$prev_action_ref,
2385 next_ref=>$next_ref);
2386  
2387 Deal with quoted mail.
2388  
2389 =cut
2390 sub mailquote ($%)
2391 519 ▶{
Subroutine mailquote: called CC=6 SCAR=17.9
Pod documented
2392 519 my $self = shift;
2393 519 my %args = (
2394 line_ref => undef,
2395 line_action_ref => undef,
2396 prev_ref => undef,
2397 prev_action_ref => undef,
2398 next_ref => undef,
2399 @_
2400 );
2401 519 my $line_ref = $args{line_ref};
2402 519 my $line_action_ref = $args{line_action_ref};
2403 519 my $prev_ref = $args{prev_ref};
2404 519 my $prev_action_ref = $args{prev_action_ref};
2405 519 my $next_ref = $args{next_ref};
2406  
2407 519 my $tag = '';
2408 519 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (${$line_ref;} =~ /^\w*&gt/ || ${$line_ref;} =~ /^[\|:]/ and defined $next_ref and not ${$next_ref;} =~ /^\s*$/) 24 495 519
Condition77%7/9
${$line_ref;} =~ /^\w*&gt/ || ${$line_ref;} =~ /^[\|:]/ and defined $next_ref and not ${$next_ref;} =~ /^\s*$/
!ll&&!rl&&r
495024
${$line_ref;} =~ /^\w*&gt/ || ${$line_ref;} =~ /^[\|:]/ and defined $next_ref
!ll&&!rl&&r
486924
${$line_ref;} =~ /^\w*&gt/ or ${$line_ref;} =~ /^[\|:]/
l!l&&r!l&&!r
330486
MC/DC50%2/4
${$line_ref;} =~ /^\w*&gt/ || ${$line_ref;} =~ /^[\|:]/ and defined $next_ref and not ${$next_ref;} =~ /^\s*$/
${$line_ref;} =~ /^\w*&gt/ ${$line_ref;} =~ /^[\|:]/ defined $next_ref not ${$next_ref;} =~ /^\s*$/
Truth table42%3/7
A or B and C and not(D)
A= ${$line_ref;} =~ /^\w*&gt/B= ${$line_ref;} =~ /^[\|:]/C= defined $next_refD= not ${$next_ref;} =~ /^\s*$/
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
2409 (
2410 519 (${$line_ref} =~ /^\w*&gt/) # Handle "FF> Werewolves."
2411 486 || (${$line_ref} =~ /^[\|:]/)
2412 ) # Handle "[|:] There wolves."
2413 24 && defined($next_ref) && (${$next_ref} !~ /^\s*$/)
2414 )
2415 {
2416 24 $tag = $self->get_tag('br', tag_type => TAG_EMPTY);
2417 24 ${$line_ref} =~ s/$/${tag}/;
2418 24 ${$line_action_ref} |= ($BREAK | $MAILQUOTE);
2419 24 ▶ if (!(${$prev_action_ref} & ($BREAK | $MAILQUOTE)))
Branch: 1 branch
BranchTrueFalseTotal
if (not ${$prev_action_ref;} & ($HTML::TextToHTML::BREAK | $HTML::TextToHTML::MAILQUOTE)) 10 14 24
2420 {
2421 10 $tag = $self->get_tag('p', inside_tag => " class='quote_mail'");
2422 10 ${$prev_ref} .= $tag;
2423 10 ${$line_action_ref} |= $PAR;
2424 }
2425 }
2426 }
2427  
2428 =head2 subtract_modes
2429
2430 $newvector = subtract_modes($vector, $mask);
2431  
2432 Subtracts modes listed in $mask from $vector.
2433  
2434 =cut
2435 sub subtract_modes ($$)
2436 1039 ▶{
Subroutine subtract_modes: called CC=1 SCAR=0.0
Pod documented
2437 1039 my ($vector, $mask) = @_;
2438 1039 return ($vector | $mask) - $mask;
2439 }
2440  
2441 =head2 paragraph
2442  
2443 $self->paragraph(line_ref=>$line_ref,
2444 line_action_ref=>$line_action_ref,
2445 prev_ref=>$prev_ref,
2446 prev_action_ref=>$prev_action_ref,
2447 line_indent=>$line_indent,
2448 prev_indent=>$prev_indent,
2449 is_fragment=>$is_fragment,
2450 ind=>$ind);
2451  
2452 Detect paragraph indentation.
2453  
2454 =cut
2455 sub paragraph ($%)
2456 1065 ▶{
Subroutine paragraph: called CC=21 SCAR=44.6
Pod documented
2457 1065 my $self = shift;
2458 1065 my %args = (
2459 line_ref => undef,
2460 line_action_ref => undef,
2461 prev_ref => undef,
2462 prev_action_ref => undef,
2463 line_indent => 0,
2464 prev_indent => 0,
2465 is_fragment => 0,
2466 ind => 0,
2467 @_
2468 );
2469 1065 my $line_ref = $args{line_ref};
2470 1065 my $line_action_ref = $args{line_action_ref};
2471 1065 my $prev_ref = $args{prev_ref};
2472 1065 my $prev_action_ref = $args{prev_action_ref};
2473 1065 my $line_indent = $args{line_indent};
2474 1065 my $prev_indent = $args{prev_indent};
2475 1065 my $is_fragment = $args{is_fragment};
2476 1065 my $line_no = $args{ind};
2477  
2478 1065 my $tag = '';
2479 1065 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if (not ${$line_ref;} =~ /^\s*$/ || &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS | $HTML::TextToHTML::BREAK) and ${$prev_ref;} =~ /^\s*$/ || ${$line_action_ref;} & $HTML::TextToHTML::END || $line_indent > $prev_indent + $self->{'par_indent'} and not $is_fragment && $line_no == 0) { } 259 806 1065
elsif ($self->{'indent_par_break'} and not $self->{'__mode'} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::LIST) and not ${$prev_ref;} =~ /^\s*$/ and not ${$line_action_ref;} & $HTML::TextToHTML::END and ${$prev_action_ref;} & ($HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR) and not &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS) and $line_indent > $self->{'par_indent'} and $line_indent == $prev_indent) { } 0 1612 1612
Condition100%9/9
not ${$line_ref;} =~ /^\s*$/ || &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS | $HTML::TextToHTML::BREAK) and ${$prev_ref;} =~ /^\s*$/ || ${$line_action_ref;} & $HTML::TextToHTML::END || $line_indent > $prev_indent + $self->{"par_indent"} and not $is_fragment && $line_no == 0
!ll&&!rl&&r
8015259
not ${$line_ref;} =~ /^\s*$/ || &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS | $HTML::TextToHTML::BREAK) and ${$prev_ref;} =~ /^\s*$/ || ${$line_action_ref;} & $HTML::TextToHTML::END || $line_indent > $prev_indent + $self->{"par_indent"}
!ll&&!rl&&r
225576264
${$line_ref;} =~ /^\s*$/ || &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS | $HTML::TextToHTML::BREAK)
l!l&&r!l&&!r
26199840
MC/DC0%0/4
not ${$line_ref;} =~ /^\s*$/ || &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS | $HTML::TextToHTML::BREAK) and ${$prev_ref;} =~ /^\s*$/ || ${$line_action_ref;} & $HTML::TextToHTML::END || $line_indent > $prev_indent + $self->{"par_indent"} and not $is_fragment && $line_no == 0
${$line_ref;} =~ /^\s*$/ &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS | $HTML::TextToHTML::BREAK) ${$prev_ref;} =~ /^\s*$/ || ${$line_action_ref;} & $HTML::TextToHTML::END || $line_indent > $prev_indent + $self->{"par_indent"} not $is_fragment && $line_no == 0
Truth table40%2/5
not(A || B) and C and not(D)
A= ${$line_ref;} =~ /^\s*$/B= &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS | $HTML::TextToHTML::BREAK)C= ${$prev_ref;} =~ /^\s*$/ || ${$line_action_ref;} & $HTML::TextToHTML::END || $line_indent > $prev_indent + $self->{"par_indent"}D= not $is_fragment && $line_no == 0
ABCDresult
1XXX0
01XX0
000X0
00100
00111
2480 1065 ${$line_ref} !~ /^\s*$/
2481 && !subtract_modes(
2482 1039 ▶ ${$line_action_ref}, $END | $MAILQUOTE | $CAPS | $BREAK
Condition100%6/6
${$prev_ref;} =~ /^\s*$/ or ${$line_action_ref;} & $HTML::TextToHTML::END or $line_indent > $prev_indent + $self->{"par_indent"}
l!l&&r!l&&!r
2586576
${$prev_ref;} =~ /^\s*$/ or ${$line_action_ref;} & $HTML::TextToHTML::END
l!l&&r!l&&!r
24612582
MC/DC0%0/3
${$prev_ref;} =~ /^\s*$/ or ${$line_action_ref;} & $HTML::TextToHTML::END or $line_indent > $prev_indent + $self->{"par_indent"}
${$prev_ref;} =~ /^\s*$/ ${$line_action_ref;} & $HTML::TextToHTML::END $line_indent > $prev_indent + $self->{"par_indent"}
Truth table0%0/4
A or B or C
A= ${$prev_ref;} =~ /^\s*$/B= ${$line_action_ref;} & $HTML::TextToHTML::ENDC= $line_indent > $prev_indent + $self->{"par_indent"}
ABCresult
1XX1
01X1
0011
0000
2483 )
2484 840 && ( ${$prev_ref} =~ /^\s*$/
2485 594 ▶ || (${$line_action_ref} & $END)
Condition66%2/3
$is_fragment && $line_no == 0
!ll&&!rl&&r
25905
MC/DC50%1/2
$is_fragment && $line_no == 0
$is_fragment $line_no == 0
Truth table66%2/3
A && B
A= $is_fragmentB= $line_no == 0
ABresult
0X0
100
111
2486 || ($line_indent > $prev_indent + $self->{par_indent}))
2487 && !($is_fragment && $line_no == 0)
2488 )
2489 {
2490  
2491 259 ▶ if ( $self->{indent_par_break}
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'indent_par_break'} and not ${$prev_ref;} =~ /^\s*$/ and not ${$line_action_ref;} & $HTML::TextToHTML::END and $line_indent > $prev_indent + $self->{'par_indent'}) { } 0 259 259
elsif ($self->{'preserve_indent'}) { } 0 259 259
Condition33%3/9
$self->{"indent_par_break"} and not ${$prev_ref;} =~ /^\s*$/ and not ${$line_action_ref;} & $HTML::TextToHTML::END and $line_indent > $prev_indent + $self->{"par_indent"}
!ll&&!rl&&r
25900
$self->{"indent_par_break"} and not ${$prev_ref;} =~ /^\s*$/ and not ${$line_action_ref;} & $HTML::TextToHTML::END
!ll&&!rl&&r
25900
$self->{"indent_par_break"} and not ${$prev_ref;} =~ /^\s*$/
!ll&&!rl&&r
25900
MC/DC0%0/4
$self->{"indent_par_break"} and not ${$prev_ref;} =~ /^\s*$/ and not ${$line_action_ref;} & $HTML::TextToHTML::END and $line_indent > $prev_indent + $self->{"par_indent"}
$self->{"indent_par_break"} not ${$prev_ref;} =~ /^\s*$/ not ${$line_action_ref;} & $HTML::TextToHTML::END $line_indent > $prev_indent + $self->{"par_indent"}
Truth table20%1/5
A and not(B) and not(C) and D
A= $self->{"indent_par_break"}B= not ${$prev_ref;} =~ /^\s*$/C= not ${$line_action_ref;} & $HTML::TextToHTML::ENDD= $line_indent > $prev_indent + $self->{"par_indent"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2492 0 && ${$prev_ref} !~ /^\s*$/
2493 0 && !(${$line_action_ref} & $END)
2494 && ($line_indent > $prev_indent + $self->{par_indent}))
2495 {
2496 0 $tag = $self->get_tag('br', tag_type => TAG_EMPTY);
2497 0 ${$prev_ref} .= $tag;
2498 0 ${$prev_ref} .= "&nbsp;" x $line_indent;
2499 0 ${$line_ref} =~ s/^ {$line_indent}//;
2500 0 ${$prev_action_ref} |= $BREAK;
2501 0 ${$line_action_ref} |= $IND_BREAK;
2502 }
2503 elsif ($self->{preserve_indent})
2504 {
2505 0 $tag = $self->get_tag('p');
2506 0 ${$prev_ref} .= $tag;
2507 0 ${$prev_ref} .= "&nbsp;" x $line_indent;
2508 0 ${$line_ref} =~ s/^ {$line_indent}//;
2509 0 ${$line_action_ref} |= $PAR;
2510 }
2511 else
2512 {
2513 259 $tag = $self->get_tag('p');
2514 259 ${$prev_ref} .= $tag;
2515 259 ${$line_action_ref} |= $PAR;
2516 }
2517 }
2518 # detect also a continuing indentation at the same level
2519 ▶ elsif ($self->{indent_par_break}
Condition33%7/21
$self->{"indent_par_break"} and not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::LIST) and not ${$prev_ref;} =~ /^\s*$/ and not ${$line_action_ref;} & $HTML::TextToHTML::END and ${$prev_action_ref;} & ($HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR) and not &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS) and $line_indent > $self->{"par_indent"} and $line_indent == $prev_indent
!ll&&!rl&&r
80600
$self->{"indent_par_break"} and not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::LIST) and not ${$prev_ref;} =~ /^\s*$/ and not ${$line_action_ref;} & $HTML::TextToHTML::END and ${$prev_action_ref;} & ($HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR) and not &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS) and $line_indent > $self->{"par_indent"}
!ll&&!rl&&r
80600
$self->{"indent_par_break"} and not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::LIST) and not ${$prev_ref;} =~ /^\s*$/ and not ${$line_action_ref;} & $HTML::TextToHTML::END and ${$prev_action_ref;} & ($HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR) and not &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS)
!ll&&!rl&&r
80600
$self->{"indent_par_break"} and not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::LIST) and not ${$prev_ref;} =~ /^\s*$/ and not ${$line_action_ref;} & $HTML::TextToHTML::END and ${$prev_action_ref;} & ($HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR)
!ll&&!rl&&r
80600
$self->{"indent_par_break"} and not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::LIST) and not ${$prev_ref;} =~ /^\s*$/ and not ${$line_action_ref;} & $HTML::TextToHTML::END
!ll&&!rl&&r
80600
$self->{"indent_par_break"} and not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::LIST) and not ${$prev_ref;} =~ /^\s*$/
!ll&&!rl&&r
80600
$self->{"indent_par_break"} and not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::LIST)
!ll&&!rl&&r
80600
MC/DC0%0/8
$self->{"indent_par_break"} and not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::LIST) and not ${$prev_ref;} =~ /^\s*$/ and not ${$line_action_ref;} & $HTML::TextToHTML::END and ${$prev_action_ref;} & ($HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR) and not &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS) and $line_indent > $self->{"par_indent"} and $line_indent == $prev_indent
$self->{"indent_par_break"} not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::LIST) not ${$prev_ref;} =~ /^\s*$/ not ${$line_action_ref;} & $HTML::TextToHTML::END ${$prev_action_ref;} & ($HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR) not &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS) $line_indent > $self->{"par_indent"} $line_indent == $prev_indent
Truth table11%1/9
A and not(B) and not(C) and not(D) and E and not(F) and G and H
A= $self->{"indent_par_break"}B= not $self->{"__mode"} & ($HTML::TextToHTML::PRE | $HTML::TextToHTML::TABLE | $HTML::TextToHTML::LIST)C= not ${$prev_ref;} =~ /^\s*$/D= not ${$line_action_ref;} & $HTML::TextToHTML::ENDE= ${$prev_action_ref;} & ($HTML::TextToHTML::IND_BREAK | $HTML::TextToHTML::PAR)F= not &subtract_modes(${$line_action_ref;}, $HTML::TextToHTML::END | $HTML::TextToHTML::MAILQUOTE | $HTML::TextToHTML::CAPS)G= $line_indent > $self->{"par_indent"}H= $line_indent == $prev_indent
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
2520 && !($self->{__mode} & ($PRE | $TABLE | $LIST))
2521 0 && ${$prev_ref} !~ /^\s*$/
2522 0 && !(${$line_action_ref} & $END)
2523 0 && (${$prev_action_ref} & ($IND_BREAK | $PAR))
2524 0 && !subtract_modes(${$line_action_ref}, $END | $MAILQUOTE | $CAPS)
2525 && ($line_indent > $self->{par_indent})
2526 && ($line_indent == $prev_indent))
2527 {
2528 0 $tag = $self->get_tag('br', tag_type => TAG_EMPTY);
2529 0 ${$prev_ref} .= $tag;
2530 0 ${$prev_ref} .= "&nbsp;" x $line_indent;
2531 0 ${$line_ref} =~ s/^ {$line_indent}//;
2532 0 ${$prev_action_ref} |= $BREAK;
2533 0 ${$line_action_ref} |= $IND_BREAK;
2534 }
2535 }
2536  
2537 =head2 listprefix
2538  
2539 ($prefix, $number, $rawprefix, $term) = $self->listprefix($line);
2540  
2541 Detect and parse a list item.
2542  
2543 =cut
2544 sub listprefix ($$)
2545 1327 ▶{
Subroutine listprefix: called CC=12 SCAR=24.8
Pod documented
2546 1327 my $self = shift;
2547 1327 my $line = shift;
2548  
2549 1327 my ($prefix, $number, $rawprefix, $term);
2550  
2551 1327 my $bullets = $self->{bullets};
2552 1327 my $bullets_ordered = $self->{bullets_ordered};
2553 1327 my $number_match = '(\d+|[^\W\d])';
2554 1327 ▶ if ($bullets_ordered)
Branch: 1 branch
BranchTrueFalseTotal
if ($bullets_ordered) 11 1316 1327
2555 {
2556 11 $number_match = '(\d+|[[:alpha:]]|[' . "${bullets_ordered}])";
2557 }
2558 1327 $self->{__number_match} = $number_match;
2559 1327 my $term_match = '(\w\w+)';
2560 1327 $self->{__term_match} = $term_match;
2561 1327 ▶ return (0, 0, 0, 0)
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /^\s*[$bullets]\s+\S/ or $line =~ /^\s*${number_match}[\.\)\]:]\s+\S/ or $line =~ /^\s*$term_match:$/ 1123 204 1327
Condition100%6/6
$line =~ /^\s*[$bullets]\s+\S/ or $line =~ /^\s*${number_match}[\.\)\]:]\s+\S/ or $line =~ /^\s*$term_match:$/
l!l&&r!l&&!r
190141123
$line =~ /^\s*[$bullets]\s+\S/ or $line =~ /^\s*${number_match}[\.\)\]:]\s+\S/
l!l&&r!l&&!r
115751137
MC/DC100%3/3
$line =~ /^\s*[$bullets]\s+\S/ or $line =~ /^\s*${number_match}[\.\)\]:]\s+\S/ or $line =~ /^\s*$term_match:$/
$line =~ /^\s*[$bullets]\s+\S/ $line =~ /^\s*${number_match}[\.\)\]:]\s+\S/ $line =~ /^\s*$term_match:$/
Truth table100%4/4
A or B or C
A= $line =~ /^\s*[$bullets]\s+\S/B= $line =~ /^\s*${number_match}[\.\)\]:]\s+\S/C= $line =~ /^\s*$term_match:$/
ABCresult
1XX1
01X1
0011
0000
2562 if ( !($line =~ /^\s*[${bullets}]\s+\S/)
2563 && !($line =~ /^\s*${number_match}[\.\)\]:]\s+\S/)
2564 && !($line =~ /^\s*${term_match}:$/));
2565  
2566 204 ($term) = $line =~ /^\s*${term_match}:$/;
2567 204 ($number) = $line =~ /^\s*${number_match}\S\s+\S/;
2568 204 ▶ $number = 0 unless defined($number);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 129 75 204
2569 204 ▶ if ( $bullets_ordered
Branch: 1 branch
BranchTrueFalseTotal
if ($bullets_ordered and $number =~ /[$bullets_ordered]/) 4 200 204
Condition100%3/3
$bullets_ordered and $number =~ /[$bullets_ordered]/
!ll&&!rl&&r
19554
MC/DC100%2/2
$bullets_ordered and $number =~ /[$bullets_ordered]/
$bullets_ordered $number =~ /[$bullets_ordered]/
Truth table100%3/3
A and B
A= $bullets_orderedB= $number =~ /[$bullets_ordered]/
ABresult
0X0
100
111
2570 && $number =~ /[${bullets_ordered}]/)
2571 {
2572 4 $number = 1;
2573 }
2574  
2575 # That slippery exception of "o" as a bullet
2576 # (This ought to be determined using the context of what lists
2577 # we have in progress, but this will probably work well enough.)
2578 204 ▶ if ($bullets =~ /o/ && $line =~ /^\s*o\s/)
Branch: 1 branch
BranchTrueFalseTotal
if ($bullets =~ /o/ and $line =~ /^\s*o\s/) 8 196 204
Condition66%2/3
$bullets =~ /o/ and $line =~ /^\s*o\s/
!ll&&!rl&&r
01968
MC/DC50%1/2
$bullets =~ /o/ and $line =~ /^\s*o\s/
$bullets =~ /o/ $line =~ /^\s*o\s/
Truth table66%2/3
A and B
A= $bullets =~ /o/B= $line =~ /^\s*o\s/
ABresult
0X0
100
111
2579 {
2580 8 $number = 0;
2581 }
2582  
2583 204 ▶ if ($term)
Branch: 2 branches
BranchTrueFalseTotal
if ($term) { } 14 190 204
elsif ($number) { } 75 115 190
2584 {
2585 14 ($rawprefix) = $line =~ /^(\s*${term_match}.)$/;
2586 14 $prefix = $rawprefix;
2587 14 $prefix =~ s/${term_match}//; # Take the term out
2588 }
2589 elsif ($number)
2590 {
2591 75 ($rawprefix) = $line =~ /^(\s*${number_match}.)/;
2592 75 $prefix = $rawprefix;
2593 75 $prefix =~ s/${number_match}//; # Take the number out
2594 }
2595 else
2596 {
2597 115 ($rawprefix) = $line =~ /^(\s*[${bullets}].)/;
2598 115 $prefix = $rawprefix;
2599 }
2600 204 ($prefix, $number, $rawprefix, $term);
2601 } # listprefix
2602  
2603 =head2 startlist
2604  
2605 $self->startlist(prefix=>$prefix,
2606 number=>0,
2607 rawprefix=>$rawprefix,
2608 term=>$term,
2609 para_lines_ref=>$para_lines_ref,
2610 para_action_ref=>$para_action_ref,
2611 ind=>0,
2612 prev_ref=>$prev_ref,
2613 total_prefix=>$total_prefix);
2614  
2615 Start a list.
2616  
2617 =cut
2618 sub startlist ($%)
2619 68 ▶{
Subroutine startlist: called CC=6 SCAR=17.9
Pod documented
2620 68 my $self = shift;
2621 68 my %args = (
2622 prefix => '',
2623 number => 0,
2624 rawprefix => '',
2625 term => '',
2626 para_lines_ref => undef,
2627 para_action_ref => undef,
2628 ind => 0,
2629 prev_ref => undef,
2630 total_prefix => '',
2631 @_
2632 );
2633 68 my $prefix = $args{prefix};
2634 68 my $number = $args{number};
2635 68 my $rawprefix = $args{rawprefix};
2636 68 my $term = $args{term};
2637 68 my $para_lines_ref = $args{para_lines_ref};
2638 68 my $para_action_ref = $args{para_action_ref};
2639 68 my $ind = $args{ind};
2640 68 my $prev_ref = $args{prev_ref};
2641  
2642 68 my $tag = '';
2643 68 $self->{__listprefix}->[$self->{__listnum}] = $prefix;
2644 68 ▶ if ($number)
Branch: 2 branches
BranchTrueFalseTotal
if ($number) { } 28 40 68
elsif ($term) { } 6 34 40
2645 {
2646  
2647 # It doesn't start with 1,a,A. Let's not screw with it.
2648 28 ▶ if (($number ne "1") && ($number ne "a") && ($number ne "A"))
Branch: 1 branch
BranchTrueFalseTotal
if ($number ne 1 and $number ne "a" and $number ne "A") 4 24 28
Condition100%6/6
$number ne 1 and $number ne "a" and $number ne "A"
!ll&&!rl&&r
2044
$number ne 1 and $number ne "a"
!ll&&!rl&&r
1378
MC/DC100%3/3
$number ne 1 and $number ne "a" and $number ne "A"
$number ne 1 $number ne "a" $number ne "A"
Truth table100%4/4
A and B and C
A= $number ne 1B= $number ne "a"C= $number ne "A"
ABCresult
0XX0
10X0
1100
1111
2649 {
2650 4 return 0;
2651 }
2652 24 $tag = $self->get_tag('ol');
2653 24 ${$prev_ref} .= join('', $self->{__list_nice_indent}, $tag, "\n");
2654 24 $self->{__list}->[$self->{__listnum}] = $OL;
2655 }
2656 elsif ($term)
2657 {
2658 6 $tag = $self->get_tag('dl');
2659 6 ${$prev_ref} .= join('', $self->{__list_nice_indent}, $tag, "\n");
2660 6 $self->{__list}->[$self->{__listnum}] = $DL;
2661 }
2662 else
2663 {
2664 34 $tag = $self->get_tag('ul');
2665 34 ${$prev_ref} .= join('', $self->{__list_nice_indent}, $tag, "\n");
2666 34 $self->{__list}->[$self->{__listnum}] = $UL;
2667 }
2668  
2669 64 $self->{__list_indent}->[$self->{__listnum}] = length($args{total_prefix});
2670 64 $self->{__listnum}++;
2671 $self->{__list_nice_indent} =
2672 64 " " x $self->{__listnum} x $self->{indent_width};
2673 64 $para_action_ref->[$ind] |= $LIST;
2674 64 $para_action_ref->[$ind] |= $LIST_START;
2675 64 $self->{__mode} |= $LIST;
2676 64 1;
2677 } # startlist
2678  
2679 =head2 endlist
2680  
2681 $self->endlist(num_lists=>0,
2682 prev_ref=>$prev_ref,
2683 line_action_ref=>$line_action_ref);
2684  
2685 End N lists
2686  
2687 =cut
2688 sub endlist ($%)
2689 53 ▶{
Subroutine endlist: called CC=6 SCAR=17.9
Pod documented
2690 53 my $self = shift;
2691 53 my %args = (
2692 num_lists => 0,
2693 prev_ref => undef,
2694 line_action_ref => undef,
2695 @_
2696 );
2697 53 my $n = $args{num_lists};
2698 53 my $prev_ref = $args{prev_ref};
2699 53 my $line_action_ref = $args{line_action_ref};
2700  
2701 53 my $tag = '';
2702 53 ▶ for (; $n > 0; $n--, $self->{__listnum}--)
Branch: 1 branch
BranchTrueFalseTotal
if ($n > 0) 64 53 117
2703 {
2704 $self->{__list_nice_indent} =
2705 64 " " x ($self->{__listnum} - 1) x $self->{indent_width};
2706 64 ▶ if ($self->{__list}->[$self->{__listnum} - 1] == $UL)
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'__list'}[$self->{'__listnum'} - 1] == $HTML::TextToHTML::UL) { } 34 30 64
elsif ($self->{'__list'}[$self->{'__listnum'} - 1] == $HTML::TextToHTML::OL) { } 24 6 30
elsif ($self->{'__list'}[$self->{'__listnum'} - 1] == $HTML::TextToHTML::DL) { } 6 0 6
2707 {
2708 34 $tag = $self->get_tag('ul', tag_type => TAG_END);
2709 34 ${$prev_ref} .= join('', $self->{__list_nice_indent}, $tag, "\n");
2710 34 pop @{$self->{__list_indent}};
2711 }
2712 elsif ($self->{__list}->[$self->{__listnum} - 1] == $OL)
2713 {
2714 24 $tag = $self->get_tag('ol', tag_type => TAG_END);
2715 24 ${$prev_ref} .= join('', $self->{__list_nice_indent}, $tag, "\n");
2716 24 pop @{$self->{__list_indent}};
2717 }
2718 elsif ($self->{__list}->[$self->{__listnum} - 1] == $DL)
2719 {
2720 6 $tag = $self->get_tag('dl', tag_type => TAG_END);
2721 6 ${$prev_ref} .= join('', $self->{__list_nice_indent}, $tag, "\n");
2722 6 pop @{$self->{__list_indent}};
2723 }
2724 else
2725 {
2726 0 print STDERR "Encountered list of unknown type\n";
2727 }
2728 }
2729 53 ${$line_action_ref} |= $END;
2730 53 ▶ $self->{__mode} ^= $LIST if (!$self->{__listnum});
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"__listnum"} 30 23 53
2731 } # endlist
2732  
2733 =head2 continuelist
2734  
2735 $self->continuelist(para_lines_ref=>$para_lines_ref,
2736 para_action_ref=>$para_action_ref,
2737 ind=>0,
2738 term=>$term);
2739  
2740 Continue a list.
2741  
2742 =cut
2743 sub continuelist ($%)
2744 158 ▶{
Subroutine continuelist: called CC=6 SCAR=17.9
Pod documented
2745 158 my $self = shift;
2746 158 my %args = (
2747 para_lines_ref => undef,
2748 para_action_ref => undef,
2749 ind => 0,
2750 term => '',
2751 @_
2752 );
2753 158 my $para_lines_ref = $args{para_lines_ref};
2754 158 my $para_action_ref = $args{para_action_ref};
2755 158 my $ind = $args{ind};
2756 158 my $term = $args{term};
2757  
2758 158 my $list_indent = $self->{__list_nice_indent};
2759 158 my $bullets = $self->{bullets};
2760 158 my $num_match = $self->{__number_match};
2761 158 my $term_match = $self->{__term_match};
2762 158 my $tag = '';
2763 158 ▶ if ( $self->{__list}->[$self->{__listnum} - 1] == $UL
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__list"}[$self->{"__listnum"} - 1] == $HTML::TextToHTML::UL and $para_lines_ref->[$ind] =~ /^\s*[$bullets]\s*/) 88 70 158
Condition66%2/3
$self->{"__list"}[$self->{"__listnum"} - 1] == $HTML::TextToHTML::UL and $para_lines_ref->[$ind] =~ /^\s*[$bullets]\s*/
!ll&&!rl&&r
70088
MC/DC50%1/2
$self->{"__list"}[$self->{"__listnum"} - 1] == $HTML::TextToHTML::UL and $para_lines_ref->[$ind] =~ /^\s*[$bullets]\s*/
$self->{"__list"}[$self->{"__listnum"} - 1] == $HTML::TextToHTML::UL $para_lines_ref->[$ind] =~ /^\s*[$bullets]\s*/
Truth table66%2/3
A and B
A= $self->{"__list"}[$self->{"__listnum"} - 1] == $HTML::TextToHTML::ULB= $para_lines_ref->[$ind] =~ /^\s*[$bullets]\s*/
ABresult
0X0
100
111
2764 && $para_lines_ref->[$ind] =~ /^\s*[${bullets}]\s*/)
2765 {
2766 88 $tag = $self->get_tag('li');
2767 88 $para_lines_ref->[$ind] =~ s/^\s*[${bullets}]\s*/${list_indent}${tag}/;
2768 88 $para_action_ref->[$ind] |= $LIST_ITEM;
2769 }
2770 158 ▶ if ($self->{__list}->[$self->{__listnum} - 1] == $OL)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__list"}[$self->{"__listnum"} - 1] == $HTML::TextToHTML::OL) 61 97 158
2771 {
2772 61 $tag = $self->get_tag('li');
2773 61 $para_lines_ref->[$ind] =~ s/^\s*${num_match}.\s*/${list_indent}${tag}/;
2774 61 $para_action_ref->[$ind] |= $LIST_ITEM;
2775 }
2776 158 ▶ if ( $self->{__list}->[$self->{__listnum} - 1] == $DL
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__list"}[$self->{"__listnum"} - 1] == $HTML::TextToHTML::DL and $term) 9 149 158
Condition66%2/3
$self->{"__list"}[$self->{"__listnum"} - 1] == $HTML::TextToHTML::DL and $term
!ll&&!rl&&r
14909
MC/DC50%1/2
$self->{"__list"}[$self->{"__listnum"} - 1] == $HTML::TextToHTML::DL and $term
$self->{"__list"}[$self->{"__listnum"} - 1] == $HTML::TextToHTML::DL $term
Truth table66%2/3
A and B
A= $self->{"__list"}[$self->{"__listnum"} - 1] == $HTML::TextToHTML::DLB= $term
ABresult
0X0
100
111
2777 && $term)
2778 {
2779 9 $tag = $self->get_tag('dt');
2780 9 my $tag2 = $self->get_tag('dt', tag_type => TAG_END);
2781 9 $term =~ s/_/ /g; # underscores are now spaces in the term
2782 9 $para_lines_ref->[$ind] =~
2783 s/^\s*${term_match}.$/${list_indent}${tag}${term}${tag2}/;
2784 9 $tag = $self->get_tag('dd');
2785 9 $para_lines_ref->[$ind] .= ${tag};
2786 9 $para_action_ref->[$ind] |= $LIST_ITEM;
2787 }
2788 158 $para_action_ref->[$ind] |= $LIST;
2789 } # continuelist
2790  
2791 =head2 liststuff
2792  
2793 $self->liststuff(para_lines_ref=>$para_lines_ref,
2794 para_action_ref=>$para_action_ref,
2795 para_line_indent_ref=>$para_line_indent_ref,
2796 ind=>0,
2797 prev_ref=>$prev_ref);
2798  
2799 Process a list (higher-level method).
2800  
2801 =cut
2802 sub liststuff ($%)
2803 1060 ▶{
Subroutine liststuff: called CC=26 SCAR=32.8
Pod documented
2804 1060 my $self = shift;
2805 1060 my %args = (
2806 para_lines_ref => undef,
2807 para_action_ref => undef,
2808 para_line_indent_ref => undef,
2809 ind => 0,
2810 prev_ref => undef,
2811 @_
2812 );
2813 1060 my $para_lines_ref = $args{para_lines_ref};
2814 1060 my $para_action_ref = $args{para_action_ref};
2815 1060 my $para_line_indent_ref = $args{para_line_indent_ref};
2816 1060 my $ind = $args{ind};
2817 1060 my $prev_ref = $args{prev_ref};
2818  
2819 1060 my $i;
2820  
2821 1060 my ($prefix, $number, $rawprefix, $term) =
2822 $self->listprefix($para_lines_ref->[$ind]);
2823  
2824 1060 ▶ if (!$prefix)
Branch: 1 branch
BranchTrueFalseTotal
unless ($prefix) 896 164 1060
2825 {
2826 # if the previous line is not blank
2827 896 ▶ if ($ind > 0 && $para_lines_ref->[$ind - 1] !~ /^\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($ind > 0 and not $$para_lines_ref[$ind - 1] =~ /^\s*$/) 592 304 896
Condition100%3/3
$ind > 0 and not $$para_lines_ref[$ind - 1] =~ /^\s*$/
!ll&&!rl&&r
29113592
MC/DC100%2/2
$ind > 0 and not $$para_lines_ref[$ind - 1] =~ /^\s*$/
$ind > 0 not $$para_lines_ref[$ind - 1] =~ /^\s*$/
Truth table100%3/3
A and not(B)
A= $ind > 0B= not $$para_lines_ref[$ind - 1] =~ /^\s*$/
ABresult
0X0
100
111
2828 {
2829 # inside a list item
2830 592 return;
2831 }
2832 # This might be a new paragraph within an existing list item;
2833 # It will be the first line, and have the same indentation
2834 # as the list's indentation.
2835 304 ▶ if ( $ind == 0
Branch: 1 branch
BranchTrueFalseTotal
if ($ind == 0 and $self->{"__listnum"} and $para_line_indent_ref->[$ind] == $self->{"__list_indent"}[$self->{"__listnum"} - 1]) 12 292 304
Condition100%6/6
$ind == 0 and $self->{"__listnum"} and $para_line_indent_ref->[$ind] == $self->{"__list_indent"}[$self->{"__listnum"} - 1]
!ll&&!rl&&r
2771512
$ind == 0 and $self->{"__listnum"}
!ll&&!rl&&r
1326427
MC/DC100%3/3
$ind == 0 and $self->{"__listnum"} and $para_line_indent_ref->[$ind] == $self->{"__list_indent"}[$self->{"__listnum"} - 1]
$ind == 0 $self->{"__listnum"} $para_line_indent_ref->[$ind] == $self->{"__list_indent"}[$self->{"__listnum"} - 1]
Truth table100%4/4
A and B and C
A= $ind == 0B= $self->{"__listnum"}C= $para_line_indent_ref->[$ind] == $self->{"__list_indent"}[$self->{"__listnum"} - 1]
ABCresult
0XX0
10X0
1100
1111
2836 && $self->{__listnum}
2837 && $para_line_indent_ref->[$ind] ==
2838 $self->{__list_indent}->[$self->{__listnum} - 1])
2839 {
2840 # start a paragraph
2841 12 my $tag = $self->get_tag('p');
2842 12 ${$prev_ref} .= $tag;
2843 12 $para_action_ref->[$ind] |= $PAR;
2844 12 return;
2845 }
2846 # This ain't no list. We'll want to end all of them.
2847 292 ▶ if ($self->{__listnum})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__listnum"}) 16 276 292
2848 {
2849 $self->endlist(
2850 num_lists => $self->{__listnum},
2851 16 prev_ref => $prev_ref,
2852 line_action_ref => \$para_action_ref->[$ind]
2853 );
2854 }
2855 292 return;
2856 }
2857  
2858 # If numbers with more than one digit grow to the left instead of
2859 # to the right, the prefix will shrink and we'll fail to match the
2860 # right list. We need to account for this.
2861 164 my $prefix_alternate;
2862 164 ▶ if (length("" . $number) > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (length '' . $number > 1) 0 164 164
2863 {
2864 0 $prefix_alternate = (" " x (length("" . $number) - 1)) . $prefix;
2865 }
2866  
2867 # Maybe we're going back up to a previous list
2868 164 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0 and $prefix ne $self->{"__listprefix"}[$i]) 73 164 237
Condition100%3/3
$i >= 0 and $prefix ne $self->{"__listprefix"}[$i]
!ll&&!rl&&r
709473
MC/DC100%2/2
$i >= 0 and $prefix ne $self->{"__listprefix"}[$i]
$i >= 0 $prefix ne $self->{"__listprefix"}[$i]
Truth table100%3/3
A and B
A= $i >= 0B= $prefix ne $self->{"__listprefix"}[$i]
ABresult
0X0
100
111
2869 $i = $self->{__listnum} - 1;
2870 ($i >= 0) && ($prefix ne $self->{__listprefix}->[$i]);
2871 $i--
2872 )
2873 {
2874 73 ▶ if (length("" . $number) > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (length '' . $number > 1) 0 73 73
2875 {
2876 0 ▶ last if $prefix_alternate eq $self->{__listprefix}->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $prefix_alternate eq $self->{"__listprefix"}[$i] 0 0 0
2877 }
2878 }
2879  
2880 164 my $islist;
2881  
2882 # Measure the indent from where the text starts, not where the
2883 # prefix starts. This won't screw anything up, and if we don't do
2884 # it, the next line might appear to be indented relative to this
2885 # line, and get tagged as a new paragraph.
2886 164 my $bullets = $self->{bullets};
2887 164 my $bullets_ordered = $self->{bullets_ordered};
2888 164 my $term_match = $self->{__term_match};
2889 164 my ($total_prefix) =
2890 $para_lines_ref->[$ind] =~ /^(\s*[${bullets}${bullets_ordered}\w]+.\s*)/;
2891 # a DL indent starts from the edge of the term, plus indent_width
2892 164 ▶ if ($term)
Branch: 1 branch
BranchTrueFalseTotal
if ($term) 9 155 164
2893 {
2894 9 ($total_prefix) = $para_lines_ref->[$ind] =~ /^(\s*)${term_match}.$/;
2895 9 $total_prefix .= " " x $self->{indent_width};
2896 }
2897  
2898 # Of course, we only use it if it really turns out to be a list.
2899  
2900 164 $islist = 1;
2901 164 $i++;
2902 164 ▶ if (($i > 0) && ($i != $self->{__listnum}))
Branch: 2 branches
BranchTrueFalseTotal
if ($i > 0 and $i != $self->{'__listnum'}) { } 23 141 164
elsif (not $self->{'__listnum'} or $i != $self->{'__listnum'}) { } 70 71 141
Condition100%3/3
$i > 0 and $i != $self->{"__listnum"}
!ll&&!rl&&r
707123
MC/DC100%2/2
$i > 0 and $i != $self->{"__listnum"}
$i > 0 $i != $self->{"__listnum"}
Truth table100%3/3
A and B
A= $i > 0B= $i != $self->{"__listnum"}
ABresult
0X0
100
111
2903 {
2904 $self->endlist(
2905 23 num_lists => $self->{__listnum} - $i,
2906 prev_ref => $prev_ref,
2907 line_action_ref => \$para_action_ref->[$ind]
2908 );
2909 23 $islist = 0;
2910 }
2911 ▶ elsif (!$self->{__listnum} || ($i != $self->{__listnum}))
Condition100%3/3
not $self->{"__listnum"} or $i != $self->{"__listnum"}
l!l&&r!l&&!r
363471
MC/DC100%2/2
not $self->{"__listnum"} or $i != $self->{"__listnum"}
not $self->{"__listnum"} $i != $self->{"__listnum"}
Truth table100%3/3
not(A) or B
A= not $self->{"__listnum"}B= $i != $self->{"__listnum"}
ABresult
1X1
011
000
2912 {
2913 70 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($para_line_indent_ref->[$ind] > 0 or $ind == 0 or $ind > 0 and $$para_lines_ref[$ind - 1] =~ /^\s*$/ or $ind > 0 and $$para_action_ref[$ind - 1] & ($HTML::TextToHTML::BREAK | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::CAPS)) { } 68 2 70
Condition73%11/15
$para_line_indent_ref->[$ind] > 0 or $ind == 0 or $ind > 0 and $$para_lines_ref[$ind - 1] =~ /^\s*$/ or $ind > 0 and $$para_action_ref[$ind - 1] & ($HTML::TextToHTML::BREAK | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::CAPS)
l!l&&r!l&&!r
6802
$para_line_indent_ref->[$ind] > 0 or $ind == 0 or $ind > 0 and $$para_lines_ref[$ind - 1] =~ /^\s*$/
l!l&&r!l&&!r
6622
$para_line_indent_ref->[$ind] > 0 or $ind == 0
l!l&&r!l&&!r
47194
$ind > 0 and $$para_lines_ref[$ind - 1] =~ /^\s*$/
!ll&&!rl&&r
022
$ind > 0 and $$para_action_ref[$ind - 1] & ($HTML::TextToHTML::BREAK | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::CAPS)
!ll&&!rl&&r
020
MC/DC50%3/6
$para_line_indent_ref->[$ind] > 0 or $ind == 0 or $ind > 0 and $$para_lines_ref[$ind - 1] =~ /^\s*$/ or $ind > 0 and $$para_action_ref[$ind - 1] & ($HTML::TextToHTML::BREAK | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::CAPS)
$para_line_indent_ref->[$ind] > 0 $ind == 0 $ind > 0 $$para_lines_ref[$ind - 1] =~ /^\s*$/ $ind > 0 $$para_action_ref[$ind - 1] & ($HTML::TextToHTML::BREAK | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::CAPS)
Truth table44%4/9
A or B or C and D or E and F
A= $para_line_indent_ref->[$ind] > 0B= $ind == 0C= $ind > 0D= $$para_lines_ref[$ind - 1] =~ /^\s*$/E= $ind > 0F= $$para_action_ref[$ind - 1] & ($HTML::TextToHTML::BREAK | $HTML::TextToHTML::HEADER | $HTML::TextToHTML::CAPS)
ABCDEFresult
1XXXXX1
01XXXX1
0011XX1
000X111
0010111
000X0X0
000X100
00100X0
0010100
2914 ($para_line_indent_ref->[$ind] > 0)
2915 || $ind == 0
2916 || ($ind > 0 && ($para_lines_ref->[$ind - 1] =~ /^\s*$/))
2917 || ( $ind > 0
2918 && $para_action_ref->[$ind - 1] & ($BREAK | $HEADER | $CAPS))
2919 )
2920 {
2921 68 $islist = $self->startlist(
2922 prefix => $prefix,
2923 number => $number,
2924 rawprefix => $rawprefix,
2925 term => $term,
2926 para_lines_ref => $para_lines_ref,
2927 para_action_ref => $para_action_ref,
2928 ind => $ind,
2929 prev_ref => $prev_ref,
2930 total_prefix => $total_prefix
2931 );
2932 }
2933 else
2934 {
2935  
2936 # We have something like this: "- foo" which usually
2937 # turns out not to be a list.
2938 2 return;
2939 }
2940 }
2941  
2942 $self->continuelist(
2943 para_lines_ref => $para_lines_ref,
2944 para_action_ref => $para_action_ref,
2945 ind => $ind,
2946 term => $term
2947 )
2948 162 ▶ if ($self->{__mode} & $LIST);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__mode"} & $HTML::TextToHTML::LIST 158 4 162
2949 162 ▶ $para_line_indent_ref->[$ind] = length($total_prefix) if $islist;
Branch: 1 branch
BranchTrueFalseTotal
if $islist 135 27 162
2950 } # liststuff
2951  
2952 =head2 get_table_type
2953  
2954 $table_type = $self->get_table_type(rows_ref=>$rows_ref,
2955 para_len=>0);
2956  
2957 Figure out the table type of this table, if any
2958  
2959 =cut
2960 sub get_table_type ($%)
2961 123 ▶{
Subroutine get_table_type: called CC=9 SCAR=22.2
Pod documented
2962 123 my $self = shift;
2963 123 my %args = (
2964 rows_ref => undef,
2965 para_len => 0,
2966 @_
2967 );
2968 123 my $table_type = 0;
2969 123 ▶ if ( $self->{table_type}->{DELIM}
Branch: 4 branches
BranchTrueFalseTotal
if ($self->{'table_type'}{'DELIM'} and $self->is_delim_table(%args)) { } 7 116 123
elsif ($self->{'table_type'}{'ALIGN'} and $self->is_aligned_table(%args)) { } 7 109 116
elsif ($self->{'table_type'}{'PGSQL'} and $self->is_pgsql_table(%args)) { } 4 105 109
elsif ($self->{'table_type'}{'BORDER'} and $self->is_border_table(%args)) { } 4 101 105
Condition66%2/3
$self->{"table_type"}{"DELIM"} and $self->is_delim_table(%args)
!ll&&!rl&&r
01167
MC/DC50%1/2
$self->{"table_type"}{"DELIM"} and $self->is_delim_table(%args)
$self->{"table_type"}{"DELIM"} $self->is_delim_table(%args)
Truth table66%2/3
A and B
A= $self->{"table_type"}{"DELIM"}B= $self->is_delim_table(%args)
ABresult
0X0
100
111
2970 && $self->is_delim_table(%args))
2971 {
2972 7 $table_type = $TAB_DELIM;
2973 }
2974 ▶ elsif ($self->{table_type}->{ALIGN}
Condition66%2/3
$self->{"table_type"}{"ALIGN"} and $self->is_aligned_table(%args)
!ll&&!rl&&r
01097
MC/DC50%1/2
$self->{"table_type"}{"ALIGN"} and $self->is_aligned_table(%args)
$self->{"table_type"}{"ALIGN"} $self->is_aligned_table(%args)
Truth table66%2/3
A and B
A= $self->{"table_type"}{"ALIGN"}B= $self->is_aligned_table(%args)
ABresult
0X0
100
111
2975 && $self->is_aligned_table(%args))
2976 {
2977 7 $table_type = $TAB_ALIGN;
2978 }
2979 ▶ elsif ($self->{table_type}->{PGSQL}
Condition66%2/3
$self->{"table_type"}{"PGSQL"} and $self->is_pgsql_table(%args)
!ll&&!rl&&r
01054
MC/DC50%1/2
$self->{"table_type"}{"PGSQL"} and $self->is_pgsql_table(%args)
$self->{"table_type"}{"PGSQL"} $self->is_pgsql_table(%args)
Truth table66%2/3
A and B
A= $self->{"table_type"}{"PGSQL"}B= $self->is_pgsql_table(%args)
ABresult
0X0
100
111
2980 && $self->is_pgsql_table(%args))
2981 {
2982 4 $table_type = $TAB_PGSQL;
2983 }
2984 ▶ elsif ($self->{table_type}->{BORDER}
Condition66%2/3
$self->{"table_type"}{"BORDER"} and $self->is_border_table(%args)
!ll&&!rl&&r
01014
MC/DC50%1/2
$self->{"table_type"}{"BORDER"} and $self->is_border_table(%args)
$self->{"table_type"}{"BORDER"} $self->is_border_table(%args)
Truth table66%2/3
A and B
A= $self->{"table_type"}{"BORDER"}B= $self->is_border_table(%args)
ABresult
0X0
100
111
2985 && $self->is_border_table(%args))
2986 {
2987 4 $table_type = $TAB_BORDER;
2988 }
2989  
2990 123 return $table_type;
2991 }
2992  
2993 =head2 is_aligned_table
2994  
2995 if ($self->is_aligned_table(rows_ref=>$rows_ref, para_len=>0))
2996 {
2997 ...
2998 }
2999  
3000 Check if the given paragraph-array is an aligned table
3001  
3002 =cut
3003 sub is_aligned_table ($%)
3004 116 ▶{
Subroutine is_aligned_table: called CC=8 SCAR=20.8
Pod documented
3005 116 my $self = shift;
3006 116 my %args = (
3007 rows_ref => undef,
3008 para_len => 0,
3009 @_
3010 );
3011 116 my $rows_ref = $args{rows_ref};
3012 116 my $para_len = $args{para_len};
3013  
3014 # TABLES: spot and mark up tables. We combine the lines of the
3015 # paragraph using the string bitwise or (|) operator, the result
3016 # being in $spaces. A character in $spaces is a space only if
3017 # there was a space at that position in every line of the
3018 # paragraph. $space can be used to search for contiguous spaces
3019 # that occur on all lines of the paragraph. If this results in at
3020 # least two columns, the paragraph is identified as a table.
3021  
3022 # Note that this sub must be called before checking for preformatted
3023 # lines because a table may well have whitespace to the left, in
3024 # which case it must not be incorrectly recognised as a preformat.
3025 116 my @rows = @{$rows_ref};
3026 116 my @starts;
3027 116 my $spaces = '';
3028 116 my $max = 0;
3029 116 my $min = $para_len;
3030 116 foreach my $row (@rows)
3031 {
3032 611 ($spaces |= $row) =~ tr/ /\xff/c;
3033 611 ▶ $min = length $row if length $row < $min;
Branch: 1 branch
BranchTrueFalseTotal
if length $row < $min 208 403 611
3034 611 ▶ $max = length $row if $max < length $row;
Branch: 1 branch
BranchTrueFalseTotal
if $max < length $row 193 418 611
3035 }
3036 116 $spaces = substr $spaces, 0, $min;
3037 116 ▶ push(@starts, 0) unless $spaces =~ /^ /;
Branch: 1 branch
BranchTrueFalseTotal
unless $spaces =~ /^ / 77 39 116
3038 116 ▶ while ($spaces =~ /((?:^| ) +)(?=[^ ])/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($spaces =~ /((?:^| ) +)(?=[^ ])/g) 47 116 163
3039 {
3040 47 push @starts, pos($spaces);
3041 }
3042  
3043 116 ▶ if (2 <= @rows and 2 <= @starts)
Branch: 1 branch
BranchTrueFalseTotal
if (2 <= @rows and 2 <= @starts) { } 7 109 116
Condition66%2/3
2 <= @rows and 2 <= @starts
!ll&&!rl&&r
01097
MC/DC50%1/2
2 <= @rows and 2 <= @starts
2 <= @rows 2 <= @starts
Truth table66%2/3
A and B
A= 2 <= @rowsB= 2 <= @starts
ABresult
0X0
100
111
3044 {
3045 7 return 1;
3046 }
3047 else
3048 {
3049 109 return 0;
3050 }
3051 }
3052  
3053 =head2 is_pgsql_table
3054  
3055 if ($self->is_pgsql_table(rows_ref=>$rows_ref, para_len=>0))
3056 {
3057 ...
3058 }
3059  
3060 Check if the given paragraph-array is a Postgresql table
3061 (the ascii format produced by Postgresql)
3062  
3063 A PGSQL table can start with an optional table-caption,
3064  
3065 then it has a row of column headings separated by |
3066 then it has a row of ------+-----
3067 then it has one or more rows of column values separated by |
3068 then it has a row-count (N rows)
3069  
3070 =cut
3071 sub is_pgsql_table ($%)
3072 109 ▶{
Subroutine is_pgsql_table: called CC=9 SCAR=22.3
Pod documented
3073 109 my $self = shift;
3074 109 my %args = (
3075 rows_ref => undef,
3076 para_len => 0,
3077 @_
3078 );
3079 109 my $rows_ref = $args{rows_ref};
3080 109 my $para_len = $args{para_len};
3081  
3082 # A PGSQL table must have at least 4 rows (see above).
3083 109 ▶ if (@{$rows_ref} < 4)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rows_ref;} < 4) 63 46 109
3084 {
3085 63 return 0;
3086 }
3087  
3088 46 my @rows = @{$rows_ref};
3089 46 ▶ if ($rows[0] !~ /\|/ && $rows[0] =~ /^\s*\w+/) # possible caption
Branch: 1 branch
BranchTrueFalseTotal
if (not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/) 29 17 46
Condition100%3/3
not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/
!ll&&!rl&&r
31429
MC/DC100%2/2
not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/
not $rows[0] =~ /\|/ $rows[0] =~ /^\s*\w+/
Truth table100%3/3
not(A) and B
A= not $rows[0] =~ /\|/B= $rows[0] =~ /^\s*\w+/
ABresult
0X0
100
111
3090 {
3091 29 shift @rows;
3092 }
3093 46 ▶ if (@rows < 4)
Branch: 1 branch
BranchTrueFalseTotal
if (@rows < 4) 10 36 46
3094 {
3095 10 return 0;
3096 }
3097 36 ▶ if ($rows[0] !~ /^\s*\w+\s+\|\s+/) # Colname |
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows[0] =~ /^\s*\w+\s+\|\s+/) 32 4 36
3098 {
3099 32 return 0;
3100 }
3101 4 ▶ if ($rows[1] !~ /^\s*[-]+[+][-]+/) # ----+----
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows[1] =~ /^\s*[-]+[+][-]+/) 0 4 4
3102 {
3103 0 return 0;
3104 }
3105 4 ▶ if ($rows[2] !~ /^\s*[^|]*\s+\|\s+/) # value |
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows[2] =~ /^\s*[^|]*\s+\|\s+/) 0 4 4
3106 {
3107 0 return 0;
3108 }
3109 # check the last row for rowcount
3110 4 ▶ if ($rows[$#rows] !~ /\(\d+\s+rows\)/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows[$#rows] =~ /\(\d+\s+rows\)/) 0 4 4
3111 {
3112 0 return 0;
3113 }
3114  
3115 4 return 1;
3116 }
3117  
3118 =head2 is_border_table
3119  
3120 if ($self->is_border_table(rows_ref=>$rows_ref, para_len=>0))
3121 {
3122 ...
3123 }
3124  
3125 Check if the given paragraph-array is a Border table.
3126  
3127 A BORDER table can start with an optional table-caption,
3128  
3129 then it has a row of +------+-----+
3130 then it has a row of column headings separated by |
3131 then it has a row of +------+-----+
3132 then it has one or more rows of column values separated by |
3133 then it has a row of +------+-----+
3134  
3135 =cut
3136 sub is_border_table ($%)
3137 105 ▶{
Subroutine is_border_table: called CC=10 SCAR=23.9
Pod documented
3138 105 my $self = shift;
3139 105 my %args = (
3140 rows_ref => undef,
3141 para_len => 0,
3142 @_
3143 );
3144 105 my $rows_ref = $args{rows_ref};
3145 105 my $para_len = $args{para_len};
3146  
3147 # A BORDER table must have at least 5 rows (see above)
3148 # And note that it could be indented with spaces
3149 105 ▶ if (@{$rows_ref} < 5)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rows_ref;} < 5) 77 28 105
3150 {
3151 77 return 0;
3152 }
3153  
3154 28 my @rows = @{$rows_ref};
3155 28 ▶ if ($rows[0] !~ /\|/ && $rows[0] =~ /^\s*\w+/) # possible caption
Branch: 1 branch
BranchTrueFalseTotal
if (not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/) 18 10 28
Condition66%2/3
not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/
!ll&&!rl&&r
01018
MC/DC50%1/2
not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/
not $rows[0] =~ /\|/ $rows[0] =~ /^\s*\w+/
Truth table66%2/3
not(A) and B
A= not $rows[0] =~ /\|/B= $rows[0] =~ /^\s*\w+/
ABresult
0X0
100
111
3156 {
3157 18 shift @rows;
3158 }
3159 28 ▶ if (@rows < 5)
Branch: 1 branch
BranchTrueFalseTotal
if (@rows < 5) 8 20 28
3160 {
3161 8 return 0;
3162 }
3163 20 ▶ if ($rows[0] !~ /^\s*[+][-]+[+][-]+[+][-+]*$/) # +----+----+
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows[0] =~ /^\s*[+][-]+[+][-]+[+][-+]*$/) 16 4 20
3164 {
3165 16 return 0;
3166 }
3167 4 ▶ if ($rows[1] !~ /^\s*\|\s*\w+\s+\|\s+.*\|$/) # | Colname |
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows[1] =~ /^\s*\|\s*\w+\s+\|\s+.*\|$/) 0 4 4
3168 {
3169 0 return 0;
3170 }
3171 4 ▶ if ($rows[2] !~ /^\s*[+][-]+[+][-]+[+][-+]*$/) # +----+----+
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows[2] =~ /^\s*[+][-]+[+][-]+[+][-+]*$/) 0 4 4
3172 {
3173 0 return 0;
3174 }
3175 4 ▶ if ($rows[3] !~ /^\s*\|\s*[^|]*\s+\|\s+.*\|$/) # | value |
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows[3] =~ /^\s*\|\s*[^|]*\s+\|\s+.*\|$/) 0 4 4
3176 {
3177 0 return 0;
3178 }
3179 # check the last row for +------+------+
3180 4 ▶ if ($rows[$#rows] !~ /^\s*[+][-]+[+][-]+[+][-+]*$/) # +----+----+
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows[$#rows] =~ /^\s*[+][-]+[+][-]+[+][-+]*$/) 0 4 4
3181 {
3182 0 return 0;
3183 }
3184  
3185 4 return 1;
3186 } # is_border_table
3187  
3188 =head2 is_delim_table
3189  
3190 if ($self->is_delim_table(rows_ref=>$rows_ref, para_len=>0))
3191 {
3192 ...
3193 }
3194  
3195 Check if the given paragraph-array is a Delimited table.
3196  
3197 A DELIM table can start with an optional table-caption,
3198 then it has at least two rows which start and end and are
3199 punctuated by a non-alphanumeric delimiter.
3200  
3201 | val1 | val2 |
3202 | val3 | val4 |
3203  
3204 =cut
3205 sub is_delim_table ($%)
3206 123 ▶{
Subroutine is_delim_table: called CC=12 SCAR=24.9
Pod documented
3207 123 my $self = shift;
3208 123 my %args = (
3209 rows_ref => undef,
3210 para_len => 0,
3211 @_
3212 );
3213 123 my $rows_ref = $args{rows_ref};
3214 123 my $para_len = $args{para_len};
3215  
3216 #
3217 # And note that it could be indented with spaces
3218 123 ▶ if (@{$rows_ref} < 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rows_ref;} < 2) 0 123 123
3219 {
3220 0 return 0;
3221 }
3222  
3223 123 my @rows = @{$rows_ref};
3224 123 ▶ if ($rows[0] !~ /[^\w\s]/ && $rows[0] =~ /^\s*\w+/) # possible caption
Branch: 1 branch
BranchTrueFalseTotal
if (not $rows[0] =~ /[^\w\s]/ and $rows[0] =~ /^\s*\w+/) 44 79 123
Condition66%2/3
not $rows[0] =~ /[^\w\s]/ and $rows[0] =~ /^\s*\w+/
!ll&&!rl&&r
79044
MC/DC50%1/2
not $rows[0] =~ /[^\w\s]/ and $rows[0] =~ /^\s*\w+/
not $rows[0] =~ /[^\w\s]/ $rows[0] =~ /^\s*\w+/
Truth table66%2/3
not(A) and B
A= not $rows[0] =~ /[^\w\s]/B= $rows[0] =~ /^\s*\w+/
ABresult
0X0
100
111
3225 {
3226 44 shift @rows;
3227 }
3228 123 ▶ if (@rows < 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@rows < 2) 30 93 123
3229 {
3230 30 return 0;
3231 }
3232 # figure out if the row starts with a possible delimiter
3233 93 my $delim = '';
3234 93 ▶ if ($rows[0] =~ /^\s*([^[:alnum:]])/)
Branch: 1 branch
BranchTrueFalseTotal
if ($rows[0] =~ /^\s*([^[:alnum:]])/) { } 55 38 93
3235 {
3236 55 $delim = $1;
3237 # have to get rid of ^ and [] and \
3238 55 $delim =~ s/\^//g;
3239 55 $delim =~ s/\[//g;
3240 55 $delim =~ s/\]//g;
3241 55 $delim =~ s/\\//g;
3242 55 ▶ if (!$delim) # no delimiter after all
Branch: 1 branch
BranchTrueFalseTotal
unless ($delim) 1 54 55
3243 {
3244 1 return 0;
3245 }
3246 }
3247 else
3248 {
3249 38 return 0;
3250 }
3251 # There needs to be at least three delimiters in the row
3252 54 my @all_delims = ($rows[0] =~ /[${delim}]/g);
3253 54 my $total_num_delims = @all_delims;
3254 54 ▶ if ($total_num_delims < 3)
Branch: 1 branch
BranchTrueFalseTotal
if ($total_num_delims < 3) 16 38 54
3255 {
3256 16 return 0;
3257 }
3258 # All rows must start and end with the delimiter
3259 # and have $total_num_delims number of them
3260 38 foreach my $row (@rows)
3261 {
3262 71 ▶ if ($row !~ /^\s*[${delim}]/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($row =~ /^\s*[$delim]/) 8 63 71
3263 {
3264 8 return 0;
3265 }
3266 63 ▶ if ($row !~ /[${delim}]\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($row =~ /[$delim]\s*$/) 23 40 63
3267 {
3268 23 return 0;
3269 }
3270 40 @all_delims = ($row =~ /[${delim}]/g);
3271 40 ▶ if (@all_delims != $total_num_delims)
Branch: 1 branch
BranchTrueFalseTotal
if (@all_delims != $total_num_delims) 0 40 40
3272 {
3273 0 return 0;
3274 }
3275 }
3276  
3277 7 return 1;
3278 } # is_delim_table
3279  
3280 =head2 tablestuff
3281  
3282 $self->tablestuff(table_type=>0,
3283 rows_ref=>$rows_ref,
3284 para_len=>0);
3285  
3286 Process a table.
3287  
3288 =cut
3289 sub tablestuff ($%)
3290 22 ▶{
Subroutine tablestuff: called CC=5 SCAR=16.1
Pod documented
3291 22 my $self = shift;
3292 22 my %args = (
3293 table_type => 0,
3294 rows_ref => undef,
3295 para_len => 0,
3296 @_
3297 );
3298 22 my $table_type = $args{table_type};
3299 22 ▶ if ($table_type eq $TAB_ALIGN)
Branch: 1 branch
BranchTrueFalseTotal
if ($table_type eq $HTML::TextToHTML::TAB_ALIGN) 7 15 22
3300 {
3301 7 return $self->make_aligned_table(%args);
3302 }
3303 15 ▶ if ($table_type eq $TAB_PGSQL)
Branch: 1 branch
BranchTrueFalseTotal
if ($table_type eq $HTML::TextToHTML::TAB_PGSQL) 4 11 15
3304 {
3305 4 return $self->make_pgsql_table(%args);
3306 }
3307 11 ▶ if ($table_type eq $TAB_BORDER)
Branch: 1 branch
BranchTrueFalseTotal
if ($table_type eq $HTML::TextToHTML::TAB_BORDER) 4 7 11
3308 {
3309 4 return $self->make_border_table(%args);
3310 }
3311 7 ▶ if ($table_type eq $TAB_DELIM)
Branch: 1 branch
BranchTrueFalseTotal
if ($table_type eq $HTML::TextToHTML::TAB_DELIM) 7 0 7
3312 {
3313 7 return $self->make_delim_table(%args);
3314 }
3315 } # tablestuff
3316  
3317 =head2 make_aligned_table
3318  
3319 $self->make_aligned_table(rows_ref=>$rows_ref,
3320 para_len=>0);
3321  
3322 Make an Aligned table.
3323  
3324 =cut
3325 sub make_aligned_table ($%)
3326 7 ▶{
Subroutine make_aligned_table: called CC=21 SCAR=30.5
Pod documented
3327 7 my $self = shift;
3328 7 my %args = (
3329 rows_ref => undef,
3330 para_len => 0,
3331 @_
3332 );
3333 7 my $rows_ref = $args{rows_ref};
3334 7 my $para_len = $args{para_len};
3335  
3336 # TABLES: spot and mark up tables. We combine the lines of the
3337 # paragraph using the string bitwise or (|) operator, the result
3338 # being in $spaces. A character in $spaces is a space only if
3339 # there was a space at that position in every line of the
3340 # paragraph. $space can be used to search for contiguous spaces
3341 # that occur on all lines of the paragraph. If this results in at
3342 # least two columns, the paragraph is identified as a table.
3343  
3344 # Note that this sub must be called before checking for preformatted
3345 # lines because a table may well have whitespace to the left, in
3346 # which case it must not be incorrectly recognised as a preformat.
3347 7 my @rows = @{$rows_ref};
3348 7 my @starts;
3349 my @ends;
3350 7 my $spaces;
3351 7 my $max = 0;
3352 7 my $min = $para_len;
3353 7 foreach my $row (@rows)
3354 {
3355 33 ($spaces |= $row) =~ tr/ /\xff/c;
3356 33 ▶ $min = length $row if length $row < $min;
Branch: 1 branch
BranchTrueFalseTotal
if length $row < $min 10 23 33
3357 33 ▶ $max = length $row if $max < length $row;
Branch: 1 branch
BranchTrueFalseTotal
if $max < length $row 18 15 33
3358 }
3359 7 $spaces = substr $spaces, 0, $min;
3360 7 ▶ push(@starts, 0) unless $spaces =~ /^ /;
Branch: 1 branch
BranchTrueFalseTotal
unless $spaces =~ /^ / 3 4 7
3361 7 ▶ while ($spaces =~ /((?:^| ) +)(?=[^ ])/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($spaces =~ /((?:^| ) +)(?=[^ ])/g) 12 7 19
3362 {
3363 12 push @ends, pos($spaces) - length $1;
3364 12 push @starts, pos($spaces);
3365 }
3366 7 ▶ shift(@ends) if $spaces =~ /^ /;
Branch: 1 branch
BranchTrueFalseTotal
if $spaces =~ /^ / 4 3 7
3367 7 push(@ends, $max);
3368  
3369 # Two or more rows and two or more columns indicate a table.
3370 7 ▶ if (2 <= @rows and 2 <= @starts)
Branch: 1 branch
BranchTrueFalseTotal
if (2 <= @rows and 2 <= @starts) { } 7 0 7
Condition33%1/3
2 <= @rows and 2 <= @starts
!ll&&!rl&&r
007
MC/DC0%0/2
2 <= @rows and 2 <= @starts
2 <= @rows 2 <= @starts
Truth table33%1/3
A and B
A= 2 <= @rowsB= 2 <= @starts
ABresult
0X0
100
111
3371 {
3372 7 $self->{__mode} |= $TABLE;
3373  
3374 # For each column, guess whether it should be left, centre or
3375 # right aligned by examining all cells in that column for space
3376 # to the left or the right. A simple majority among those cells
3377 # that actually have space to one side or another decides (if no
3378 # alignment gets a majority, left alignment wins by default).
3379 7 my @align;
3380 7 my $cell = '';
3381 7 foreach my $col (0 .. $#starts)
3382 {
3383 15 my @count = (0, 0, 0, 0);
3384 15 foreach my $row (@rows)
3385 {
3386 69 my $width = $ends[$col] - $starts[$col];
3387 69 $cell = substr $row, $starts[$col], $width;
3388 69 ▶ ++$count[($cell =~ /^ / ? 2 : 0) +
Branch: 2 branches
BranchTrueFalseTotal
$cell =~ /^ / ? : 16 53 69
$cell =~ / $/ || length $cell < $width ? : 36 33 69
Condition100%3/3
$cell =~ / $/ or length $cell < $width
l!l&&r!l&&!r
102633
MC/DC100%2/2
$cell =~ / $/ or length $cell < $width
$cell =~ / $/ length $cell < $width
Truth table100%3/3
A or B
A= $cell =~ / $/B= length $cell < $width
ABresult
1X1
011
000
3389 ($cell =~ / $/ || length($cell) < $width ? 1 : 0)];
3390 }
3391 15 $align[$col] = 0;
3392 15 my $population = $count[1] + $count[2] + $count[3];
3393 15 foreach (1 .. 3)
3394 {
3395 24 ▶ if ($count[$_] * 2 > $population)
Branch: 1 branch
BranchTrueFalseTotal
if ($count[$_] * 2 > $population) 12 12 24
3396 {
3397 12 $align[$col] = $_;
3398 12 last;
3399 }
3400 }
3401 }
3402  
3403 7 foreach my $row (@rows)
3404 {
3405 $row = join '', $self->get_tag('tr'), (
3406 map {
3407 33 $cell = substr $row, $starts[$_], $ends[$_] - $starts[$_];
3408 69 $cell =~ s/^ +//;
3409 69 $cell =~ s/ +$//;
3410  
3411 69 ▶ if ($self->{escape_HTML_chars})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"escape_HTML_chars"}) 69 0 69
3412 {
3413 69 $cell = escape($cell);
3414 }
3415  
3416 (
3417 $self->get_tag(
3418 'td',
3419 inside_tag => (
3420 $self->{xhtml} ? $xhtml_alignments[$align[$_]]
3421 : (
3422 $self->{lower_case_tags}
3423 69 ▶ ? $lc_alignments[$align[$_]]
Branch: 2 branches
BranchTrueFalseTotal
$self->{'xhtml'} ? : 45 24 69
$self->{'lower_case_tags'} ? : 0 24 24
3424 : $alignments[$align[$_]]
3425 )
3426 )
3427 ),
3428 $cell,
3429 $self->close_tag('td')
3430 );
3431 } 0 .. $#starts
3432 ),
3433 $self->close_tag('tr');
3434 }
3435  
3436 # put the <TABLE> around the rows
3437 7 my $tag;
3438 7 ▶ if ($self->{xhtml})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'xhtml'}) { } 5 2 7
3439 {
3440 5 $tag = $self->get_tag('table', inside_tag => ' summary=""');
3441 }
3442 else
3443 {
3444 2 $tag = $self->get_tag('table');
3445 }
3446 7 $rows[0] = join("\n", $tag, $rows[0]);
3447 7 $tag = $self->close_tag('table', tag_type => TAG_END);
3448 7 $rows[$#rows] .= "\n${tag}";
3449 7 @{$rows_ref} = @rows;
3450 7 return 1;
3451 }
3452 else
3453 {
3454 0 return 0;
3455 }
3456 } # make_aligned_table
3457  
3458 =head2 make_pgsql_table
3459  
3460 $self->make_pgsql_table(rows_ref=>$rows_ref,
3461 para_len=>0);
3462  
3463 Make a PGSQL table.
3464  
3465 =cut
3466 sub make_pgsql_table ($%)
3467 4 ▶{
Subroutine make_pgsql_table: called CC=11 SCAR=24.0
Pod documented
3468 4 my $self = shift;
3469 4 my %args = (
3470 rows_ref => undef,
3471 para_len => 0,
3472 @_
3473 );
3474 4 my $rows_ref = $args{rows_ref};
3475 4 my $para_len = $args{para_len};
3476  
3477 # a PGSQL table can start with an optional table-caption,
3478 # then it has a row of column headings separated by |
3479 # then it has a row of ------+-----
3480 # then it has one or more rows of column values separated by |
3481 # then it has a row-count (N rows)
3482 # Thus it must have at least 4 rows.
3483 4 my @rows = @{$rows_ref};
3484 4 my $caption = '';
3485 4 ▶ if ($rows[0] !~ /\|/ && $rows[0] =~ /^\s*\w+/) # possible caption
Branch: 1 branch
BranchTrueFalseTotal
if (not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/) 1 3 4
Condition66%2/3
not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/
!ll&&!rl&&r
301
MC/DC50%1/2
not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/
not $rows[0] =~ /\|/ $rows[0] =~ /^\s*\w+/
Truth table66%2/3
not(A) and B
A= not $rows[0] =~ /\|/B= $rows[0] =~ /^\s*\w+/
ABresult
0X0
100
111
3486 {
3487 1 $caption = shift @rows;
3488 }
3489 4 my @headings = split(/\s+\|\s+/, shift @rows);
3490 # skip the ----+--- line
3491 4 shift @rows;
3492 # grab the N rows line
3493 4 my $n_rows = pop @rows;
3494  
3495 # now start making the table
3496 4 my @tab_lines = ();
3497 4 my $tag;
3498 my $tag2;
3499 4 ▶ if ($self->{xhtml})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'xhtml'}) { } 3 1 4
3500 {
3501 3 $tag = $self->get_tag('table', inside_tag => ' border="1" summary=""');
3502 }
3503 else
3504 {
3505 1 $tag = $self->get_tag('table', inside_tag => ' border="1"');
3506 }
3507 4 push @tab_lines, "$tag\n";
3508 4 ▶ if ($caption)
Branch: 1 branch
BranchTrueFalseTotal
if ($caption) 1 3 4
3509 {
3510 1 $caption =~ s/^\s+//;
3511 1 $caption =~ s/\s+$//;
3512 1 $tag = $self->get_tag('caption');
3513 1 $tag2 = $self->close_tag('caption');
3514 1 $caption = join('', $tag, $caption, $tag2, "\n");
3515 1 push @tab_lines, $caption;
3516 }
3517 # table header
3518 4 my $thead = '';
3519 4 $tag = $self->get_tag('thead');
3520 4 $thead .= $tag;
3521 4 $tag = $self->get_tag('tr');
3522 4 $thead .= $tag;
3523 4 foreach my $col (@headings)
3524 {
3525 18 $col =~ s/^\s+//;
3526 18 $col =~ s/\s+$//;
3527 18 $tag = $self->get_tag('th');
3528 18 $tag2 = $self->close_tag('th');
3529 18 $thead .= join('', $tag, $col, $tag2);
3530 }
3531 4 $tag = $self->close_tag('tr');
3532 4 $thead .= $tag;
3533 4 $tag = $self->close_tag('thead');
3534 4 $thead .= $tag;
3535 4 push @tab_lines, "${thead}\n";
3536 4 $tag = $self->get_tag('tbody');
3537 4 push @tab_lines, "$tag\n";
3538  
3539 # each row
3540 4 foreach my $row (@rows)
3541 {
3542 141 my $this_row = '';
3543 141 $tag = $self->get_tag('tr');
3544 141 $this_row .= $tag;
3545 141 my @cols = split(/\|/, $row);
3546 141 foreach my $cell (@cols)
3547 {
3548 1274 $cell =~ s/^\s+//;
3549 1274 $cell =~ s/\s+$//;
3550 1274 ▶ if ($self->{escape_HTML_chars})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"escape_HTML_chars"}) 1274 0 1274
3551 {
3552 1274 $cell = escape($cell);
3553 }
3554 1274 ▶ if (!$cell)
Branch: 1 branch
BranchTrueFalseTotal
unless ($cell) 422 852 1274
3555 {
3556 422 $cell = '&nbsp;';
3557 }
3558 1274 $tag = $self->get_tag('td');
3559 1274 $tag2 = $self->close_tag('td');
3560 1274 $this_row .= join('', $tag, $cell, $tag2);
3561 }
3562 141 $tag = $self->close_tag('tr');
3563 141 $this_row .= $tag;
3564 141 push @tab_lines, "${this_row}\n";
3565 }
3566  
3567 # end the table
3568 4 $tag = $self->close_tag('tbody');
3569 4 push @tab_lines, "$tag\n";
3570 4 $tag = $self->get_tag('table', tag_type => TAG_END);
3571 4 push @tab_lines, "$tag\n";
3572  
3573 # and add the N rows line
3574 4 $tag = $self->get_tag('p');
3575 4 push @tab_lines, "${tag}${n_rows}\n";
3576 4 ▶ if ($self->{xhtml})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"xhtml"}) 3 1 4
3577 {
3578 3 $tag = $self->get_tag('p', tag_type => TAG_END);
3579 3 $tab_lines[$#tab_lines] =~ s/\n/${tag}\n/;
3580 }
3581  
3582 # replace the rows
3583 4 @{$rows_ref} = @tab_lines;
3584 } # make_pgsql_table
3585  
3586 =head2 make_border_table
3587  
3588 $self->make_border_table(rows_ref=>$rows_ref,
3589 para_len=>0);
3590  
3591 Make a BORDER table.
3592  
3593 =cut
3594 sub make_border_table ($%)
3595 4 ▶{
Subroutine make_border_table: called CC=10 SCAR=23.5
Pod documented
3596 4 my $self = shift;
3597 4 my %args = (
3598 rows_ref => undef,
3599 para_len => 0,
3600 @_
3601 );
3602 4 my $rows_ref = $args{rows_ref};
3603 4 my $para_len = $args{para_len};
3604  
3605 # a BORDER table can start with an optional table-caption,
3606 # then it has a row of +------+-----+
3607 # then it has a row of column headings separated by |
3608 # then it has a row of +------+-----+
3609 # then it has one or more rows of column values separated by |
3610 # then it has a row of +------+-----+
3611 4 my @rows = @{$rows_ref};
3612 4 my $caption = '';
3613 4 ▶ if ($rows[0] !~ /\|/ && $rows[0] =~ /^\s*\w+/) # possible caption
Branch: 1 branch
BranchTrueFalseTotal
if (not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/) 0 4 4
Condition33%1/3
not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/
!ll&&!rl&&r
040
MC/DC0%0/2
not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/
not $rows[0] =~ /\|/ $rows[0] =~ /^\s*\w+/
Truth table33%1/3
not(A) and B
A= not $rows[0] =~ /\|/B= $rows[0] =~ /^\s*\w+/
ABresult
0X0
100
111
3614 {
3615 0 $caption = shift @rows;
3616 }
3617 # skip the +----+---+ line
3618 4 shift @rows;
3619 # get the head row and cut off the start and end |
3620 4 my $head_row = shift @rows;
3621 4 $head_row =~ s/^\s*\|//;
3622 4 $head_row =~ s/\|$//;
3623 4 my @headings = split(/\s+\|\s+/, $head_row);
3624 # skip the +----+---+ line
3625 4 shift @rows;
3626 # skip the last +----+---+ line
3627 4 pop @rows;
3628  
3629 # now start making the table
3630 4 my @tab_lines = ();
3631 4 my $tag;
3632 4 ▶ if ($self->{xhtml})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'xhtml'}) { } 3 1 4
3633 {
3634 3 $tag = $self->get_tag('table', inside_tag => ' border="1" summary=""');
3635 }
3636 else
3637 {
3638 1 $tag = $self->get_tag('table', inside_tag => ' border="1"');
3639 }
3640 4 push @tab_lines, "$tag\n";
3641 4 ▶ if ($caption)
Branch: 1 branch
BranchTrueFalseTotal
if ($caption) 0 4 4
3642 {
3643 0 $caption =~ s/^\s+//;
3644 0 $caption =~ s/\s+$//;
3645 0 $tag = $self->get_tag('caption');
3646 0 $caption = $tag . $caption;
3647 0 $tag = $self->close_tag('caption');
3648 0 $caption .= $tag;
3649 0 push @tab_lines, "$caption\n";
3650 }
3651 # table header
3652 4 my $thead = '';
3653 4 $tag = $self->get_tag('thead');
3654 4 $thead .= $tag;
3655 4 $tag = $self->get_tag('tr');
3656 4 $thead .= $tag;
3657 4 foreach my $col (@headings)
3658 {
3659 12 $col =~ s/^\s+//;
3660 12 $col =~ s/\s+$//;
3661 12 $tag = $self->get_tag('th');
3662 12 $thead .= $tag;
3663 12 $thead .= $col;
3664 12 $tag = $self->close_tag('th');
3665 12 $thead .= $tag;
3666 }
3667 4 $tag = $self->close_tag('tr');
3668 4 $thead .= $tag;
3669 4 $tag = $self->close_tag('thead');
3670 4 $thead .= $tag;
3671 4 push @tab_lines, "${thead}\n";
3672 4 $tag = $self->get_tag('tbody');
3673 4 push @tab_lines, "$tag\n";
3674  
3675 # each row
3676 4 foreach my $row (@rows)
3677 {
3678 # cut off the start and end |
3679 32 $row =~ s/^\s*\|//;
3680 32 $row =~ s/\|$//;
3681 32 my $this_row = '';
3682 32 $tag = $self->get_tag('tr');
3683 32 $this_row .= $tag;
3684 32 my @cols = split(/\|/, $row);
3685 32 foreach my $cell (@cols)
3686 {
3687 112 $cell =~ s/^\s+//;
3688 112 $cell =~ s/\s+$//;
3689 112 ▶ if ($self->{escape_HTML_chars})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"escape_HTML_chars"}) 112 0 112
3690 {
3691 112 $cell = escape($cell);
3692 }
3693 112 ▶ if (!$cell)
Branch: 1 branch
BranchTrueFalseTotal
unless ($cell) 0 112 112
3694 {
3695 0 $cell = '&nbsp;';
3696 }
3697 112 $tag = $self->get_tag('td');
3698 112 $this_row .= $tag;
3699 112 $this_row .= $cell;
3700 112 $tag = $self->close_tag('td');
3701 112 $this_row .= $tag;
3702 }
3703 32 $tag = $self->close_tag('tr');
3704 32 $this_row .= $tag;
3705 32 push @tab_lines, "${this_row}\n";
3706 }
3707  
3708 # end the table
3709 4 $tag = $self->close_tag('tbody');
3710 4 push @tab_lines, "$tag\n";
3711 4 $tag = $self->get_tag('table', tag_type => TAG_END);
3712 4 push @tab_lines, "$tag\n";
3713  
3714 # replace the rows
3715 4 @{$rows_ref} = @tab_lines;
3716 } # make_border_table
3717  
3718 =head2 make_delim_table
3719  
3720 $self->make_delim_table(rows_ref=>$rows_ref,
3721 para_len=>0);
3722  
3723 Make a Delimited table.
3724  
3725 =cut
3726 sub make_delim_table ($%)
3727 7 ▶{
Subroutine make_delim_table: called CC=10 SCAR=23.0
Pod documented
3728 7 my $self = shift;
3729 7 my %args = (
3730 rows_ref => undef,
3731 para_len => 0,
3732 @_
3733 );
3734 7 my $rows_ref = $args{rows_ref};
3735 7 my $para_len = $args{para_len};
3736  
3737 # a DELIM table can start with an optional table-caption,
3738 # then it has at least two rows which start and end and are
3739 # punctuated by a non-alphanumeric delimiter.
3740 # A DELIM table has no table-header.
3741 7 my @rows = @{$rows_ref};
3742 7 my $caption = '';
3743 7 ▶ if ($rows[0] !~ /\|/ && $rows[0] =~ /^\s*\w+/) # possible caption
Branch: 1 branch
BranchTrueFalseTotal
if (not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/) 1 6 7
Condition100%3/3
not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/
!ll&&!rl&&r
331
MC/DC100%2/2
not $rows[0] =~ /\|/ and $rows[0] =~ /^\s*\w+/
not $rows[0] =~ /\|/ $rows[0] =~ /^\s*\w+/
Truth table100%3/3
not(A) and B
A= not $rows[0] =~ /\|/B= $rows[0] =~ /^\s*\w+/
ABresult
0X0
100
111
3744 {
3745 1 $caption = shift @rows;
3746 }
3747 # figure out the delimiter
3748 7 my $delim = '';
3749 7 ▶ if ($rows[0] =~ /^\s*([^[:alnum:]])/)
Branch: 1 branch
BranchTrueFalseTotal
if ($rows[0] =~ /^\s*([^[:alnum:]])/) { } 7 0 7
3750 {
3751 7 $delim = $1;
3752 }
3753 else
3754 {
3755 0 return 0;
3756 }
3757  
3758 # now start making the table
3759 7 my @tab_lines = ();
3760 7 my $tag;
3761 7 ▶ if ($self->{xhtml})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'xhtml'}) { } 5 2 7
3762 {
3763 5 $tag = $self->get_tag('table', inside_tag => ' border="1" summary=""');
3764 }
3765 else
3766 {
3767 2 $tag = $self->get_tag('table', inside_tag => ' border="1"');
3768 }
3769 7 push @tab_lines, "$tag\n";
3770 7 ▶ if ($caption)
Branch: 1 branch
BranchTrueFalseTotal
if ($caption) 1 6 7
3771 {
3772 1 $caption =~ s/^\s+//;
3773 1 $caption =~ s/\s+$//;
3774 1 $tag = $self->get_tag('caption');
3775 1 $caption = $tag . $caption;
3776 1 $tag = $self->close_tag('caption');
3777 1 $caption .= $tag;
3778 1 push @tab_lines, "$caption\n";
3779 }
3780  
3781 # each row
3782 7 foreach my $row (@rows)
3783 {
3784 # cut off the start and end delimiter
3785 30 $row =~ s/^\s*[${delim}]//;
3786 30 $row =~ s/[${delim}]$//;
3787 30 my $this_row = '';
3788 30 $tag = $self->get_tag('tr');
3789 30 $this_row .= $tag;
3790 30 my @cols = split(/[${delim}]/, $row);
3791 30 foreach my $cell (@cols)
3792 {
3793 95 $cell =~ s/^\s+//;
3794 95 $cell =~ s/\s+$//;
3795 95 ▶ if ($self->{escape_HTML_chars})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"escape_HTML_chars"}) 95 0 95
3796 {
3797 95 $cell = escape($cell);
3798 }
3799 95 ▶ if (!$cell)
Branch: 1 branch
BranchTrueFalseTotal
unless ($cell) 1 94 95
3800 {
3801 1 $cell = '&nbsp;';
3802 }
3803 95 $tag = $self->get_tag('td');
3804 95 $this_row .= $tag;
3805 95 $this_row .= $cell;
3806 95 $tag = $self->close_tag('td');
3807 95 $this_row .= $tag;
3808 }
3809 30 $tag = $self->close_tag('tr');
3810 30 $this_row .= $tag;
3811 30 push @tab_lines, "${this_row}\n";
3812 }
3813  
3814 # end the table
3815 7 $tag = $self->get_tag('table', tag_type => TAG_END);
3816 7 push @tab_lines, "$tag\n";
3817  
3818 # replace the rows
3819 7 @{$rows_ref} = @tab_lines;
3820 } # make_delim_table
3821  
3822 =head2 is_preformatted
3823  
3824 if ($self->is_preformatted($line))
3825 {
3826 ...
3827 }
3828  
3829 Returns true if the passed string is considered to be preformatted.
3830  
3831 =cut
3832 sub is_preformatted ($$)
3833 921 ▶{
Subroutine is_preformatted: called CC=2 SCAR=7.0
Pod documented
3834 921 my $self = shift;
3835 921 my $line = shift;
3836  
3837 921 my $pre_white_min = $self->{preformat_whitespace_min};
3838 921 ▶ my $result = (
Condition66%2/3
$line =~ /\s{$pre_white_min,}\S+/o || $line =~ /\.{$pre_white_min,}\S+/o
l!l&&r!l&&!r
1370784
MC/DC50%1/2
$line =~ /\s{$pre_white_min,}\S+/o || $line =~ /\.{$pre_white_min,}\S+/o
$line =~ /\s{$pre_white_min,}\S+/o $line =~ /\.{$pre_white_min,}\S+/o
Truth table66%2/3
A || B
A= $line =~ /\s{$pre_white_min,}\S+/oB= $line =~ /\.{$pre_white_min,}\S+/o
ABresult
1X1
011
000
3839 ($line =~ /\s{$pre_white_min,}\S+/o) # whitespaces
3840 || ($line =~ /\.{$pre_white_min,}\S+/o)
3841 ); # dots
3842 921 return $result;
3843 }
3844  
3845 =head2 split_end_explicit_preformat
3846  
3847 $front = $self->split_end_explicit_preformat(para_ref=>$para_ref);
3848  
3849 Modifies the given string, and returns the front preformatted part.
3850  
3851 =cut
3852 sub split_end_explicit_preformat ($%)
3853 0 ▶{
Subroutine split_end_explicit_preformat: not called CC=5 SCAR=34.0
Pod documented
3854 0 my $self = shift;
3855 0 my %args = (
3856 para_ref => undef,
3857 @_
3858 );
3859 0 my $para_ref = $args{para_ref};
3860  
3861 0 my $tag = '';
3862 0 my $pre_str = '';
3863 0 my $post_str = '';
3864 0 ▶ if ($self->{__mode} & $PRE_EXPLICIT)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT) 0 0 0
3865 {
3866 0 my $pe_mark = $self->{preformat_end_marker};
3867 0 ▶ if (${para_ref} =~ /$pe_mark/io)
Branch: 1 branch
BranchTrueFalseTotal
if ($para_ref =~ /$pe_mark/io) { } 0 0 0
3868 {
3869 0 ($pre_str, $post_str) = split(/$pe_mark/, ${$para_ref}, 2);
3870 0 ▶ if ($self->{escape_HTML_chars})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"escape_HTML_chars"}) 0 0 0
3871 {
3872 0 $pre_str = escape($pre_str);
3873 }
3874 0 $tag = $self->close_tag('pre');
3875 0 $pre_str .= "${tag}\n";
3876 0 $self->{__mode} ^= (($PRE | $PRE_EXPLICIT) & $self->{__mode});
3877 }
3878 else # no end -- the whole thing is preformatted
3879 {
3880 0 $pre_str = ${$para_ref};
3881 0 ▶ if ($self->{escape_HTML_chars})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"escape_HTML_chars"}) 0 0 0
3882 {
3883 0 $pre_str = escape($pre_str);
3884 }
3885 0 ${$para_ref} = '';
3886 }
3887 }
3888 0 return $pre_str;
3889 } # split_end_explicit_preformat
3890  
3891 =head2 endpreformat
3892  
3893 $self->endpreformat(para_lines_ref=>$para_lines_ref,
3894 para_action_ref=>$para_action_ref,
3895 ind=>0,
3896 prev_ref=>$prev_ref);
3897  
3898 End a preformatted section.
3899  
3900 =cut
3901 sub endpreformat ($%)
3902 85 ▶{
Subroutine endpreformat: called CC=10 SCAR=25.2
Pod documented
3903 85 my $self = shift;
3904 85 my %args = (
3905 para_lines_ref => undef,
3906 para_action_ref => undef,
3907 ind => 0,
3908 prev_ref => undef,
3909 @_
3910 );
3911 85 my $para_lines_ref = $args{para_lines_ref};
3912 85 my $para_action_ref = $args{para_action_ref};
3913 85 my $ind = $args{ind};
3914 85 my $prev_ref = $args{prev_ref};
3915  
3916 85 my $tag = '';
3917 85 ▶ if ($self->{__mode} & $PRE_EXPLICIT)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__mode"} & $HTML::TextToHTML::PRE_EXPLICIT) 5 80 85
3918 {
3919 5 my $pe_mark = $self->{preformat_end_marker};
3920 5 ▶ if ($para_lines_ref->[$ind] =~ /$pe_mark/io)
Branch: 1 branch
BranchTrueFalseTotal
if ($para_lines_ref->[$ind] =~ /$pe_mark/io) 1 4 5
3921 {
3922 1 ▶ if ($ind == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($ind == 0) { } 0 1 1
3923 {
3924 0 $tag = $self->close_tag('pre');
3925 0 $para_lines_ref->[$ind] = "${tag}\n";
3926 }
3927 else
3928 {
3929 1 $tag = $self->close_tag('pre');
3930 1 $para_lines_ref->[$ind - 1] .= "${tag}\n";
3931 1 $para_lines_ref->[$ind] = "";
3932 }
3933 1 $self->{__mode} ^= (($PRE | $PRE_EXPLICIT) & $self->{__mode});
3934 1 $para_action_ref->[$ind] |= $END;
3935 }
3936 5 return;
3937 }
3938  
3939 80 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->is_preformatted($para_lines_ref->[$ind]) and $self->{"endpreformat_trigger_lines"} == 1 || $ind + 1 < @{$para_lines_ref;} && !$self->is_preformatted($$para_lines_ref[$ind + 1]) || $ind + 1 >= @{$para_lines_ref;}) 4 76 80
Condition41%5/12
not $self->is_preformatted($para_lines_ref->[$ind]) and $self->{"endpreformat_trigger_lines"} == 1 || $ind + 1 < @{$para_lines_ref;} && !$self->is_preformatted($$para_lines_ref[$ind + 1]) || $ind + 1 >= @{$para_lines_ref;}
!ll&&!rl&&r
7604
$self->{"endpreformat_trigger_lines"} == 1 or $ind + 1 < @{$para_lines_ref;} and not $self->is_preformatted($$para_lines_ref[$ind + 1]) or $ind + 1 >= @{$para_lines_ref;}
l!l&&r!l&&!r
400
$self->{"endpreformat_trigger_lines"} == 1 or $ind + 1 < @{$para_lines_ref;} and not $self->is_preformatted($$para_lines_ref[$ind + 1])
l!l&&r!l&&!r
040
$ind + 1 < @{$para_lines_ref;} and not $self->is_preformatted($$para_lines_ref[$ind + 1])
!ll&&!rl&&r
004
MC/DC20%1/5
not $self->is_preformatted($para_lines_ref->[$ind]) and $self->{"endpreformat_trigger_lines"} == 1 || $ind + 1 < @{$para_lines_ref;} && !$self->is_preformatted($$para_lines_ref[$ind + 1]) || $ind + 1 >= @{$para_lines_ref;}
not $self->is_preformatted($para_lines_ref->[$ind]) $self->{"endpreformat_trigger_lines"} == 1 $ind + 1 < @{$para_lines_ref;} not $self->is_preformatted($$para_lines_ref[$ind + 1]) $ind + 1 >= @{$para_lines_ref;}
Truth table28%2/7
not(A) and B or C and not(D) or E
A= not $self->is_preformatted($para_lines_ref->[$ind])B= $self->{"endpreformat_trigger_lines"} == 1C= $ind + 1 < @{$para_lines_ref;}D= not $self->is_preformatted($$para_lines_ref[$ind + 1])E= $ind + 1 >= @{$para_lines_ref;}
ABCDEresult
0XXXX0
100X00
101000
11XXX1
1011X1
100X11
101011
3940 !$self->is_preformatted($para_lines_ref->[$ind])
3941 && (
3942 $self->{endpreformat_trigger_lines} == 1
3943 4 || ($ind + 1 < @{$para_lines_ref}
3944 && !$self->is_preformatted($para_lines_ref->[$ind + 1]))
3945 0 || $ind + 1 >= @{$para_lines_ref} # last line of para
3946 )
3947 )
3948 {
3949 4 ▶ if ($ind == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($ind == 0) { } 0 4 4
3950 {
3951 0 $tag = $self->close_tag('pre');
3952 0 ${$prev_ref} = "${tag}\n";
3953 }
3954 else
3955 {
3956 4 $tag = $self->close_tag('pre');
3957 4 $para_lines_ref->[$ind - 1] .= "${tag}\n";
3958 }
3959 4 $self->{__mode} ^= ($PRE & $self->{__mode});
3960 4 $para_action_ref->[$ind] |= $END;
3961 }
3962 } # endpreformat
3963  
3964 =head2 preformat
3965  
3966 $self->preformat(mode_ref=>$mode_ref,
3967 line_ref=>$line_ref,
3968 line_action_ref=>$line_action_ref,
3969 prev_ref=>$prev_ref,
3970 next_ref=>$next_ref,
3971 prev_action_ref);
3972  
3973 Detect and process a preformatted section.
3974  
3975 =cut
3976 sub preformat ($%)
3977 823 ▶{
Subroutine preformat: called CC=12 SCAR=25.0
Pod documented
3978 823 my $self = shift;
3979 823 my %args = (
3980 mode_ref => undef,
3981 line_ref => undef,
3982 line_action_ref => undef,
3983 prev_ref => undef,
3984 next_ref => undef,
3985 prev_action_ref => undef,
3986 @_
3987 );
3988 823 my $mode_ref = $args{mode_ref};
3989 823 my $line_ref = $args{line_ref};
3990 823 my $line_action_ref = $args{line_action_ref};
3991 823 my $prev_ref = $args{prev_ref};
3992 823 my $next_ref = $args{next_ref};
3993 823 my $prev_action_ref = $args{prev_action_ref};
3994  
3995 823 my $tag = '';
3996 823 ▶ if ($self->{use_preformat_marker})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"use_preformat_marker"}) 6 817 823
3997 {
3998 6 my $pstart = $self->{preformat_start_marker};
3999 6 ▶ if (${$line_ref} =~ /$pstart/io)
Branch: 1 branch
BranchTrueFalseTotal
if (${$line_ref;} =~ /$pstart/io) 1 5 6
4000 {
4001 1 ▶ if (${$prev_ref} =~ s/<p>$//)
Branch: 1 branch
BranchTrueFalseTotal
if (${$prev_ref;} =~ s/<p>$//) 0 1 1
4002 {
4003 0 pop @{$self->{__tags}};
4004 }
4005 $tag =
4006 1 $self->get_tag('pre', inside_tag => " class='quote_explicit'");
4007 1 ${$line_ref} = "${tag}\n";
4008 1 ${$mode_ref} |= $PRE | $PRE_EXPLICIT;
4009 1 ${$line_action_ref} |= $PRE;
4010 1 return;
4011 }
4012 }
4013  
4014 822 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not ${$line_action_ref;} & $HTML::TextToHTML::MAILQUOTE || ${$prev_action_ref;} & $HTML::TextToHTML::MAILQUOTE and $self->{"preformat_trigger_lines"} == 0 || $self->is_preformatted(${$line_ref;}) && ($self->{"preformat_trigger_lines"} == 1 || defined $next_ref && $self->is_preformatted(${$next_ref;}))) 20 802 822
Condition100%6/6
not ${$line_action_ref;} & $HTML::TextToHTML::MAILQUOTE || ${$prev_action_ref;} & $HTML::TextToHTML::MAILQUOTE and $self->{"preformat_trigger_lines"} == 0 || $self->is_preformatted(${$line_ref;}) && ($self->{"preformat_trigger_lines"} == 1 || defined $next_ref && $self->is_preformatted(${$next_ref;}))
!ll&&!rl&&r
3476820
${$line_action_ref;} & $HTML::TextToHTML::MAILQUOTE || ${$prev_action_ref;} & $HTML::TextToHTML::MAILQUOTE
l!l&&r!l&&!r
2410788
MC/DC0%0/3
not ${$line_action_ref;} & $HTML::TextToHTML::MAILQUOTE || ${$prev_action_ref;} & $HTML::TextToHTML::MAILQUOTE and $self->{"preformat_trigger_lines"} == 0 || $self->is_preformatted(${$line_ref;}) && ($self->{"preformat_trigger_lines"} == 1 || defined $next_ref && $self->is_preformatted(${$next_ref;}))
${$line_action_ref;} & $HTML::TextToHTML::MAILQUOTE ${$prev_action_ref;} & $HTML::TextToHTML::MAILQUOTE $self->{"preformat_trigger_lines"} == 0 || $self->is_preformatted(${$line_ref;}) && ($self->{"preformat_trigger_lines"} == 1 || defined $next_ref && $self->is_preformatted(${$next_ref;}))
Truth table75%3/4
not(A || B) and C
A= ${$line_action_ref;} & $HTML::TextToHTML::MAILQUOTEB= ${$prev_action_ref;} & $HTML::TextToHTML::MAILQUOTEC= $self->{"preformat_trigger_lines"} == 0 || $self->is_preformatted(${$line_ref;}) && ($self->{"preformat_trigger_lines"} == 1 || defined $next_ref && $self->is_preformatted(${$next_ref;}))
ABCresult
1XX0
01X0
0000
0011
4015 822 !(${$line_action_ref} & $MAILQUOTE)
4016 798 ▶ && !(${$prev_action_ref} & $MAILQUOTE)
Condition83%5/6
$self->{"preformat_trigger_lines"} == 0 or $self->is_preformatted(${$line_ref;}) and $self->{"preformat_trigger_lines"} == 1 || defined $next_ref && $self->is_preformatted(${$next_ref;})
l!l&&r!l&&!r
020768
$self->is_preformatted(${$line_ref;}) and $self->{"preformat_trigger_lines"} == 1 || defined $next_ref && $self->is_preformatted(${$next_ref;})
!ll&&!rl&&r
7531520
MC/DC0%0/3
$self->{"preformat_trigger_lines"} == 0 or $self->is_preformatted(${$line_ref;}) and $self->{"preformat_trigger_lines"} == 1 || defined $next_ref && $self->is_preformatted(${$next_ref;})
$self->{"preformat_trigger_lines"} == 0 $self->is_preformatted(${$line_ref;}) $self->{"preformat_trigger_lines"} == 1 || defined $next_ref && $self->is_preformatted(${$next_ref;})
Truth table0%0/4
A or B and C
A= $self->{"preformat_trigger_lines"} == 0B= $self->is_preformatted(${$line_ref;})C= $self->{"preformat_trigger_lines"} == 1 || defined $next_ref && $self->is_preformatted(${$next_ref;})
ABCresult
1XX1
0111
00X0
0100
4017 && (
4018 $self->{preformat_trigger_lines} == 0
4019 || (
4020 788 ▶ $self->is_preformatted(${$line_ref})
Condition83%5/6
$self->{"preformat_trigger_lines"} == 1 or defined $next_ref and $self->is_preformatted(${$next_ref;})
l!l&&r!l&&!r
02015
defined $next_ref and $self->is_preformatted(${$next_ref;})
!ll&&!rl&&r
51020
MC/DC0%0/3
$self->{"preformat_trigger_lines"} == 1 or defined $next_ref and $self->is_preformatted(${$next_ref;})
$self->{"preformat_trigger_lines"} == 1 defined $next_ref $self->is_preformatted(${$next_ref;})
Truth table0%0/4
A or B and C
A= $self->{"preformat_trigger_lines"} == 1B= defined $next_refC= $self->is_preformatted(${$next_ref;})
ABCresult
1XX1
0111
00X0
0100
4021 && (
4022 $self->{preformat_trigger_lines} == 1
4023 || (defined $next_ref
4024 30 && $self->is_preformatted(${$next_ref}))
4025 )
4026 )
4027 )
4028 )
4029 {
4030 20 ▶ if (${$prev_ref} =~ s/<p>$//)
Branch: 1 branch
BranchTrueFalseTotal
if (${$prev_ref;} =~ s/<p>$//) 0 20 20
4031 {
4032 0 pop @{$self->{__tags}};
4033 }
4034 20 $tag = $self->get_tag('pre');
4035 20 ${$line_ref} =~ s/^/${tag}\n/;
4036 20 ${$mode_ref} |= $PRE;
4037 20 ${$line_action_ref} |= $PRE;
4038 }
4039 } # preformat
4040  
4041 =head2 make_new_anchor
4042  
4043 $anchor = $self->make_new_anchor($heading_level);
4044  
4045 Make a new anchor.
4046  
4047 =cut
4048 sub make_new_anchor ($$)
4049 73 ▶{
Subroutine make_new_anchor: called CC=5 SCAR=16.1
Pod documented
4050 73 my $self = shift;
4051 73 my $heading_level = shift;
4052  
4053 73 my ($anchor, $i);
4054  
4055 73 ▶ return sprintf("%d", $self->{__non_header_anchor}++) if (!$heading_level);
Branch: 1 branch
BranchTrueFalseTotal
unless $heading_level 11 62 73
4056  
4057 62 $anchor = "section";
4058 62 $self->{__heading_count}->[$heading_level - 1]++;
4059  
4060 # Reset lower order counters
4061 62 ▶ for ($i = @{$self->{__heading_count}}; $i > $heading_level; $i--)
Branch: 1 branch
BranchTrueFalseTotal
if ($i > $heading_level) 14 62 76
4062 {
4063 14 $self->{__heading_count}->[$i - 1] = 0;
4064 }
4065  
4066 62 ▶ for ($i = 0; $i < $heading_level; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $heading_level) 151 62 213
4067 {
4068 $self->{__heading_count}->[$i] = 1
4069 151 ▶ if !$self->{__heading_count}->[$i]; # In case they skip any
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"__heading_count"}[$i] 2 149 151
4070 151 $anchor .= sprintf("_%d", $self->{__heading_count}->[$i]);
4071 }
4072 62 chomp($anchor);
4073 62 $anchor;
4074 } # make_new_anchor
4075  
4076 =head2 anchor_mail
4077  
4078 $self->anchor_mail($line_ref);
4079  
4080 Make an anchor for a mail section.
4081  
4082 =cut
4083 sub anchor_mail ($$)
4084 11 ▶{
Subroutine anchor_mail: called CC=3 SCAR=11.0
Pod documented
4085 11 my $self = shift;
4086 11 my $line_ref = shift;
4087  
4088 11 ▶ if ($self->{make_anchors})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"make_anchors"}) 11 0 11
4089 {
4090 11 my ($anchor) = $self->make_new_anchor(0);
4091 11 ▶ if ($self->{lower_case_tags})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'lower_case_tags'}) { } 10 1 11
4092 {
4093 10 ${$line_ref} =~ s/([^ ]*)/<a name="$anchor">$1<\/a>/;
4094 }
4095 else
4096 {
4097 1 ${$line_ref} =~ s/([^ ]*)/<A NAME="$anchor">$1<\/A>/;
4098 }
4099 }
4100 } # anchor_mail
4101  
4102 =head2 anchor_heading
4103  
4104 $self->anchor_heading($heading_level, $line_ref);
4105  
4106 Make an anchor for a heading.
4107  
4108 =cut
4109 sub anchor_heading ($$$)
4110 63 ▶{
Subroutine anchor_heading: called CC=5 SCAR=16.8
Pod documented
4111 63 my $self = shift;
4112 63 my $level = shift;
4113 63 my $line_ref = shift;
4114  
4115 63 ▶ if ($DictDebug & 8)
Branch: 1 branch
BranchTrueFalseTotal
if ($HTML::TextToHTML::DictDebug & 8) 0 63 63
4116 {
4117 0 print STDERR "anchor_heading: ", ${$line_ref}, "\n";
4118 }
4119 63 ▶ if ($self->{make_anchors})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"make_anchors"}) 62 1 63
4120 {
4121 62 my ($anchor) = $self->make_new_anchor($level);
4122 62 ▶ if ($self->{lower_case_tags})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'lower_case_tags'}) { } 47 15 62
4123 {
4124 47 ${$line_ref} =~ s/(<h.>)(.*)(<\/h.>)/$1<a name="$anchor">$2<\/a>$3/;
4125 }
4126 else
4127 {
4128 15 ${$line_ref} =~ s/(<H.>)(.*)(<\/H.>)/$1<A NAME="$anchor">$2<\/A>$3/;
4129 }
4130 }
4131 63 ▶ if ($DictDebug & 8)
Branch: 1 branch
BranchTrueFalseTotal
if ($HTML::TextToHTML::DictDebug & 8) 0 63 63
4132 {
4133 0 print STDERR "anchor_heading(after): ", ${$line_ref}, "\n";
4134 }
4135 } # anchor_heading
4136  
4137 =head2 heading_level
4138  
4139 $self->heading_level($style);
4140  
4141 Add a new heading style if this is a new heading style.
4142  
4143 =cut
4144 sub heading_level ($$)
4145 63 ▶{
Subroutine heading_level: called CC=2 SCAR=6.9
Pod documented
4146 63 my $self = shift;
4147  
4148 63 my ($style) = @_;
4149 $self->{__heading_styles}->{$style} = ++$self->{__num_heading_styles}
4150 63 ▶ if !$self->{__heading_styles}->{$style};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"__heading_styles"}{$style} 24 39 63
4151 63 $self->{__heading_styles}->{$style};
4152 } # heading_level
4153  
4154 =head2 is_ul_list_line
4155  
4156 if ($self->is_ul_list_line($line))
4157 {
4158 ...
4159 }
4160  
4161 Tests if this line starts a UL list item.
4162  
4163 =cut
4164 sub is_ul_list_line ($%)
4165 267 ▶{
Subroutine is_ul_list_line: called CC=3 SCAR=11.0
Pod documented
4166 267 my $self = shift;
4167 267 my %args = (
4168 line => undef,
4169 @_
4170 );
4171 267 my $line = $args{line};
4172  
4173 267 my ($prefix, $number, $rawprefix, $term) = $self->listprefix($line);
4174 267 ▶ if ($prefix && !$number)
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix and not $number) 32 235 267
Condition100%3/3
$prefix and not $number
!ll&&!rl&&r
227832
MC/DC100%2/2
$prefix and not $number
$prefix not $number
Truth table100%3/3
A and not(B)
A= $prefixB= not $number
ABresult
0X0
100
111
4175 {
4176 32 return 1;
4177 }
4178 235 return 0;
4179 }
4180  
4181 =head2 is_heading
4182  
4183 if ($self->is_heading(line_ref=>$line_ref, next_ref=>$next_ref))
4184 {
4185 ...
4186 }
4187  
4188 Tests if this line is a heading. Needs to take account of the
4189 next line, because a standard heading is defined by "underlining"
4190 the text of the heading.
4191  
4192 =cut
4193 sub is_heading ($%)
4194 269 ▶{
Subroutine is_heading: called CC=13 SCAR=26.3
Pod documented
4195 269 my $self = shift;
4196 269 my %args = (
4197 line_ref => undef,
4198 next_ref => undef,
4199 @_
4200 );
4201 269 my $line_ref = $args{line_ref};
4202 269 my $next_ref = $args{next_ref};
4203  
4204 269 ▶ if ( ${$line_ref} !~ /^\s*$/
Branch: 1 branch
BranchTrueFalseTotal
if (not ${$line_ref;} =~ /^\s*$/ || $self->is_ul_list_line("line", ${$line_ref;}) and defined $next_ref and ${$next_ref;} =~ /^\s*[-=*.~+]+\s*$/) 54 215 269
Condition88%8/9
not ${$line_ref;} =~ /^\s*$/ || $self->is_ul_list_line("line", ${$line_ref;}) and defined $next_ref and ${$next_ref;} =~ /^\s*[-=*.~+]+\s*$/
!ll&&!rl&&r
3418154
not ${$line_ref;} =~ /^\s*$/ || $self->is_ul_list_line("line", ${$line_ref;}) and defined $next_ref
!ll&&!rl&&r
340235
${$line_ref;} =~ /^\s*$/ || $self->is_ul_list_line('line', ${$line_ref;})
l!l&&r!l&&!r
232235
MC/DC75%3/4
not ${$line_ref;} =~ /^\s*$/ || $self->is_ul_list_line("line", ${$line_ref;}) and defined $next_ref and ${$next_ref;} =~ /^\s*[-=*.~+]+\s*$/
${$line_ref;} =~ /^\s*$/ $self->is_ul_list_line('line', ${$line_ref;}) defined $next_ref ${$next_ref;} =~ /^\s*[-=*.~+]+\s*$/
Truth table80%4/5
not(A || B) and C and D
A= ${$line_ref;} =~ /^\s*$/B= $self->is_ul_list_line('line', ${$line_ref;})C= defined $next_refD= ${$next_ref;} =~ /^\s*[-=*.~+]+\s*$/
ABCDresult
1XXX0
01XX0
000X0
00100
00111
4205 267 && !$self->is_ul_list_line(line => ${$line_ref})
4206 && defined $next_ref
4207 235 && ${$next_ref} =~ /^\s*[-=*.~+]+\s*$/)
4208 {
4209 54 my ($hoffset, $heading) = ${$line_ref} =~ /^(\s*)(.+)$/;
4210 54 ▶ $hoffset = "" unless defined($hoffset);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hoffset 0 54 54
4211 54 ▶ $heading = "" unless defined($heading);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $heading 0 54 54
4212 # Unescape chars so we get an accurate length
4213 54 $heading =~ s/&[^;]+;/X/g;
4214 54 my ($uoffset, $underline) = ${$next_ref} =~ /^(\s*)(\S+)\s*$/;
4215 54 ▶ $uoffset = "" unless defined($uoffset);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uoffset 0 54 54
4216 54 ▶ $underline = "" unless defined($underline);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $underline 0 54 54
4217 54 my ($lendiff, $offsetdiff);
4218 54 $lendiff = length($heading) - length($underline);
4219 54 ▶ $lendiff *= -1 if $lendiff < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $lendiff < 0 3 51 54
4220  
4221 54 $offsetdiff = length($hoffset) - length($uoffset);
4222 54 ▶ $offsetdiff *= -1 if $offsetdiff < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $offsetdiff < 0 0 54 54
4223 54 ▶ if ( ($lendiff <= $self->{underline_length_tolerance})
Branch: 1 branch
BranchTrueFalseTotal
if ($lendiff <= $self->{"underline_length_tolerance"} or $offsetdiff <= $self->{"underline_offset_tolerance"}) 54 0 54
Condition33%1/3
$lendiff <= $self->{"underline_length_tolerance"} or $offsetdiff <= $self->{"underline_offset_tolerance"}
l!l&&r!l&&!r
5400
MC/DC0%0/2
$lendiff <= $self->{"underline_length_tolerance"} or $offsetdiff <= $self->{"underline_offset_tolerance"}
$lendiff <= $self->{"underline_length_tolerance"} $offsetdiff <= $self->{"underline_offset_tolerance"}
Truth table33%1/3
A or B
A= $lendiff <= $self->{"underline_length_tolerance"}B= $offsetdiff <= $self->{"underline_offset_tolerance"}
ABresult
1X1
011
000
4224 || ($offsetdiff <= $self->{underline_offset_tolerance}))
4225 {
4226 54 return 1;
4227 }
4228 }
4229  
4230 215 return 0;
4231  
4232 } # is_heading
4233  
4234 =head2 heading
4235
4236 $self->heading(line_ref=>$line_ref,
4237 next_ref=>$next_ref);
4238  
4239 Make a heading.
4240 Assumes is_heading is true.
4241  
4242 =cut
4243 sub heading ($%)
4244 54 ▶{
Subroutine heading: called CC=7 SCAR=19.6
Pod documented
4245 54 my $self = shift;
4246 54 my %args = (
4247 line_ref => undef,
4248 next_ref => undef,
4249 @_
4250 );
4251 54 my $line_ref = $args{line_ref};
4252 54 my $next_ref = $args{next_ref};
4253  
4254 54 my ($hoffset, $heading) = ${$line_ref} =~ /^(\s*)(.+)$/;
4255 54 ▶ $hoffset = "" unless defined($hoffset);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hoffset 0 54 54
4256 54 ▶ $heading = "" unless defined($heading);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $heading 0 54 54
4257 54 $heading =~ s/&[^;]+;/X/g; # Unescape chars so we get an accurate length
4258 54 my ($uoffset, $underline) = ${$next_ref} =~ /^(\s*)(\S+)\s*$/;
4259 54 ▶ $uoffset = "" unless defined($uoffset);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uoffset 0 54 54
4260 54 ▶ $underline = "" unless defined($underline);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $underline 0 54 54
4261  
4262 54 $underline = substr($underline, 0, 1);
4263  
4264 # Call it a different style if the heading is in all caps.
4265 54 ▶ $underline .= "C" if $self->iscaps(${$line_ref});
Branch: 1 branch
BranchTrueFalseTotal
if $self->iscaps(${$line_ref;}) 13 41 54
4266 54 ${$next_ref} = " "; # Eat the underline
4267 54 $self->{__heading_level} = $self->heading_level($underline);
4268 54 ▶ if ($self->{escape_HTML_chars})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"escape_HTML_chars"}) 54 0 54
4269 {
4270 54 ${$line_ref} = escape(${$line_ref});
4271 }
4272 54 $self->tagline("H" . $self->{__heading_level}, $line_ref);
4273 54 $self->anchor_heading($self->{__heading_level}, $line_ref);
4274 } # heading
4275  
4276 =head2 is_custom_heading
4277  
4278 if ($self->is_custom_heading($line))
4279 {
4280 ...
4281 }
4282  
4283 Check if the given line matches a custom heading.
4284  
4285 =cut
4286 sub is_custom_heading ($%)
4287 155 ▶{
Subroutine is_custom_heading: called CC=3 SCAR=11.0
Pod documented
4288 155 my $self = shift;
4289 155 my %args = (
4290 line => undef,
4291 @_
4292 );
4293 155 my $line = $args{line};
4294  
4295 155 foreach my $reg (@{$self->{custom_heading_regexp}})
4296 {
4297 161 ▶ return 1 if ($line =~ /$reg/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /$reg/ 9 152 161
4298 }
4299 146 return 0;
4300 } # is_custom_heading
4301  
4302 =head2 custom_heading
4303  
4304 $self->custom_heading(line_ref=>$line_ref);
4305  
4306 Make a custom heading. Assumes is_custom_heading is true.
4307  
4308 =cut
4309 sub custom_heading ($%)
4310 9 ▶{
Subroutine custom_heading: called CC=5 SCAR=16.2
Pod documented
4311 9 my $self = shift;
4312 9 my %args = (
4313 line_ref => undef,
4314 @_
4315 );
4316 9 my $line_ref = $args{line_ref};
4317  
4318 9 my $level;
4319 9 my $i = 0;
4320 9 foreach my $reg (@{$self->{custom_heading_regexp}})
4321 {
4322 11 ▶ if (${$line_ref} =~ /$reg/)
Branch: 1 branch
BranchTrueFalseTotal
if (${$line_ref;} =~ /$reg/) 9 2 11
4323 {
4324 9 ▶ if ($self->{explicit_headings})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'explicit_headings'}) { } 0 9 9
4325 {
4326 0 $level = $i + 1;
4327 }
4328 else
4329 {
4330 9 $level = $self->heading_level("Cust" . $i);
4331 }
4332 9 ▶ if ($self->{escape_HTML_chars})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"escape_HTML_chars"}) 9 0 9
4333 {
4334 9 ${$line_ref} = escape(${$line_ref});
4335 }
4336 9 $self->tagline("H" . $level, $line_ref);
4337 9 $self->anchor_heading($level, $line_ref);
4338 9 last;
4339 }
4340 2 $i++;
4341 }
4342 } # custom_heading
4343  
4344 =head2 unhyphenate_para
4345  
4346 $self->unhyphenate_para($para_ref);
4347  
4348 Join up hyphenated words that are split across lines.
4349  
4350 =cut
4351 sub unhyphenate_para ($$)
4352 8 ▶{
Subroutine unhyphenate_para: called CC=1 SCAR=0.0
Pod documented
4353 8 my $self = shift;
4354 8 my $para_ref = shift;
4355  
4356 # Treating this whole paragraph as one string, look for
4357 # 1 - whitespace
4358 # 2 - a word (ending in a hyphen, followed by a newline)
4359 # 3 - whitespace (starting on the next line)
4360 # 4 - a word with its punctuation
4361 # Substitute this with
4362 # 1-whitespace 2-word 4-word newline 3-whitespace
4363 # We preserve the 3-whitespace because we don't want to mess up
4364 # our existing indentation.
4365 8 ${$para_ref} =~
4366 /(\s*)([^\W\d_]*)\-\n(\s*)([^\W\d_]+[\)\}\]\.,:;\'\"\>]*\s*)/s;
4367 8 ${$para_ref} =~
4368 s/(\s*)([^\W\d_]*)\-\n(\s*)([^\W\d_]+[\)\}\]\.,:;\'\"\>]*\s*)/$1$2$4\n$3/gs;
4369 } # unhyphenate_para
4370  
4371 =head2 tagline
4372  
4373 $self->tagline($tag, $line_ref);
4374  
4375 Put the given tag around the given line.
4376  
4377 =cut
4378 sub tagline ($$$)
4379 66 ▶{
Subroutine tagline: called CC=1 SCAR=0.0
Pod documented
4380 66 my $self = shift;
4381 66 my $tag = shift;
4382 66 my $line_ref = shift;
4383  
4384 66 chomp ${$line_ref}; # Drop newline
4385 66 my $tag1 = $self->get_tag($tag);
4386 66 my $tag2 = $self->close_tag($tag);
4387 66 ${$line_ref} =~ s/^\s*(.*)$/${tag1}$1${tag2}\n/;
4388 } # tagline
4389  
4390 =head2 iscaps
4391  
4392 if ($self->iscaps($line))
4393 {
4394 ...
4395 }
4396  
4397 Check if a line is all capitals.
4398  
4399 =cut
4400 sub iscaps
4401 1117 ▶{
Subroutine iscaps: called CC=1 SCAR=0.0
Pod documented
4402 1117 my $self = shift;
4403 1117 local ($_) = @_;
4404  
4405 1117 my $min_caps_len = $self->{min_caps_length};
4406  
4407 1117 /^[^[:lower:]<]*[[:upper:]]{$min_caps_len,}[^[:lower:]<]*$/;
4408 } # iscaps
4409  
4410 =head2 caps
4411  
4412 $self->caps(line_ref=>$line_ref,
4413 line_action_ref=>$line_action_ref);
4414  
4415 Detect and deal with an all-caps line.
4416  
4417 =cut
4418 sub caps
4419 1065 ▶{
Subroutine caps: called CC=3 SCAR=11.0
Pod documented
4420 1065 my $self = shift;
4421 1065 my %args = (
4422 line_ref => undef,
4423 line_action_ref => undef,
4424 @_
4425 );
4426 1065 my $line_ref = $args{line_ref};
4427 1065 my $line_action_ref = $args{line_action_ref};
4428  
4429 1065 ▶ if ( $self->{caps_tag}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"caps_tag"} and $self->iscaps(${$line_ref;})) 3 1062 1065
Condition100%3/3
$self->{"caps_tag"} and $self->iscaps(${$line_ref;})
!ll&&!rl&&r
210603
MC/DC100%2/2
$self->{"caps_tag"} and $self->iscaps(${$line_ref;})
$self->{"caps_tag"} $self->iscaps(${$line_ref;})
Truth table100%3/3
A and B
A= $self->{"caps_tag"}B= $self->iscaps(${$line_ref;})
ABresult
0X0
100
111
4430 1063 && $self->iscaps(${$line_ref}))
4431 {
4432 3 $self->tagline($self->{caps_tag}, $line_ref);
4433 3 ${$line_action_ref} |= $CAPS;
4434 }
4435 } # caps
4436  
4437 =head2 do_delim
4438  
4439 $self->do_delim(line_ref=>$line_ref,
4440 line_action_ref=>$line_action_ref,
4441 delim=>'*',
4442 tag=>'STRONG');
4443  
4444 Deal with a line which has words delimited by the given delimiter;
4445 this is used to deal with italics, bold and underline formatting.
4446  
4447 =cut
4448 sub do_delim
4449 1318 ▶{
Subroutine do_delim: called CC=13 SCAR=25.9
Pod documented
4450 1318 my $self = shift;
4451 1318 my %args = (
4452 line_ref => undef,
4453 line_action_ref => undef,
4454 delim => '*',
4455 tag => 'STRONG',
4456 @_
4457 );
4458 1318 my $line_ref = $args{line_ref};
4459 1318 my $line_action_ref = $args{line_action_ref};
4460 1318 my $delim = $args{delim};
4461 1318 my $tag = $args{tag};
4462  
4463 1318 ▶ if ($delim eq '#')
Branch: 4 branches
BranchTrueFalseTotal
if ($delim eq '#') { } 438 880 1318
elsif ($delim eq '^') { } 1 879 880
elsif ($delim eq '_') { } 440 439 879
elsif (length $delim eq 1) { } 438 1 439
4464 {
4465 438 ▶ if (${$line_ref} =~ m/\B#([[:alpha:]])#\B/s)
Branch: 1 branch
BranchTrueFalseTotal
if (${$line_ref;} =~ /\B#([[:alpha:]])#\B/s) 0 438 438
4466 {
4467 0 ${$line_ref} =~ s/\B#([[:alpha:]])#\B/<${tag}>$1<\/${tag}>/gs;
4468 }
4469 # special treatment of # for the #num case and the #link case
4470 438 ▶ if (${$line_ref} !~ m/<[aA]/)
Branch: 1 branch
BranchTrueFalseTotal
if (not ${$line_ref;} =~ /<[aA]/) { } 342 96 438
4471 {
4472 342 ${$line_ref} =~
4473 s/#([^\d#](?![^#]*(?:<li>|<LI>|<P>|<p>))[^#]*[^# \t\n])#/<${tag}>$1<\/${tag}>/gs;
4474 }
4475 else
4476 {
4477 96 my $line_with_links = '';
4478 96 my $linkme = '';
4479 96 my $unmatched = ${$line_ref};
4480 96 ▶ while ($unmatched =~
Branch: 1 branch
BranchTrueFalseTotal
if ($unmatched =~ /#([^\d#](?![^#]*(?:<li>|<LI>|<P>|<p>))[^#]*[^# \t\n])#/s) 2 96 98
4481 m/#([^\d#](?![^#]*(?:<li>|<LI>|<P>|<p>))[^#]*[^# \t\n])#/s)
4482 {
4483 2 $line_with_links .= $`;
4484 2 $linkme = $&;
4485 2 $unmatched = $';
4486 2 ▶ if (!$self->in_link_context($linkme, $line_with_links))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->in_link_context($linkme, $line_with_links)) 1 1 2
4487 {
4488 1 $linkme =~
4489 s/#([^\d#](?![^#]*(?:<li>|<LI>|<P>|<p>))[^#]*[^# \t\n])#/<${tag}>$1<\/${tag}>/gs;
4490 }
4491 2 $line_with_links .= $linkme;
4492 }
4493 96 ${$line_ref} = $line_with_links . $unmatched;
4494 }
4495 }
4496 elsif ($delim eq '^')
4497 {
4498 1 ${$line_ref} =~
4499 s/\^((?![^^]*(?:<li>|<LI>|<p>|<P>))(\w|["'<>])[^^]*)\^/<${tag}>$1<\/${tag}>/gs;
4500 1 ${$line_ref} =~ s/\B\^([[:alpha:]])\^\B/<${tag}>$1<\/${tag}>/gs;
4501 }
4502 elsif ($delim eq '_')
4503 {
4504 440 ▶ if (${$line_ref} =~ m/\B_([[:alpha:]])_\B/s)
Branch: 1 branch
BranchTrueFalseTotal
if (${$line_ref;} =~ /\B_([[:alpha:]])_\B/s) { } 0 440 440
4505 {
4506 0 ${$line_ref} =~ s/\B_([[:alpha:]])_\B/<${tag}>$1<\/${tag}>/gs;
4507 0 ${$line_ref} =~
4508 s#(?<![_[:alnum:]])_([^_]+?[[:alnum:]"'\.\?\&;:<>])_#<${tag}>$1</${tag}>#gs;
4509 }
4510 else
4511 {
4512 # make sure we don't wallop links that have underscores
4513 # need to make sure that _ delimiters are not mistaken for
4514 # a_variable_name
4515 440 my $line_with_links = '';
4516 440 my $linkme = '';
4517 440 my $unmatched = ${$line_ref};
4518 440 ▶ while ($unmatched =~
Branch: 1 branch
BranchTrueFalseTotal
if ($unmatched =~ /(?<![_[:alnum:]])_([^_]+?[[:alnum:]"'\.\?\&;:<>])_/s) 15 440 455
4519 m#(?<![_[:alnum:]])_([^_]+?[[:alnum:]"'\.\?\&;:<>])_#s)
4520 {
4521 15 $line_with_links .= $`;
4522 15 $linkme = $&;
4523 15 $unmatched = $';
4524 15 ▶ if (!$self->in_link_context($linkme, $line_with_links))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->in_link_context($linkme, $line_with_links)) 11 4 15
4525 {
4526 11 $linkme =~
4527 s#(?<![_[:alnum:]])_([^_]+?[[:alnum:]"'\.\?\&;:<>])_#<${tag}>$1</${tag}>#gs;
4528 }
4529 15 $line_with_links .= $linkme;
4530 }
4531 440 ${$line_ref} = $line_with_links . $unmatched;
4532 }
4533 }
4534 elsif (length($delim) eq 1) # one-character, general
4535 {
4536 438 ▶ if (${$line_ref} =~ m/\B[${delim}]([[:alpha:]])[${delim}]\B/s)
Branch: 1 branch
BranchTrueFalseTotal
if (${$line_ref;} =~ /\B[$delim]([[:alpha:]])[$delim]\B/s) 0 438 438
4537 {
4538 0 ${$line_ref} =~ s/\B[${delim}]([[:alpha:]])[${delim}]\B/<${tag}>$1<\/${tag}>/gs;
4539 }
4540 438 ${$line_ref} =~
4541 s#(?<![${delim}])[${delim}]([^${delim}]+?[[:alnum:][:punct:]\&<>])[${delim}]#<${tag}>$1</${tag}>#gs;
4542 }
4543 else
4544 {
4545 1 ${$line_ref} =~
4546 s/(?<!${delim})${delim}((\w|["'])(\w|[-\s[:punct:]])*[^\s])${delim}/<${tag}>$1<\/${tag}>/gs;
4547 1 ${$line_ref} =~ s/${delim}]([[:alpha:]])${delim}/<${tag}>$1<\/${tag}>/gs;
4548 }
4549 } # do_delim
4550  
4551 =head2 glob2regexp
4552  
4553 $regexp = glob2regexp($glob);
4554  
4555 Convert very simple globs to regexps
4556  
4557 =cut
4558 sub glob2regexp
4559 0 ▶{
Subroutine glob2regexp: not called CC=6 SCAR=37.4
Pod documented
4560 0 my ($glob) = @_;
4561  
4562 # Escape funky chars
4563 0 $glob =~ s/[^\w\[\]\*\?\|\\]/\\$&/g;
4564 0 my ($regexp, $i, $len, $escaped) = ("", 0, length($glob), 0);
4565  
4566 0 ▶ for (; $i < $len; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 0 0 0
4567 {
4568 0 my $char = substr($glob, $i, 1);
4569 0 ▶ if ($escaped)
Branch: 1 branch
BranchTrueFalseTotal
if ($escaped) 0 0 0
4570 {
4571 0 $escaped = 0;
4572 0 $regexp .= $char;
4573 0 next;
4574 }
4575 0 ▶ if ($char eq "\\")
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\\") 0 0 0
4576 {
4577 0 $escaped = 1;
4578 0 next;
4579 0 $regexp .= $char;
4580 }
4581 0 ▶ if ($char eq "?")
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "?") 0 0 0
4582 {
4583 0 $regexp .= ".";
4584 0 next;
4585 }
4586 0 ▶ if ($char eq "*")
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "*") 0 0 0
4587 {
4588 0 $regexp .= ".*";
4589 0 next;
4590 }
4591 0 $regexp .= $char; # Normal character
4592 }
4593 0 join('', "\\b", $regexp, "\\b");
4594 } # glob2regexp
4595  
4596 =head2 add_regexp_to_links_table
4597  
4598 $self->add_regexp_to_links_table(label=>$label,
4599 pattern=>$pattern,
4600 url=>$url,
4601 switches=>$switches);
4602  
4603 Add the given regexp "link definition" to the links table.
4604  
4605 =cut
4606 sub add_regexp_to_links_table ($%)
4607 1352 ▶{
Subroutine add_regexp_to_links_table: called CC=4 SCAR=14.8
Pod documented
4608 1352 my $self = shift;
4609 1352 my %args = (
4610 label => undef,
4611 pattern => undef,
4612 url => undef,
4613 switches => undef,
4614 @_
4615 );
4616 1352 my $label = $args{label};
4617 1352 my $pattern = $args{pattern};
4618 1352 my $URL = $args{url};
4619 1352 my $switches = $args{switches};
4620  
4621 # No sense adding a second one if it's already in there.
4622 # It would never get used.
4623 1352 ▶ if (!$self->{__links_table}->{$label})
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'__links_table'}{$label}) { } 1352 0 1352
4624 {
4625  
4626 # Keep track of the order they were added so we can
4627 # look for matches in the same order
4628 1352 push(@{$self->{__links_table_order}}, ($label));
4629  
4630 1352 $self->{__links_table_patterns}->{$label} = $pattern;
4631 1352 $self->{__links_table}->{$label} = $URL; # Put it in The Table
4632 1352 $self->{__links_switch_table}->{$label} = $switches;
4633 1352 my $ind = @{$self->{__links_table_order}} - 1;
4634 1352 ▶ print STDERR " (", $ind,
Branch: 1 branch
BranchTrueFalseTotal
if $HTML::TextToHTML::DictDebug & 1 0 1352 1352
4635 ")\tLABEL: $label \tPATTERN: $pattern\n\tVALUE: $URL\n\tSWITCHES: $switches\n\n"
4636 if ($DictDebug & 1);
4637 }
4638 else
4639 {
4640 0 ▶ if ($DictDebug & 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($HTML::TextToHTML::DictDebug & 1) 0 0 0
4641 {
4642 0 print STDERR " Skipping entry. Key already in table.\n";
4643 0 print STDERR "\tLABEL: $label \tPATTERN: $pattern\n\tVALUE: $URL\n\n";
4644 }
4645 }
4646 } # add_regexp_to_links_table
4647  
4648 =head2 add_literal_to_links_table
4649  
4650 $self->add_literal_to_links_table(label=>$label,
4651 pattern=>$pattern,
4652 url=>$url,
4653 switches=>$switches);
4654  
4655 Add the given literal "link definition" to the links table.
4656  
4657 =cut
4658 sub add_literal_to_links_table ($%)
4659 156 ▶{
Subroutine add_literal_to_links_table: called CC=1 SCAR=0.0
Pod documented
4660 156 my $self = shift;
4661 156 my %args = (
4662 label => undef,
4663 pattern => undef,
4664 url => undef,
4665 switches => undef,
4666 @_
4667 );
4668 156 my $label = $args{label};
4669 156 my $pattern = $args{pattern};
4670 156 my $URL = $args{url};
4671 156 my $switches = $args{switches};
4672  
4673 156 $pattern =~ s/(\W)/\\$1/g; # Escape non-alphanumeric chars
4674 156 $pattern = "\\b$pattern\\b"; # Make a regexp out of it
4675 156 $self->add_regexp_to_links_table(label=>$label, pattern=>$pattern, url=>$URL, switches=>$switches);
4676 } # add_literal_to_links_table
4677  
4678 =head2 add_glob_to_links_table
4679  
4680 $self->add_glob_to_links_table(label=>$label,
4681 pattern=>$pattern,
4682 url=>$url,
4683 switches=>$switches);
4684  
4685 Add the given glob "link definition" to the links table.
4686  
4687 =cut
4688 sub add_glob_to_links_table ($%)
4689 0 ▶{
Subroutine add_glob_to_links_table: not called CC=1 SCAR=6.9
Pod documented
4690 0 my $self = shift;
4691 0 my %args = (
4692 label => undef,
4693 pattern => undef,
4694 url => undef,
4695 switches => undef,
4696 @_
4697 );
4698 0 my $label = $args{label};
4699 0 my $pattern = $args{pattern};
4700 0 my $URL = $args{url};
4701 0 my $switches = $args{switches};
4702  
4703 0 $self->add_regexp_to_links_table(pattern=>glob2regexp($pattern),
4704 label=>$label,
4705 url=>$URL, switches=>$switches);
4706 } # add_glob_to_links_table
4707  
4708 =head2 parse_dict
4709
4710 $self->parse_dict($dictfile, $dict);
4711  
4712 Parse the dictionary file.
4713 (see also load_dictionary_links, for things that were stripped)
4714  
4715 =cut
4716 sub parse_dict ($$$)
4717 26 ▶{
Subroutine parse_dict: called CC=14 SCAR=27.7
Pod documented
4718 26 my $self = shift;
4719  
4720 26 my ($dictfile, $dict) = @_;
4721  
4722 26 ▶ print STDERR "Parsing dictionary file $dictfile\n"
Branch: 1 branch
BranchTrueFalseTotal
if $HTML::TextToHTML::DictDebug & 1 0 26 26
4723 if ($DictDebug & 1);
4724  
4725 26 ▶ if ($dict =~ /->\s*->/)
Branch: 1 branch
BranchTrueFalseTotal
if ($dict =~ /->\s*->/) 0 26 26
4726 {
4727 0 my $message = "Two consecutive '->'s found in $dictfile\n";
4728 0 my $near;
4729  
4730 # Print out any useful context so they can find it.
4731 0 ($near) = $dict =~ /([\S ]*\s*->\s*->\s*\S*)/;
4732 0 ▶ $message .= "\n$near\n" if $near =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $near =~ /\S/ 0 0 0
4733 0 die $message;
4734 }
4735  
4736 26 my ($key, $URL, $switches, $options);
4737 26 ▶ while ($dict =~ /\s*(.+)\s+\-+([iehos]+\-+)?\>\s*(.*\S+)\s*\n/ig)
Branch: 1 branch
BranchTrueFalseTotal
if ($dict =~ /\s*(.+)\s+\-+([iehos]+\-+)?\>\s*(.*\S+)\s*\n/gi) 1352 26 1378
4738 {
4739 1352 $key = $1;
4740 1352 $options = $2;
4741 1352 ▶ $options = "" unless defined($options);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options 390 962 1352
4742 1352 $URL = $3;
4743 1352 $switches = 0;
4744 # Case insensitivity
4745 1352 ▶ $switches += $LINK_NOCASE if $options =~ /i/i;
Branch: 1 branch
BranchTrueFalseTotal
if $options =~ /i/i 26 1326 1352
4746 # Evaluate as Perl code
4747 1352 ▶ $switches += $LINK_EVAL if $options =~ /e/i;
Branch: 1 branch
BranchTrueFalseTotal
if $options =~ /e/i 0 1352 1352
4748 # provides HTML, not just URL
4749 1352 ▶ $switches += $LINK_HTML if $options =~ /h/i;
Branch: 1 branch
BranchTrueFalseTotal
if $options =~ /h/i 780 572 1352
4750 # Only do this link once
4751 1352 ▶ $switches += $LINK_ONCE if $options =~ /o/i;
Branch: 1 branch
BranchTrueFalseTotal
if $options =~ /o/i 156 1196 1352
4752 # Only do this link once per section
4753 1352 ▶ $switches += $LINK_SECT_ONCE if $options =~ /s/i;
Branch: 1 branch
BranchTrueFalseTotal
if $options =~ /s/i 0 1352 1352
4754  
4755 1352 $key =~ s/\s*$//; # Chop trailing whitespace
4756  
4757 1352 ▶ if ($key =~ m|^/|) # Regexp
Branch: 3 branches
BranchTrueFalseTotal
if ($key =~ m[^/]) { } 104 1248 1352
elsif ($key =~ /^\|/) { } 1092 156 1248
elsif ($key =~ /\"/) { } 156 0 156
4758 {
4759 104 $key = substr($key, 1);
4760 104 $key =~ s|/$||; # Allow them to forget the closing /
4761 104 $self->add_regexp_to_links_table(pattern=>$key, label=>$key, url=>$URL, switches=>$switches);
4762 }
4763 elsif ($key =~ /^\|/) # alternate regexp format
4764 {
4765 1092 $key = substr($key, 1);
4766 1092 $key =~ s/\|$//; # Allow them to forget the closing |
4767 1092 $key =~ s|/|\\/|g; # Escape all slashes
4768 1092 $self->add_regexp_to_links_table(pattern=>$key, label=>$key, url=>$URL, switches=>$switches);
4769 }
4770 elsif ($key =~ /\"/)
4771 {
4772 156 $key = substr($key, 1);
4773 156 $key =~ s/\"$//; # Allow them to forget the closing "
4774 156 $self->add_literal_to_links_table(pattern=>$key, label=>$key, url=>$URL, switches=>$switches);
4775 }
4776 else
4777 {
4778 0 $self->add_glob_to_links_table(pattern=>$key, label=>$key, url=>$URL, switches=>$switches);
4779 }
4780 }
4781  
4782 } # parse_dict
4783  
4784 =head2 setup_dict_checking
4785  
4786 $self->setup_dict_checking();
4787  
4788 Set up the dictionary checking.
4789  
4790 =cut
4791 sub setup_dict_checking ($)
4792 26 ▶{
Subroutine setup_dict_checking: called CC=9 SCAR=22.0
Pod documented
4793 26 my $self = shift;
4794  
4795 # now create the replace funcs and precomile the regexes
4796 26 my ($URL, $switches, $pattern, $options, $tag1, $tag2);
4797 26 my ($href, $r_sw);
4798 26 my @subs;
4799 26 my $i = 0;
4800 26 foreach my $label (@{$self->{__links_table_order}})
4801 {
4802 1352 $switches = $self->{__links_switch_table}->{$label};
4803 1352 $pattern = $self->{__links_table_patterns}->{$label};
4804  
4805 1352 $href = $self->{__links_table}->{$label};
4806  
4807 1352 ▶ if (!($switches & $LINK_HTML))
Branch: 1 branch
BranchTrueFalseTotal
if (not $switches & $HTML::TextToHTML::LINK_HTML) { } 572 780 1352
4808 {
4809 572 $href =~ s#/#\\/#g;
4810 $href = (
4811 $self->{lower_case_tags}
4812 572 ▶ ? join('', '<a href="', $href, '">$&<\\/a>')
Branch: 1 branch
BranchTrueFalseTotal
$self->{'lower_case_tags'} ? : 550 22 572
4813 : join('', '<A HREF="', $href, '">$&<\\/A>')
4814 );
4815 }
4816 else
4817 {
4818 # change the uppercase tags to lower case
4819 780 ▶ if ($self->{lower_case_tags})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"lower_case_tags"}) 750 30 780
4820 {
4821 750 $href =~ s#(</)([A-Z]*)(>)#${1}\L${2}${3}#g;
4822 750 $href =~ s/(<)([A-Z]*)(>)/${1}\L${2}${3}/g;
4823 # and the anchors
4824 750 $href =~ s/(<)(A\s*HREF)([^>]*>)/$1\L$2$3/g;
4825 }
4826 780 $href =~ s#/#\\/#g;
4827 }
4828  
4829 1352 $r_sw = "s"; # Options for replacing
4830 1352 ▶ $r_sw .= "i" if ($switches & $LINK_NOCASE);
Branch: 1 branch
BranchTrueFalseTotal
if $switches & $HTML::TextToHTML::LINK_NOCASE 26 1326 1352
4831 1352 ▶ $r_sw .= "e" if ($switches & $LINK_EVAL);
Branch: 1 branch
BranchTrueFalseTotal
if $switches & $HTML::TextToHTML::LINK_EVAL 0 1352 1352
4832  
4833 # Generate code for replacements.
4834 # Create an anonymous subroutine for each replacement,
4835 # and store its reference in an array.
4836 # We need to do an "eval" to create these because we need to
4837 # be able to treat the *contents* of the $href variable
4838 # as if it were perl code, because sometimes the $href
4839 # contains things which need to be evaluated, such as $& or $1,
4840 # not just those cases where we have a "e" switch.
4841 1352 my $code = <<EOT;
4842 \$self->{__repl_code}->[$i] =
4843 sub {
4844 my \$al = shift;
4845 \$al =~ s/$pattern/$href/$r_sw;
4846 return \$al;
4847 };
4848 EOT
4849 1352 ▶ print STDERR $code if ($DictDebug & 2);
Branch: 1 branch
BranchTrueFalseTotal
if $HTML::TextToHTML::DictDebug & 2 0 1352 1352
4850 1352 push @subs, $code;
4851  
4852 # compile searching pattern
4853 1352 ▶ if ($switches & $LINK_NOCASE) # i
Branch: 1 branch
BranchTrueFalseTotal
if ($switches & $HTML::TextToHTML::LINK_NOCASE) { } 26 1326 1352
4854 {
4855 26 $self->{__search_patterns}->[$i] = qr/$pattern/si;
4856 }
4857 else
4858 {
4859 1326 $self->{__search_patterns}->[$i] = qr/$pattern/s;
4860 }
4861 1352 $i++;
4862 }
4863 # now eval the replacements code string
4864 26 my $codes = join('', @subs);
4865 26 eval "$codes";
4866 } # setup_dict_checking
4867  
4868 =head2 in_link_context
4869  
4870 if ($self->in_link_context($match, $before))
4871 {
4872 ...
4873 }
4874  
4875 Check if we are inside a link (<a ...>); certain kinds of substitution are
4876 not allowed here.
4877  
4878 =cut
4879 sub in_link_context ($$$)
4880 124 ▶{
Subroutine in_link_context: called CC=8 SCAR=20.9
Pod documented
4881 124 my $self = shift;
4882 124 my ($match, $before) = @_;
4883 124 ▶ return 1 if $match =~ m@</?A>@i; # No links allowed inside match
Branch: 1 branch
BranchTrueFalseTotal
if $match =~ m[</?A>]i 12 112 124
4884  
4885 112 my ($final_open, $final_close);
4886 112 ▶ if ($self->{lower_case_tags})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'lower_case_tags'}) { } 92 20 112
4887 {
4888 92 $final_open = rindex($before, "<a ") - $[;
4889 92 $final_close = rindex($before, "</a>") - $[;
4890 }
4891 else
4892 {
4893 20 $final_open = rindex($before, "<A ") - $[;
4894 20 $final_close = rindex($before, "</A>") - $[;
4895 }
4896  
4897 112 ▶ return 1 if ($final_open >= 0) # Link opened
Branch: 1 branch
BranchTrueFalseTotal
if $final_open >= 0 and $final_close < 0 || $final_open > $final_close 29 83 112
Condition100%6/6
$final_open >= 0 and $final_close < 0 || $final_open > $final_close
!ll&&!rl&&r
374629
$final_close < 0 or $final_open > $final_close
l!l&&r!l&&!r
191046
MC/DC100%3/3
$final_open >= 0 and $final_close < 0 || $final_open > $final_close
$final_open >= 0 $final_close < 0 $final_open > $final_close
Truth table100%4/4
A and B or C
A= $final_open >= 0B= $final_close < 0C= $final_open > $final_close
ABCresult
0XX0
1000
11X1
1011
4898 && (
4899 ($final_close < 0) # and not closed or
4900 || ($final_open > $final_close)
4901 ); # one opened after last close
4902  
4903 # Now check to see if we're inside a tag, matching a tag name,
4904 # or attribute name or value
4905 83 $final_open = rindex($before, "<") - $[;
4906 83 $final_close = rindex($before, ">") - $[;
4907 83 ▶ ($final_open >= 0) # Tag opened
Branch: 1 branch
BranchTrueFalseTotal
$final_open >= 0 and $final_close < 0 || $final_open > $final_close 82 1 83
Condition50%3/6
$final_open >= 0 && ($final_close < 0 || $final_open > $final_close)
!ll&&!rl&&r
1820
$final_close < 0 or $final_open > $final_close
l!l&&r!l&&!r
0082
MC/DC0%0/3
$final_open >= 0 && ($final_close < 0 || $final_open > $final_close)
$final_open >= 0 $final_close < 0 $final_open > $final_close
Truth table50%2/4
A && B or C
A= $final_open >= 0B= $final_close < 0C= $final_open > $final_close
ABCresult
0XX0
1000
11X1
1011
4908 && (
4909 ($final_close < 0) # and not closed or
4910 || ($final_open > $final_close)
4911 ); # one opened after last close
4912 } # in_link_context
4913  
4914 =head2 apply_links
4915  
4916 $self->apply_links(para_ref=>$para_ref,
4917 para_action_ref=>$para_action_ref);
4918  
4919 Apply links and formatting to this paragraph.
4920  
4921 =cut
4922 sub apply_links ($%)
4923 440 ▶{
Subroutine apply_links: called CC=9 SCAR=22.1
Pod documented
4924 440 my $self = shift;
4925 440 my %args = (
4926 para_ref => undef,
4927 para_action_ref => undef,
4928 @_
4929 );
4930 440 my $para_ref = $args{para_ref};
4931 440 my $para_action_ref = $args{para_action_ref};
4932  
4933 440 ▶ if ($self->{make_links}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"make_links"} and @{$self->{"__links_table_order"};}) 440 0 440
Condition33%1/3
$self->{"make_links"} and @{$self->{"__links_table_order"};}
!ll&&!rl&&r
00440
MC/DC0%0/2
$self->{"make_links"} and @{$self->{"__links_table_order"};}
$self->{"make_links"} @{$self->{"__links_table_order"};}
Truth table33%1/3
A and B
A= $self->{"make_links"}B= @{$self->{"__links_table_order"};}
ABresult
0X0
100
111
4934 440 && @{$self->{__links_table_order}})
4935 {
4936 440 $self->check_dictionary_links(
4937 line_ref => $para_ref,
4938 line_action_ref => $para_action_ref
4939 );
4940 }
4941 440 ▶ if ($self->{bold_delimiter})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bold_delimiter"}) 439 1 440
4942 {
4943 439 ▶ my $tag = ($self->{lower_case_tags} ? 'strong' : 'STRONG');
Branch: 1 branch
BranchTrueFalseTotal
$self->{'lower_case_tags'} ? : 366 73 439
4944 $self->do_delim(
4945 line_ref => $para_ref,
4946 line_action_ref => $para_action_ref,
4947 delim => $self->{bold_delimiter},
4948 439 tag => $tag
4949 );
4950 }
4951 440 ▶ if ($self->{italic_delimiter})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"italic_delimiter"}) 439 1 440
4952 {
4953 439 ▶ my $tag = ($self->{lower_case_tags} ? 'em' : 'EM');
Branch: 1 branch
BranchTrueFalseTotal
$self->{'lower_case_tags'} ? : 366 73 439
4954 $self->do_delim(
4955 line_ref => $para_ref,
4956 line_action_ref => $para_action_ref,
4957 delim => $self->{italic_delimiter},
4958 439 tag => $tag
4959 );
4960 }
4961 440 ▶ if ($self->{underline_delimiter})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"underline_delimiter"}) 440 0 440
4962 {
4963 440 ▶ my $tag = ($self->{lower_case_tags} ? 'u' : 'U');
Branch: 1 branch
BranchTrueFalseTotal
$self->{'lower_case_tags'} ? : 367 73 440
4964 $self->do_delim(
4965 line_ref => $para_ref,
4966 line_action_ref => $para_action_ref,
4967 delim => $self->{underline_delimiter},
4968 440 tag => $tag
4969 );
4970 }
4971  
4972 } # apply_links
4973  
4974 =head2 check_dictionary_links
4975  
4976 $self->check_dictionary_links(line_ref=>$line_ref,
4977 line_action_ref=>$line_action_ref);
4978  
4979 Check (and alter if need be) the bits in this line matching
4980 the patterns in the link dictionary.
4981  
4982 =cut
4983 sub check_dictionary_links ($%)
4984 440 ▶{
Subroutine check_dictionary_links: called CC=15 SCAR=31.1
Pod documented
4985 440 my $self = shift;
4986 440 my %args = (
4987 line_ref => undef,
4988 line_action_ref => undef,
4989 @_
4990 );
4991 440 my $line_ref = $args{line_ref};
4992 440 my $line_action_ref = $args{line_action_ref};
4993  
4994 440 my ($switches, $pattern, $options, $repl_func);
4995 440 my ($linkme, $line_with_links);
4996  
4997 # for each pattern, check and alter the line
4998 440 my $i = 0;
4999 440 foreach my $label (@{$self->{__links_table_order}})
5000 {
5001 22880 $switches = $self->{__links_switch_table}->{$label};
5002 22880 $pattern = $self->{__links_table_patterns}->{$label};
5003  
5004 # check the pattern
5005 22880 ▶ if ($switches & $LINK_ONCE) # Do link only once
Branch: 2 branches
BranchTrueFalseTotal
if ($switches & $HTML::TextToHTML::LINK_ONCE) { } 2640 20240 22880
elsif ($switches & $HTML::TextToHTML::LINK_SECT_ONCE) { } 0 20240 20240
5006 {
5007 2640 $line_with_links = '';
5008 2640 ▶ if (!$self->{__done_with_link}->[$i]
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"__done_with_link"}[$i] and ${$line_ref;} =~ /$self->{"__search_patterns"}[$i]/) 11 2629 2640
Condition100%3/3
not $self->{"__done_with_link"}[$i] and ${$line_ref;} =~ /$self->{"__search_patterns"}[$i]/
!ll&&!rl&&r
670195911
MC/DC100%2/2
not $self->{"__done_with_link"}[$i] and ${$line_ref;} =~ /$self->{"__search_patterns"}[$i]/
not $self->{"__done_with_link"}[$i] ${$line_ref;} =~ /$self->{"__search_patterns"}[$i]/
Truth table100%3/3
not(A) and B
A= not $self->{"__done_with_link"}[$i]B= ${$line_ref;} =~ /$self->{"__search_patterns"}[$i]/
ABresult
0X0
100
111
5009 1970 && ${$line_ref} =~ $self->{__search_patterns}->[$i])
5010 {
5011 11 $self->{__done_with_link}->[$i] = 1;
5012 11 $line_with_links .= $`;
5013 11 $linkme = $&;
5014  
5015 11 ${$line_ref} = $';
5016 11 ▶ if (!$self->in_link_context($linkme, $line_with_links))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->in_link_context($linkme, $line_with_links)) 11 0 11
5017 {
5018 11 ▶ print STDERR "Link rule $i matches $linkme\n"
Branch: 1 branch
BranchTrueFalseTotal
if $HTML::TextToHTML::DictDebug & 4 0 11 11
5019 if ($DictDebug & 4);
5020  
5021 # call the special subroutine already created to do
5022 # this replacement
5023 11 $repl_func = $self->{__repl_code}->[$i];
5024 11 $linkme = &$repl_func($linkme);
5025 }
5026 11 $line_with_links .= $linkme;
5027 }
5028 2640 ${$line_ref} = $line_with_links . ${$line_ref};
5029 }
5030 elsif ($switches & $LINK_SECT_ONCE) # Do link only once per section
5031 {
5032 0 $line_with_links = '';
5033 0 ▶ if (!$self->{__done_with_sect_link}->[$i]
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"__done_with_sect_link"}[$i] and ${$line_ref;} =~ /$self->{"__search_patterns"}[$i]/) 0 0 0
Condition0%0/3
not $self->{"__done_with_sect_link"}[$i] and ${$line_ref;} =~ /$self->{"__search_patterns"}[$i]/
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->{"__done_with_sect_link"}[$i] and ${$line_ref;} =~ /$self->{"__search_patterns"}[$i]/
not $self->{"__done_with_sect_link"}[$i] ${$line_ref;} =~ /$self->{"__search_patterns"}[$i]/
Truth table0%0/3
not(A) and B
A= not $self->{"__done_with_sect_link"}[$i]B= ${$line_ref;} =~ /$self->{"__search_patterns"}[$i]/
ABresult
0X0
100
111
5034 0 && ${$line_ref} =~ $self->{__search_patterns}->[$i])
5035 {
5036 0 $self->{__done_with_sect_link}->[$i] = 1;
5037 0 $line_with_links .= $`;
5038 0 $linkme = $&;
5039  
5040 0 ${$line_ref} = $';
5041 0 ▶ if (!$self->in_link_context($linkme, $line_with_links))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->in_link_context($linkme, $line_with_links)) 0 0 0
5042 {
5043 0 ▶ print STDERR "Link rule $i matches $linkme\n"
Branch: 1 branch
BranchTrueFalseTotal
if $HTML::TextToHTML::DictDebug & 4 0 0 0
5044 if ($DictDebug & 4);
5045  
5046 # call the special subroutine already created to do
5047 # this replacement
5048 0 $repl_func = $self->{__repl_code}->[$i];
5049 0 $linkme = &$repl_func($linkme);
5050 }
5051 0 $line_with_links .= $linkme;
5052 }
5053 0 ${$line_ref} = $line_with_links . ${$line_ref};
5054 }
5055 else
5056 {
5057 20240 $line_with_links = '';
5058 20240 ▶ while (${$line_ref} =~ $self->{__search_patterns}->[$i])
Branch: 1 branch
BranchTrueFalseTotal
if (${$line_ref;} =~ /$self->{"__search_patterns"}[$i]/) 96 20240 20336
5059 {
5060 96 $line_with_links .= $`;
5061 96 $linkme = $&;
5062  
5063 96 ${$line_ref} = $';
5064 96 ▶ if (!$self->in_link_context($linkme, $line_with_links))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->in_link_context($linkme, $line_with_links)) 60 36 96
5065 {
5066 60 ▶ print STDERR "Link rule $i matches $linkme\n"
Branch: 1 branch
BranchTrueFalseTotal
if $HTML::TextToHTML::DictDebug & 4 0 60 60
5067 if ($DictDebug & 4);
5068  
5069 # call the special subroutine already created to do
5070 # this replacement
5071 60 $repl_func = $self->{__repl_code}->[$i];
5072 60 $linkme = &$repl_func($linkme);
5073 }
5074 96 $line_with_links .= $linkme;
5075 }
5076 20240 ${$line_ref} = $line_with_links . ${$line_ref};
5077 }
5078 22880 $i++;
5079 }
5080 440 ${$line_action_ref} |= $LINK;
5081 } # check_dictionary_links
5082  
5083 =head2 load_dictionary_links
5084  
5085 $self->load_dictionary_links();
5086  
5087 Load the dictionary links.
5088  
5089 =cut
5090 sub load_dictionary_links ($)
5091 26 ▶{
Subroutine load_dictionary_links: called CC=8 SCAR=32.0
Pod documented
5092 26 my $self = shift;
5093  
5094 26 @{$self->{__links_table_order}} = ();
5095 26 %{$self->{__links_table}} = ();
5096  
5097 26 my $dict;
5098 26 foreach $dict (@{$self->{links_dictionaries}})
5099 {
5100 0 ▶ next unless $dict;
Branch: 1 branch
BranchTrueFalseTotal
unless $dict 0 0 0
5101 0 ▶ open(DICT, "$dict") || die "Can't open Dictionary file $dict\n";
Branch: 1 branch
BranchTrueFalseTotal
open DICT, "$dict" or die "Can't open Dictionary file $dict\n" 0 0 0
5102  
5103 0 my @lines = ();
5104 0 ▶ while (<DICT>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline DICT)) 0 0 0
5105 {
5106 # skip lines that start with '#'
5107 0 ▶ next if /^\#/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\#/ 0 0 0
5108 # skip lines that end with unescaped ':'
5109 0 ▶ next if /^.*[^\\]:\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^.*[^\\]:\s*$/ 0 0 0
5110 0 push @lines, $_;
5111 }
5112 0 close(DICT);
5113 0 my $contents = join('', @lines);
5114 0 $self->parse_dict($dict, $contents);
5115 }
5116 # last of all, do the system dictionary, already read in from DATA
5117 26 ▶ if ($self->{__global_links_data})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__global_links_data"}) 26 0 26
5118 {
5119 26 $self->parse_dict("DATA", $self->{__global_links_data});
5120 }
5121  
5122 26 $self->setup_dict_checking();
5123 } # load_dictionary_links
5124  
5125 =head2 do_file_start
5126  
5127 $self->do_file_start($outhandle, $para);
5128  
5129 Extra stuff needed for the beginning:
5130 HTML headers, and prepending a file if desired.
5131  
5132 =cut
5133 sub do_file_start ($$$)
5134 34 ▶{
Subroutine do_file_start: called CC=18 SCAR=36.4
Pod documented
5135 34 my $self = shift;
5136 34 my $outhandle = shift;
5137 34 my $para = shift;
5138  
5139 34 ▶ if (!$self->{extract})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"extract"}) 13 21 34
5140 {
5141 13 my @para_lines = split(/\n/, $para);
5142 13 my $first_line = $para_lines[0];
5143  
5144 13 ▶ if ($self->{doctype})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"doctype"}) 13 0 13
5145 {
5146 13 ▶ if ($self->{xhtml})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'xhtml'}) { } 12 1 13
5147 {
5148 12 print $outhandle
5149 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"',
5150 "\n";
5151 12 print $outhandle
5152 '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
5153 "\n";
5154 12 print $outhandle $self->get_tag('html',
5155 inside_tag => ' xmlns="http://www.w3.org/1999/xhtml"'), "\n";
5156 }
5157 else
5158 {
5159 print $outhandle '<!DOCTYPE HTML PUBLIC "', $self->{doctype},
5160 1 "\">\n";
5161 1 print $outhandle $self->get_tag('html'), "\n";
5162 }
5163 }
5164 13 print $outhandle $self->get_tag('head'), "\n";
5165  
5166 # if --titlefirst is set and --title isn't, use the first line
5167 # as the title.
5168 13 ▶ if ($self->{titlefirst} && !$self->{title})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"titlefirst"} and not $self->{"title"}) 2 11 13
Condition66%2/3
$self->{"titlefirst"} and not $self->{"title"}
!ll&&!rl&&r
1102
MC/DC50%1/2
$self->{"titlefirst"} and not $self->{"title"}
$self->{"titlefirst"} not $self->{"title"}
Truth table66%2/3
A and not(B)
A= $self->{"titlefirst"}B= not $self->{"title"}
ABresult
0X0
100
111
5169 {
5170 2 my ($tit) = $first_line =~ /^ *(.*)/; # grab first line
5171 2 $tit =~ s/ *$//; # strip trailing whitespace
5172 2 ▶ $tit = escape($tit) if $self->{escape_HTML_chars};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"escape_HTML_chars"} 2 0 2
5173 2 $self->{'title'} = $tit;
5174 }
5175 13 ▶ if (!$self->{title})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"title"}) 11 2 13
5176 {
5177 11 $self->{'title'} = "";
5178 }
5179 print $outhandle $self->get_tag('title'), $self->{title},
5180 13 $self->close_tag('title'), "\n";
5181  
5182 13 ▶ if ($self->{append_head})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"append_head"}) 0 13 13
5183 {
5184 open(APPEND, $self->{append_head})
5185 0 ▶ || die "Failed to open ", $self->{append_head}, "\n";
Branch: 1 branch
BranchTrueFalseTotal
open APPEND, $self->{"append_head"} or die "Failed to open ", $self->{"append_head"}, "\n" 0 0 0
5186 0 ▶ while (<APPEND>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline APPEND)) 0 0 0
5187 {
5188 0 print $outhandle $_;
5189 }
5190 0 close(APPEND);
5191 }
5192  
5193 13 ▶ if ($self->{lower_case_tags})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'lower_case_tags'}) { } 12 1 13
5194 {
5195 12 print $outhandle $self->get_tag(
5196 'meta',
5197 tag_type => TAG_EMPTY,
5198 inside_tag => " name=\"generator\" content=\"$PROG v$HTML::TextToHTML::VERSION\""
5199 ),
5200 "\n";
5201 }
5202 else
5203 {
5204 1 print $outhandle $self->get_tag(
5205 'meta',
5206 tag_type => TAG_EMPTY,
5207 inside_tag => " NAME=\"generator\" CONTENT=\"$PROG v$HTML::TextToHTML::VERSION\""
5208 ),
5209 "\n";
5210 }
5211 13 ▶ if ($self->{style_url})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"style_url"}) 0 13 13
5212 {
5213 0 my $style_url = $self->{style_url};
5214 0 ▶ if ($self->{lower_case_tags})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'lower_case_tags'}) { } 0 0 0
5215 {
5216 0 print $outhandle $self->get_tag(
5217 'link',
5218 tag_type => TAG_EMPTY,
5219 inside_tag =>
5220 " rel=\"stylesheet\" type=\"text/css\" href=\"$style_url\""
5221 ),
5222 "\n";
5223 }
5224 else
5225 {
5226 0 print $outhandle $self->get_tag(
5227 'link',
5228 tag_type => TAG_EMPTY,
5229 inside_tag =>
5230 " REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"$style_url\""
5231 ),
5232 "\n";
5233 }
5234 }
5235 13 print $outhandle $self->close_tag('head'), "\n";
5236 13 ▶ if ($self->{body_deco})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'body_deco'}) { } 0 13 13
5237 {
5238 print $outhandle $self->get_tag('body',
5239 0 inside_tag => $self->{body_deco}), "\n";
5240 }
5241 else
5242 {
5243 13 print $outhandle $self->get_tag('body'), "\n";
5244 }
5245 }
5246  
5247 34 ▶ if ($self->{prepend_file})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"prepend_file"}) 0 34 34
5248 {
5249 0 ▶ if (-r $self->{prepend_file})
Branch: 1 branch
BranchTrueFalseTotal
if (-r $self->{'prepend_file'}) { } 0 0 0
5250 {
5251 0 open(PREPEND, $self->{prepend_file});
5252 0 ▶ while (<PREPEND>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline PREPEND)) 0 0 0
5253 {
5254 0 print $outhandle $_;
5255 }
5256 0 close(PREPEND);
5257 }
5258 else
5259 {
5260 print STDERR "Can't find or read file ", $self->{prepend_file},
5261 0 " to prepend.\n";
5262 }
5263 }
5264 } # do_file_start
5265  
5266 =head2 do_init_call
5267  
5268 $self->do_init_call();
5269  
5270 Certain things, like reading link dictionaries, need to be done only
5271 once.
5272  
5273 =cut
5274 sub do_init_call ($)
5275 478 ▶{
Subroutine do_init_call: called CC=8 SCAR=23.6
Pod documented
5276 478 my $self = shift;
5277  
5278 478 ▶ if (!$self->{__call_init_done})
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"__call_init_done"}) 26 452 478
5279 {
5280 0 push(@{$self->{links_dictionaries}}, ($self->{default_link_dict}))
5281 26 ▶ if ($self->{make_links} && (-f $self->{default_link_dict}));
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"make_links"} and -f $self->{"default_link_dict"} 0 26 26
Condition33%1/3
$self->{"make_links"} and -f $self->{"default_link_dict"}
!ll&&!rl&&r
0260
MC/DC0%0/2
$self->{"make_links"} and -f $self->{"default_link_dict"}
$self->{"make_links"} -f $self->{"default_link_dict"}
Truth table33%1/3
A and B
A= $self->{"make_links"}B= -f $self->{"default_link_dict"}
ABresult
0X0
100
111
5282 26 ▶ if ($self->{links_dictionaries})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"links_dictionaries"}) 26 0 26
5283 {
5284 # only put into the links dictionaries files which are readable
5285 26 my @dict_files = @{$self->{links_dictionaries}};
5286 26 $self->args(links_dictionaries => []);
5287  
5288 26 foreach my $ld (@dict_files)
5289 {
5290 0 ▶ if (-r $ld)
Branch: 1 branch
BranchTrueFalseTotal
if (-r $ld) { } 0 0 0
5291 {
5292 0 $self->{'make_links'} = 1;
5293 0 $self->args(['--links_dictionaries', $ld]);
5294 }
5295 else
5296 {
5297 0 print STDERR "Can't find or read link-file $ld\n";
5298 }
5299 }
5300 }
5301 26 ▶ if ($self->{make_links})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"make_links"}) 26 0 26
5302 {
5303 26 $self->load_dictionary_links();
5304 }
5305  
5306 # various initializations
5307 26 $self->{__non_header_anchor} = 0;
5308 26 $self->{__mode} = 0;
5309 26 $self->{__listnum} = 0;
5310 26 $self->{__list_nice_indent} = '';
5311 26 $self->{__list_indent} = [];
5312 26 $self->{__tags} = [];
5313  
5314 26 $self->{__call_init_done} = 1;
5315 }
5316 } # do_init_call
5317  
5318 =head1 FILE FORMATS
5319  
5320 There are two files which are used which can affect the outcome of the
5321 conversion. One is the link dictionary, which contains patterns (of how
5322 to recognise http links and other things) and how to convert them. The
5323 other is, naturally, the format of the input file itself.
5324  
5325 =head2 Link Dictionary
5326  
5327 A link dictionary file contains patterns to match, and what to convert
5328 them to. It is called a "link" dictionary because it was intended to be
5329 something which defined what a href link was, but it can be used for
5330 more than that. However, if you wish to define your own links, it is
5331 strongly advised to read up on regular expressions (regexes) because
5332 this relies heavily on them.
5333  
5334 The file consists of comments (which are lines starting with #)
5335 and blank lines, and link entries.
5336 Each entry consists of a regular expression, a -> separator (with
5337 optional flags), and a link "result".
5338  
5339 In the simplest case, with no flags, the regular expression
5340 defines the pattern to look for, and the result says what part
5341 of the regular expression is the actual link, and the link which
5342 is generated has the href as the link, and the whole matched pattern
5343 as the visible part of the link. The first character of the regular
5344 expression is taken to be the separator for the regex, so one
5345 could either use the traditional / separator, or something else
5346 such as | (which can be helpful with URLs which are full of / characters).
5347  
5348 So, for example, an ftp URL might be defined as:
5349  
5350 |ftp:[\w/\.:+\-]+| -> $&
5351  
5352 This takes the whole pattern as the href, and the resultant link
5353 has the same thing in the href as in the contents of the anchor.
5354  
5355 But sometimes the href isn't the whole pattern.
5356  
5357 /&lt;URL:\s*(\S+?)\s*&gt;/ --> $1
5358  
5359 With the above regex, a () grouping marks the first subexpression,
5360 which is represented as $1 (rather than $& the whole expression).
5361 This entry matches a URL which was marked explicity as a URL
5362 with the pattern <URL:foo> (note the &lt; is shown as the
5363 entity, not the actual character. This is because by the
5364 time the links dictionary is checked, all such things have
5365 already been converted to their HTML entity forms, unless, of course,
5366 the escape_HTML_chars option was turned off)
5367 This would give us a link in the form
5368 <A HREF="foo">&lt;URL:foo&gt;</A>
5369  
5370 B<The h flag>
5371  
5372 However, if we want more control over the way the link is constructed,
5373 we can construct it ourself. If one gives the h flag, then the
5374 "result" part of the entry is taken not to contain the href part of
5375 the link, but the whole link.
5376  
5377 For example, the entry:
5378  
5379 /&lt;URL:\s*(\S+?)\s*&gt;/ -h-> <A HREF="$1">$1</A>
5380  
5381 will take <URL:foo> and give us <A HREF="foo">foo</A>
5382  
5383 However, this is a very powerful mechanism, because it
5384 can be used to construct custom tags which aren't links at all.
5385 For example, to flag *italicised words* the following
5386 entry will surround the words with EM tags.
5387  
5388 /\B\*([a-z][a-z -]*[a-z])\*\B/ -hi-> <EM>$1</EM>
5389  
5390 B<The i flag>
5391  
5392 This turns on ignore case in the pattern matching.
5393  
5394 B<The e flag>
5395  
5396 This turns on execute in the pattern substitution. This really
5397 only makes sense if h is turned on too. In that case, the "result"
5398 part of the entry is taken as perl code to be executed, and the
5399 result of that code is what replaces the pattern.
5400  
5401 B<The o flag>
5402  
5403 This marks the entry as a once-only link. This will convert the
5404 first instance of a matching pattern, and ignore any others
5405 further on.
5406  
5407 For example, the following pattern will take the first mention
5408 of HTML::TextToHTML and convert it to a link to the module's home page.
5409  
5410 "HTML::TextToHTML" -io-> http://www.katspace.com/tools/text_to_html/
5411  
5412 =head2 Input File Format
5413  
5414 For the most part, this module tries to use intuitive conventions for
5415 determining the structure of the text input. Unordered lists are
5416 marked by bullets; ordered lists are marked by numbers or letters;
5417 in either case, an increase in indentation marks a sub-list contained
5418 in the outer list.
5419  
5420 Headers (apart from custom headers) are distinguished by "underlines"
5421 underneath them; headers in all-capitals are distinguished from
5422 those in mixed case. All headers, both normal and custom headers,
5423 are expected to start at the first line in a "paragraph".
5424  
5425 In other words, the following is a header:
5426  
5427 I am Head Man
5428 -------------
5429  
5430 But the following does not have a header:
5431  
5432 I am not a head Man, man
5433 I am Head Man
5434 -------------
5435  
5436 Tables require a more rigid convention. A table must be marked as a
5437 separate paragraph, that is, it must be surrounded by blank lines.
5438 Tables come in different types. For a table to be parsed, its
5439 --table_type option must be on, and the --make_tables option must be true.
5440  
5441 B<ALIGN Table Type>
5442  
5443 Columns must be separated by two or more spaces (this prevents
5444 accidental incorrect recognition of a paragraph where interword spaces
5445 happen to line up). If there are two or more rows in a paragraph and
5446 all rows share the same set of (two or more) columns, the paragraph is
5447 assumed to be a table. For example
5448  
5449 -e File exists.
5450 -z File has zero size.
5451 -s File has nonzero size (returns size).
5452  
5453 becomes
5454  
5455 <table>
5456 <tr><td>-e</td><td>File exists.</td></tr>
5457 <tr><td>-z</td><td>File has zero size.</td></tr>
5458 <tr><td>-s</td><td>File has nonzero size (returns size).</td></tr>
5459 </table>
5460  
5461 This guesses for each column whether it is intended to be left,
5462 centre or right aligned.
5463  
5464 B<BORDER Table Type>
5465  
5466 This table type has nice borders around it, and will be rendered
5467 with a border, like so:
5468  
5469 +---------+---------+
5470 | Column1 | Column2 |
5471 +---------+---------+
5472 | val1 | val2 |
5473 | val3 | val3 |
5474 +---------+---------+
5475  
5476 The above becomes
5477  
5478 <table border="1">
5479 <thead><tr><th>Column1</th><th>Column2</th></tr></thead>
5480 <tbody>
5481 <tr><td>val1</td><td>val2</td></tr>
5482 <tr><td>val3</td><td>val3</td></tr>
5483 </tbody>
5484 </table>
5485  
5486 It can also have an optional caption at the start.
5487  
5488 My Caption
5489 +---------+---------+
5490 | Column1 | Column2 |
5491 +---------+---------+
5492 | val1 | val2 |
5493 | val3 | val3 |
5494 +---------+---------+
5495  
5496 B<PGSQL Table Type>
5497  
5498 This format of table is what one gets from the output of a Postgresql
5499 query.
5500  
5501 Column1 | Column2
5502 ---------+---------
5503 val1 | val2
5504 val3 | val3
5505 (2 rows)
5506  
5507 This can also have an optional caption at the start.
5508 This table is also rendered with a border and table-headers like
5509 the BORDER type.
5510  
5511 B<DELIM Table Type>
5512  
5513 This table type is delimited by non-alphanumeric characters, and has to
5514 have at least two rows and two columns before it's recognised as a table.
5515  
5516 This one is delimited by the '| character:
5517  
5518 | val1 | val2 |
5519 | val3 | val3 |
5520  
5521 But one can use almost any suitable character such as : # $ % + and so on.
5522 This is clever enough to figure out what you are using as the delimiter
5523 if you have your data set up like a table. Note that the line has to
5524 both begin and end with the delimiter, as well as using it to separate
5525 values.
5526  
5527 This can also have an optional caption at the start.
5528  
5529 =head1 EXAMPLES
5530  
5531 use HTML::TextToHTML;
5532
5533 =head2 Create a new object
5534  
5535 my $conv = new HTML::TextToHTML();
5536  
5537 my $conv = new HTML::TextToHTML(title=>"Wonderful Things",
5538 default_link_dict=>$my_link_file,
5539 );
5540  
5541 =head2 Add further arguments
5542  
5543 $conv->args(short_line_length=>60,
5544 preformat_trigger_lines=>4,
5545 caps_tag=>"strong",
5546 );
5547  
5548 =head2 Convert a file
5549  
5550 $conv->txt2html(infile=>[$text_file],
5551 outfile=>$html_file,
5552 title=>"Wonderful Things",
5553 mail=>1
5554 );
5555  
5556 =head2 Make a pipleline
5557  
5558 open(IN, "ls |") or die "could not open!";
5559 $conv->txt2html(inhandle=>[\*IN],
5560 outfile=>'-',
5561 );
5562  
5563 =head1 NOTES
5564  
5565 =over
5566  
5567 =item *
5568  
5569 If the underline used to mark a header is off by more than 1, then
5570 that part of the text will not be picked up as a header unless you
5571 change the value of --underline_length_tolerance and/or
5572 --underline_offset_tolerance. People tend to forget this.
5573  
5574 =back
5575  
5576 =head1 REQUIRES
5577  
5578 HTML::TextToHTML requires Perl 5.8.1 or later.
5579  
5580 For installation, it needs:
5581  
5582 Module::Build
5583  
5584 The txt2html script needs:
5585  
5586 Getopt::Long
5587 Getopt::ArgvFile
5588 Pod::Usage
5589 File::Basename
5590  
5591 For testing, it also needs:
5592  
5593 Test::More
5594  
5595 For debugging, it also needs:
5596  
5597 YAML::Syck
5598  
5599 =head1 INSTALLATION
5600  
5601 Make sure you have the dependencies installed first!
5602 (see REQUIRES above)
5603  
5604 Some of those modules come standard with more recent versions of perl,
5605 but I thought I'd mention them anyway, just in case you may not have
5606 them.
5607  
5608 If you don't know how to install these, try using the CPAN module, an
5609 easy way of auto-installing modules from the Comprehensive Perl Archive
5610 Network, where the above modules reside.
5611 Do "perldoc perlmodinstall" or "perldoc CPAN" for more information.
5612  
5613 To install this module type the following:
5614  
5615 perl Build.PL
5616 ./Build
5617 ./Build test
5618 ./Build install
5619  
5620 Or, if you're on a platform (like DOS or Windows) that doesn't like the
5621 "./" notation, you can do this:
5622  
5623 perl Build.PL
5624 perl Build
5625 perl Build test
5626 perl Build install
5627  
5628 In order to install somewhere other than the default, such as
5629 in a directory under your home directory, like "/home/fred/perl"
5630 go
5631  
5632 perl Build.PL --install_base /home/fred/perl
5633  
5634 as the first step instead.
5635  
5636 This will install the files underneath /home/fred/perl.
5637  
5638 You will then need to make sure that you alter the PERL5LIB variable to
5639 find the modules, and the PATH variable to find the script.
5640  
5641 Therefore you will need to change:
5642 your path, to include /home/fred/perl/script (where the script will be)
5643  
5644 PATH=/home/fred/perl/script:${PATH}
5645  
5646 the PERL5LIB variable to add /home/fred/perl/lib
5647  
5648 PERL5LIB=/home/fred/perl/lib:${PERL5LIB}
5649  
5650 Note that the system links dictionary will be installed as
5651 "/home/fred/perl/share/txt2html/txt2html.dict"
5652  
5653 If you want to install in a temporary install directory (such as
5654 if you are building a package) then instead of going
5655  
5656 perl Build install
5657  
5658 go
5659  
5660 perl Build install destdir=/my/temp/dir
5661  
5662 and it will be installed there, with a directory structure under
5663 /my/temp/dir the same as it would be if it were installed plain.
5664 Note that this is NOT the same as setting --install_base, because
5665 certain things are done at build-time which use the install_base info.
5666  
5667 See "perldoc perlrun" for more information on PERL5LIB, and
5668 see "perldoc Module::Build" for more information on
5669 installation options.
5670  
5671 =head1 BUGS
5672  
5673 Tell me about them.
5674  
5675 =head1 SEE ALSO
5676  
5677 perl
5678 L<txt2html>.
5679  
5680 =head1 AUTHOR
5681  
5682 Kathryn Andersen (RUBYKAT)
5683 perlkat AT katspace dot com
5684 http//www.katspace.com/
5685  
5686 based on txt2html by Seth Golub
5687  
5688 =head1 COPYRIGHT AND LICENCE
5689  
5690 Original txt2html script copyright (c) 1994-2000 Seth Golub <seth AT aigeek.com>
5691  
5692 Copyright (c) 2002-2005 by Kathryn Andersen
5693  
5694 This program is free software; you can redistribute it and/or
5695 modify it under the same terms as Perl itself.
5696  
5697 =cut
5698  
5699 #------------------------------------------------------------------------
5700 7 1;
↑ Summary