File Coverage

blib/lib/Markdent/Dialect/GitHub/BlockParser.pm
Criterion Covered Total %
statement 27 27 100.0
branch 5 8 62.5
condition n/a
subroutine 7 7 100.0
pod n/a
total 39 42 92.8


line stmt bran cond sub pod time code
1             package Markdent::Dialect::GitHub::BlockParser;
2              
3 5     5   2611 use strict;
  5         15  
  5         152  
4 5     5   25 use warnings;
  5         12  
  5         142  
5 5     5   25 use namespace::autoclean;
  5         10  
  5         46  
6              
7             our $VERSION = '0.39';
8              
9 5     5   2464 use Markdent::Event::CodeBlock;
  5         19  
  5         221  
10 5     5   1790 use Markdent::Regexes qw( $BlockStart $HorizontalWS );
  5         18  
  5         689  
11              
12 5     5   37 use Moose::Role;
  5         10  
  5         49  
13              
14             with 'Markdent::Role::Dialect::BlockParser';
15              
16             around _possible_block_matches => sub {
17             my $orig = shift;
18             my $self = shift;
19              
20             my @look_for = $self->$orig();
21             unshift @look_for, 'fenced_code_block';
22              
23             return @look_for;
24             };
25              
26             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
27             sub _match_fenced_code_block {
28 37     37   118 my $self = shift;
29 37         66 my $text = shift;
30              
31 37 100       69 return unless ${$text} =~ / \G
  37         563  
32             $BlockStart
33             ```
34             $HorizontalWS?\{?\.?([\w-]+)?\}?$HorizontalWS* # optional language name
35             \n
36             ( # code block content
37             (?:.|\n)+?
38             )
39             \n
40             ```
41             \n
42             /xmgc;
43              
44 7         23 my $lang = $1;
45 7         16 my $code = $2;
46              
47 7 0       170 $self->_debug_parse_result(
    50          
48             $code,
49             'code block',
50             ( $lang ? [ language => $lang ] : () ),
51             ) if $self->debug;
52              
53 7 100       50 $self->_send_event(
54             'CodeBlock',
55             code => $code,
56             ( defined $lang ? ( language => $lang ) : () ),
57             );
58              
59 7         824 return 1;
60             }
61             ## use critic
62              
63             1;
64              
65             # ABSTRACT: Block parser for GitHub Markdown
66              
67             __END__
68              
69             =pod
70              
71             =encoding UTF-8
72              
73             =head1 NAME
74              
75             Markdent::Dialect::GitHub::BlockParser - Block parser for GitHub Markdown
76              
77             =head1 VERSION
78              
79             version 0.39
80              
81             =head1 DESCRIPTION
82              
83             This role adds parsing for some of the Markdown extensions used on GitHub. See
84             http://github.github.com/github-flavored-markdown/ for details.
85              
86             =head1 ROLES
87              
88             This role does the L<Markdent::Role::Dialect::BlockParser> role.
89              
90             =head1 BUGS
91              
92             See L<Markdent> for bug reporting details.
93              
94             Bugs may be submitted at L<https://github.com/houseabsolute/Markdent/issues>.
95              
96             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
97              
98             =head1 SOURCE
99              
100             The source code repository for Markdent can be found at L<https://github.com/houseabsolute/Markdent>.
101              
102             =head1 AUTHOR
103              
104             Dave Rolsky <autarch@urth.org>
105              
106             =head1 COPYRIGHT AND LICENSE
107              
108             This software is copyright (c) 2021 by Dave Rolsky.
109              
110             This is free software; you can redistribute it and/or modify it under
111             the same terms as the Perl 5 programming language system itself.
112              
113             The full text of the license can be found in the
114             F<LICENSE> file included with this distribution.
115              
116             =cut