Markup/Rest.pm

filter: Statementstmt 65.3% 17 / 26 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod n/a totaltotal 60.5% 23 / 38 CC 3 SCAR 11.0
CC
3
Cov
57%
import
6.0
parser
6.0
BEGIN
1.0
CRAP 3.0
« Markup.pm ↑ Summary Markup/Mediawiki.pm »
1 package Text::Markup::Rest;
2  
3 1 ▶use 5.8.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Text::Markup;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Text::Markup::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 our $VERSION = '0.43';
11  
12 0 ▶sub import {
Subroutine import: not called CC=2 SCAR=17.9
13 # Replace the regex if passed one.
14 0 ▶ Text::Markup->register( rest => $_[1] ) if $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 0 0 0
15 }
16  
17 # Find Python or die.
18 my $PYTHON = find_cmd(
19 [WIN32 ? 'python3.exe' : 'python3'],
20 '--version',
21 );
22  
23 # We have python, let's find out if we have docutils.
24 exec_or_die(
25 qq{Missing required Python "docutils" module},
26 $PYTHON, '-c', 'import docutils',
27 );
28  
29 # We ship with our own rst2html that's lenient with unknown directives.
30 my $RST2HTML = File::Spec->catfile(dirname(__FILE__), 'rst2html_lenient.py');
31  
32 exec_or_die(
33 "$RST2HTML will not execute",
34 $PYTHON, $RST2HTML, '--test-patch',
35 );
36  
37 # Optional arguments to pass to rst2html
38 my @OPTIONS = qw(
39 --no-raw
40 --no-file-insertion
41 --stylesheet=
42 --cloak-email-address
43 --no-generator
44 --quiet
45 );
46  
47 # Options to improve rendering of Sphinx documents
48 my @SPHINX_OPTIONS = qw(
49 --dir-ignore toctree
50 --dir-ignore highlight
51 --dir-ignore index
52 --dir-ignore default-domain
53  
54 --dir-nested note
55 --dir-nested warning
56 --dir-nested versionadded
57 --dir-nested versionchanged
58 --dir-nested deprecated
59 --dir-nested seealso
60 --dir-nested hlist
61 --dir-nested glossary
62  
63 --dir-notitle code-block
64  
65 --dir-nested module
66 --dir-nested function
67 --output-encoding utf-8
68 );
69 # note: domains directive (last 2 options) incomplete
70  
71 0 ▶sub parser {
Subroutine parser: not called CC=2 SCAR=17.9
72 0 my ($file, $encoding, $opts) = @_;
73 0 my $html = do {
74 0 my $fh = open_pipe(
75 $PYTHON, $RST2HTML,
76 @OPTIONS, @SPHINX_OPTIONS,
77 '--input-encoding', $encoding,
78 $file
79 );
80 0 local $/;
81 0 <$fh>;
82 };
83  
84 # Make sure we have something.
85 0 ▶ return undef if $html =~ m{<div\s+class\s*=\s*(['"])document\1>\s+</div>}ms;
Branch: 1 branch
BranchTrueFalseTotal
if $html =~ m[<div\s+class\s*=\s*(['"])document\1>\s+</div>]ms 0 0 0
86  
87 # Alas, --no-generator does not remove the generator meta tag. :-(
88 0 $html =~ s{^\s*<meta\s+name\s*=\s*(['"])generator\1[^>]+>\n}{}ms;
89  
90 0 return $html;
91 }
92  
93 1;
94 __END__
« Markup.pm ↑ Summary Markup/Mediawiki.pm »