| 1 | package Markdown::Perl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 31 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 31 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 31 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 31 | ▶ | use feature ':5.24'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 31 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 31 | ▶ | use English; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 31 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 31 | ▶ | use Hash::Util 'lock_keys'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 31 | ▶ | use List::Util 'none'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 31 | ▶ | use List::MoreUtils 'pairwise'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 31 | ▶ | use Markdown::Perl::BlockParser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 31 | ▶ | use Markdown::Perl::Inlines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 31 | ▶ | use Markdown::Perl::HTML 'html_escape', 'decode_entities', 'parse_attributes'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 31 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 31 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 31 | ▶ | use parent 'Markdown::Perl::Options'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 31 | our $VERSION = '1.14'; # remember to bump in App::pmarkdown too. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 31 | our @EXPORT_OK = qw(convert set_options set_mode set_hooks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 31 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 47 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 47 | my ($class, @options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 47 | my $this = $class->SUPER::new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | mode => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | options => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | local_options => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | hooks => {}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 47 | $this->SUPER::set_options(options => @options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 47 | lock_keys(%{$this}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 47 | return $this; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | sub set_options { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | my ($this, @options) = &_get_this_and_args; ## no critic (ProhibitAmpersandSigils) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | $this->SUPER::set_options(options => @options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | ▶ | sub set_mode { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_mode: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | my ($this, $mode) = &_get_this_and_args; ## no critic (ProhibitAmpersandSigils) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | $this->SUPER::set_mode(options => $mode); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 31 | Readonly::Array my @VALID_HOOKS => qw(resolve_link_ref yaml_metadata); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | ▶ | sub set_hooks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_hooks: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 9 | my ($this, %hooks) = &_get_this_and_args; ## no critic (ProhibitAmpersandSigils) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 9 | ▶ | while (my ($k, $v) = each %hooks) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 9 | ▶ | if (none { $_ eq $k } @VALID_HOOKS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | croak "Invalid hook name: ${k}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } elsif (!defined $v) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | delete $this->{hooks}{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } elsif (ref $v ne 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | carp 'Hook target must be a CODE reference'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 8 | $this->{hooks}{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # Returns @_, unless the first argument is not blessed as a Markdown::Perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # object, in which case it returns a default object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 31 | my $default_this = Markdown::Perl->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 35159 | ▶ | sub _get_this_and_args { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_this_and_args: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 35159 | ▶ | return unless @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # We could use `$this isa Markdown::Perl` that does not require to test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # blessedness first. However this requires 5.31.6 which is not in Debian | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # stable as of writing this. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 35159 | ▶ | if (!blessed($_[0]) || !$_[0]->isa(__PACKAGE__)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
MC/DC50%1/2
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
builtin::blessed($_[0])
$_[0]->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 206 | unshift @_, $default_this; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 35159 | ▶ | return @_ if defined wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 17575 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # Takes a string and converts it to HTML. Can be called as a free function or as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # class method. In the latter case, provided options override those set in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # class constructor. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # Both the input and output are unicode strings. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 17575 | ▶ | sub convert { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 17575 | &_get_this_and_args; ## no critic (ProhibitAmpersandSigils) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 17575 | my $this = shift @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 17575 | my $md = \(shift @_); # Taking a reference to avoid copying the input. is it useful? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 17575 | $this->SUPER::set_options(local_options => @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # TODO: introduce an HtmlRenderer object that carries the $linkrefs states | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # around (instead of having to pass it in all the calls). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 17572 | my ($blocks, $linkrefs) = $this->_parse($md); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 17571 | my $out = $this->_emit_html(0, 'root', $linkrefs, @{$blocks}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 17571 | $this->{local_options} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 17571 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # This is an internal call for now because the structure of the parse tree is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # not defined. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # Note that while convert() takes care not to copy the md argument, this is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # the case of this method, however, it can receive a scalar ref instead of a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # scalar, to avoid the copy. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # TODO: create a BlockTree class and document it, then make this be public. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 17572 | ▶ | sub _parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 17572 | my ($this, $md_or_ref) = &_get_this_and_args; ## no critic (ProhibitAmpersandSigils) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 17572 | ▶ | my $md = ref($md_or_ref) ? $md_or_ref : \$md_or_ref; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 17572 | my $parser = Markdown::Perl::BlockParser->new($this, $md); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 17572 | my ($linkrefs, $blocks) = $parser->process(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 17571 | ▶ | return ($blocks, $linkrefs) if wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | return $blocks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 44053 | ▶ | sub _render_inlines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_render_inlines: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 44053 | my ($this, $linkrefs, @lines) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 44053 | return Markdown::Perl::Inlines::render($this, $linkrefs, @lines); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # TODO: move this to a separate package and split the method in smaller chunks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 43522 | ▶ | sub _emit_html { ## no critic (ProhibitExcessComplexity) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_html: called CC=39 SCAR=36.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 43522 | my ($this, $tight_block, $parent_type, $linkrefs, @blocks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 43522 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 43522 | my $block_index = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 43522 | for my $bl (@blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 75289 | $block_index++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 75289 | ▶ | if ($bl->{type} eq 'break') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 250 | $out .= "<hr />\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } elsif ($bl->{type} eq 'heading') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1032 | my $l = $bl->{level}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1032 | my $c = $bl->{content}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1032 | ▶ | $c = $this->_render_inlines($linkrefs, ref $c eq 'ARRAY' ? @{$c} : $c); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1032 | $c =~ s/^[ \t]+|[ \t]+$//g; # Only the setext headings spec asks for this, but this can’t hurt atx heading where this can’t change anything. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1032 | $out .= "<h${l}>$c</h${l}>\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } elsif ($bl->{type} eq 'code') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 4870 | my $c = $bl->{content}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 4870 | html_escape($c, $this->get_html_escaped_code_characters); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 4870 | my $i = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 4870 | ▶ | if ($this->get_code_blocks_info eq 'language' && $bl->{info}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$this->get_code_blocks_info eq "language" and $bl->{"info"}
MC/DC50%1/2
$this->get_code_blocks_info eq "language" and $bl->{"info"}
$this->get_code_blocks_info eq "language"
$bl->{"info"}
Truth table66%2/3
A and B
A= $this->get_code_blocks_info eq "language"B= $bl->{"info"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 3181 | my $l = $bl->{info} =~ s/\s.*//r; # The spec does not really cover this behavior so we’re using Perl notion of whitespace here. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 3181 | decode_entities($l); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 3181 | html_escape($l, $this->get_html_escaped_characters); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 3181 | $i = " class=\"language-${l}\""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 4870 | $out .= "<pre><code${i}>$c</code></pre>\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } elsif ($bl->{type} eq 'html') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 2656 | $out .= $bl->{content}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } elsif ($bl->{type} eq 'paragraph') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 42994 | my $html = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 42994 | ▶ | if (( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$this->get_allow_task_list_markers eq "list" and $parent_type eq "list" and $block_index == 1 or $this->get_allow_task_list_markers eq "always"
$this->get_allow_task_list_markers eq "list" and $parent_type eq "list" and $block_index == 1
$this->get_allow_task_list_markers eq "list" and $parent_type eq "list"
MC/DC100%4/4
$this->get_allow_task_list_markers eq "list" and $parent_type eq "list" and $block_index == 1 or $this->get_allow_task_list_markers eq "always"
$this->get_allow_task_list_markers eq "list"
$parent_type eq "list"
$block_index == 1
$this->get_allow_task_list_markers eq "always"
Truth table71%5/7
A and B and C or D
A= $this->get_allow_task_list_markers eq "list"B= $parent_type eq "list"C= $block_index == 1D= $this->get_allow_task_list_markers eq "always"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | $this->get_allow_task_list_markers eq 'list' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | && $parent_type eq 'list' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | && $block_index == 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | || $this->get_allow_task_list_markers eq 'always' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 7908 | ▶ | if ($bl->{content}[0] =~ m/ ^ \s* \[ (?<marker> [ xX] ) \] (?<space> \s | $ ) /x) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | $html = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | '<input ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | .($LAST_PAREN_MATCH{marker} eq ' ' ? '' : 'checked="" ') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | .'disabled="" type="checkbox">' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 9 | ▶ | .($LAST_PAREN_MATCH{space} eq ' ' ? ' ' : "\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 9 | substr $bl->{content}[0], 0, $LAST_MATCH_END[0], ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 42994 | $html .= $this->_render_inlines($linkrefs, @{$bl->{content}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 42994 | ▶ | if ($tight_block) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 11994 | $out .= $html; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } elsif ($this->get_render_naked_paragraphs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 5 | $out .= "${html}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 30995 | $out .= "<p>${html}</p>\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } elsif ($bl->{type} eq 'quotes') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 9507 | my $c = $this->_emit_html(0, 'quotes', $linkrefs, @{$bl->{content}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 9507 | $out .= "<blockquote>\n${c}</blockquote>\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } elsif ($bl->{type} eq 'list') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 13900 | my $type = $bl->{style}; # 'ol' or 'ul' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 13900 | my $start = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 13900 | my $num = $bl->{start_num}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 13900 | my $loose = $bl->{loose}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 13900 | ▶ | $start = " start=\"${num}\"" if $type eq 'ol' && $num != 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$type eq "ol" and $num != 1
MC/DC100%2/2
$type eq "ol" and $num != 1
$type eq "ol"
$num != 1
Truth table100%3/3
A and B
A= $type eq "ol"B= $num != 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | $out .= "<${type}${start}>\n<li>" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | .join("</li>\n<li>", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 13900 | map { $this->_emit_html(!$loose, 'list', $linkrefs, @{$_->{content}}) } @{$bl->{items}}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | ."</li>\n</${type}>\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } elsif ($bl->{type} eq 'table') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 7 | $out .= '<table><thead><tr>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 7 | ▶ | my @align = map { $_ ? " align=\"${_}\"" : '' } @{$bl->{content}{align}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 7 | my @h = map { $this->_render_inlines($linkrefs, $_) } @{$bl->{content}{headers}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 7 | ▶ | $out .= join('', pairwise { "<th${a}>${b}</th>" } @align, @h); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 7 | $out .= '</tr></thead>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 7 | ▶ | if (@{$bl->{content}{table}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | $out .= '<tbody>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 6 | my $ms = $this->get_table_blocks_have_cells_for_missing_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 6 | for my $l (@{$bl->{content}{table}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 9 | $out .= '<tr>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 9 | ▶ | my @d = map { defined ? $this->_render_inlines($linkrefs, $_) : $ms ? '' : undef } @{$l}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 9 | ▶ | $out .= join('', pairwise { defined $b ? "<td${a}>${b}</td>" : '' } @align, @d); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 9 | $out .= '</tr>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 6 | $out .= '</tbody>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 7 | $out .= '</table>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } elsif ($bl->{type} eq 'directive') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 73 | my $c = $this->_emit_html(0, 'directive', $linkrefs, @{$bl->{content}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 73 | ▶ | my %attr = parse_attributes($bl->{attributes}) if defined $bl->{attributes}; ## no critic (ProhibitConditionalDeclaration) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 73 | my @attr = ('div'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 73 | ▶ | push @attr, 'id="'.$attr{id}.'"' if exists $attr{id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 73 | ▶ | unshift @{$attr{class}}, lc($bl->{name}) if defined $bl->{name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 73 | ▶ | push @attr, 'class="'.join(' ', @{$attr{class}}).'"' if exists $attr{class}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 73 | ▶ | push @attr, map { sprintf 'data-%s="%s"', @{$_} } @{$attr{keys}} if exists $attr{keys}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 73 | my $tag = join(' ', @attr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # TODO: the inline content is ignored for now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # TODO we should add a hook to process the directive in custom cases. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 73 | $out .= "<${tag}>\n${c}</div>\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 73 | ▶ | if (defined $bl->{inline} && $this->get_warn_for_unused_input()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $bl->{"inline"} and $this->get_warn_for_unused_input
MC/DC100%2/2
defined $bl->{"inline"} and $this->get_warn_for_unused_input
defined $bl->{"inline"}
$this->get_warn_for_unused_input
Truth table100%3/3
A and B
A= defined $bl->{"inline"}B= $this->get_warn_for_unused_input
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | carp 'Unused inline content in a directive block: '.$bl->{inline}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 73 | ▶ | if (defined $attr{junk} && $this->get_warn_for_unused_input()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $attr{"junk"} and $this->get_warn_for_unused_input
MC/DC100%2/2
defined $attr{"junk"} and $this->get_warn_for_unused_input
defined $attr{"junk"}
$this->get_warn_for_unused_input
Truth table100%3/3
A and B
A= defined $attr{"junk"}B= $this->get_warn_for_unused_input
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | carp 'Unused attribute content in a directive block: '.$attr{junk}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | confess 'Unexpected block type when rendering HTML output: '.$bl->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # Note: a final new line should always be appended to $out. This is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # guaranteed when the last element is HTML and the input file did not contain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # a final new line, unless the option force_final_new_line is set. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 43522 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 31 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||