| 1 | package Markdent::Dialect::GitHub::SpanParser; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 5 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 5 | our $VERSION = '0.39'; | |||||||||
| 8 | |||||||||||
| 9 | 5 | ▶ | use Markdent::Event::AutoLink; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 5 | ▶ | use Markdent::Event::EndStrikethrough; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 5 | ▶ | use Markdent::Event::LineBreak; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 5 | ▶ | use Markdent::Event::StartStrikethrough; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 5 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 5 | with 'Markdent::Role::Dialect::SpanParser'; | |||||||||
| 17 | |||||||||||
| 18 | sub _build_emphasis_start_delimiter_re { | ||||||||||
| 19 | 19 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build_emphasis_start_delimiter_re: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 19 | return qr/(?:\*|(?<=\W)_|(?<=^)_)/; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) | ||||||||||
| 25 | sub _emphasis_end_delimiter_re { | ||||||||||
| 26 | 10 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_emphasis_end_delimiter_re: called CC=2 SCAR=6.9
| |||||||||||
| 27 | 10 | my $delim = shift; | |||||||||
| 28 | |||||||||||
| 29 | 10 | ▶ | return $delim eq '*' ? qr/\Q$delim\E/ : qr/\Q$delim\E(?=$|\W)/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | } | ||||||||||
| 31 | ## use critic | ||||||||||
| 32 | |||||||||||
| 33 | around _possible_span_matches => sub { | ||||||||||
| 34 | 69 | ▶ | my $orig = shift; | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||
| 35 | 69 | my $self = shift; | |||||||||
| 36 | |||||||||||
| 37 | 69 | my @look_for = $self->$orig(); | |||||||||
| 38 | |||||||||||
| 39 | 69 | my %open = $self->_open_start_events_for_span( 'code', 'link' ); | |||||||||
| 40 | |||||||||||
| 41 | push @look_for, $self->_look_for_strikethrough | ||||||||||
| 42 | 69 | ▶ | unless $open{code}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | push @look_for, 'bare_link' | ||||||||||
| 44 | 69 | ▶ | unless $open{link}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | |||||||||||
| 46 | 69 | return @look_for; | |||||||||
| 47 | 5 | }; | |||||||||
| 48 | |||||||||||
| 49 | sub _look_for_strikethrough { | ||||||||||
| 50 | 69 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_look_for_strikethrough: called CC=2 SCAR=6.9
| |||||||||||
| 51 | |||||||||||
| 52 | 69 | my %open = $self->_open_start_events_for_span('strikethrough'); | |||||||||
| 53 | |||||||||||
| 54 | 69 | ▶ | if ( $open{strikethrough} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 2 | return ( [ 'strikethrough_end', $open{strikethrough}->delimiter ] ); | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 67 | return ('strikethrough_start'); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) | ||||||||||
| 62 | sub _match_bare_link { | ||||||||||
| 63 | 57 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_match_bare_link: called CC=2 SCAR=6.9
| |||||||||||
| 64 | 57 | my $text = shift; | |||||||||
| 65 | |||||||||||
| 66 | 57 | ▶ | return unless ${$text} =~ m{ \G | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | (?: | ||||||||||
| 68 | (?<=^) | ||||||||||
| 69 | | | ||||||||||
| 70 | (?<=\W) | ||||||||||
| 71 | ) | ||||||||||
| 72 | ( | ||||||||||
| 73 | https? | ||||||||||
| 74 | :// | ||||||||||
| 75 | \S+ | ||||||||||
| 76 | ) | ||||||||||
| 77 | }xgc; | ||||||||||
| 78 | |||||||||||
| 79 | 5 | my $link = $self->_make_event( AutoLink => uri => $1 ); | |||||||||
| 80 | |||||||||||
| 81 | 5 | $self->_markup_event($link); | |||||||||
| 82 | |||||||||||
| 83 | 5 | return 1; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | sub _match_strikethrough_start { | ||||||||||
| 87 | 57 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_match_strikethrough_start: called CC=2 SCAR=6.9
| |||||||||||
| 88 | 57 | my $text = shift; | |||||||||
| 89 | |||||||||||
| 90 | 57 | ▶ | my ($delim) = $self->_match_delimiter_start( $text, qr/\~\~/ ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | or return; | ||||||||||
| 92 | |||||||||||
| 93 | 1 | my $event | |||||||||
| 94 | = $self->_make_event( StartStrikethrough => delimiter => $delim ); | ||||||||||
| 95 | |||||||||||
| 96 | 1 | $self->_markup_event($event); | |||||||||
| 97 | |||||||||||
| 98 | 1 | return 1; | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | sub _match_strikethrough_end { | ||||||||||
| 102 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_match_strikethrough_end: called CC=2 SCAR=6.9
| |||||||||||
| 103 | 2 | my $text = shift; | |||||||||
| 104 | 2 | my $delim = shift; | |||||||||
| 105 | |||||||||||
| 106 | 2 | ▶ | $self->_match_delimiter_end( $text, qr/\Q$delim\E/ ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 107 | or return; | ||||||||||
| 108 | |||||||||||
| 109 | 1 | my $event = $self->_make_event( EndStrikethrough => delimiter => $delim ); | |||||||||
| 110 | |||||||||||
| 111 | 1 | $self->_markup_event($event); | |||||||||
| 112 | |||||||||||
| 113 | 1 | return 1; | |||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | ## use critic | ||||||||||
| 117 | |||||||||||
| 118 | around _text_end_res => sub { | ||||||||||
| 119 | 52 | ▶ | my $orig = shift; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 120 | 52 | my $self = shift; | |||||||||
| 121 | |||||||||||
| 122 | return ( | ||||||||||
| 123 | 52 | $self->$orig(), | |||||||||
| 124 | qr{https?://}, | ||||||||||
| 125 | qr/\~\~/, | ||||||||||
| 126 | ); | ||||||||||
| 127 | 5 | }; | |||||||||
| 128 | |||||||||||
| 129 | 5 | 1; | |||||||||
| 130 | |||||||||||
| 131 | # ABSTRACT: Span parser for GitHub Markdown | ||||||||||
| 132 | |||||||||||
| 133 | __END__ | ||||||||||
| 134 | |||||||||||
| 135 | =pod | ||||||||||
| 136 | |||||||||||
| 137 | =encoding UTF-8 | ||||||||||
| 138 | |||||||||||
| 139 | =head1 NAME | ||||||||||
| 140 | |||||||||||
| 141 | Markdent::Dialect::GitHub::SpanParser - Span parser for GitHub Markdown | ||||||||||
| 142 | |||||||||||
| 143 | =head1 VERSION | ||||||||||
| 144 | |||||||||||
| 145 | version 0.39 | ||||||||||
| 146 | |||||||||||
| 147 | =head1 DESCRIPTION | ||||||||||
| 148 | |||||||||||
| 149 | This role adds parsing for some of the Markdown extensions used on GitHub. See | ||||||||||
| 150 | http://github.github.com/github-flavored-markdown/ for details. | ||||||||||
| 151 | |||||||||||
| 152 | =head1 ROLES | ||||||||||
| 153 | |||||||||||
| 154 | This role does the L<Markdent::Role::Dialect::SpanParser> role. | ||||||||||
| 155 | |||||||||||
| 156 | =head1 BUGS | ||||||||||
| 157 | |||||||||||
| 158 | See L<Markdent> for bug reporting details. | ||||||||||
| 159 | |||||||||||
| 160 | Bugs may be submitted at L<https://github.com/houseabsolute/Markdent/issues>. | ||||||||||
| 161 | |||||||||||
| 162 | I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>. | ||||||||||
| 163 | |||||||||||
| 164 | =head1 SOURCE | ||||||||||
| 165 | |||||||||||
| 166 | The source code repository for Markdent can be found at L<https://github.com/houseabsolute/Markdent>. | ||||||||||
| 167 | |||||||||||
| 168 | =head1 AUTHOR | ||||||||||
| 169 | |||||||||||
| 170 | Dave Rolsky <autarch@urth.org> | ||||||||||
| 171 | |||||||||||
| 172 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 173 | |||||||||||
| 174 | This software is copyright (c) 2021 by Dave Rolsky. | ||||||||||
| 175 | |||||||||||
| 176 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 177 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 178 | |||||||||||
| 179 | The full text of the license can be found in the | ||||||||||
| 180 | F<LICENSE> file included with this distribution. | ||||||||||
| 181 | |||||||||||
| 182 | =cut | ||||||||||