line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Markup::Rest; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2564
|
use 5.8.1; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
5
|
use Text::Markup::Cmd; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
7
|
1
|
|
|
1
|
|
6
|
use File::Basename; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
412
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.31'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Find Python or die. |
12
|
|
|
|
|
|
|
my $PYTHON = find_cmd( |
13
|
|
|
|
|
|
|
[WIN32 ? 'python3.exe' : 'python3'], |
14
|
|
|
|
|
|
|
'--version', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# We have python, let's find out if we have docutils. |
18
|
|
|
|
|
|
|
exec_or_die( |
19
|
|
|
|
|
|
|
qq{Missing required Python "docutils" module}, |
20
|
|
|
|
|
|
|
$PYTHON, '-c', 'import docutils', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# We ship with our own rst2html that's lenient with unknown directives. |
24
|
|
|
|
|
|
|
my $RST2HTML = File::Spec->catfile(dirname(__FILE__), 'rst2html_lenient.py'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
exec_or_die( |
27
|
|
|
|
|
|
|
"$RST2HTML will not execute", |
28
|
|
|
|
|
|
|
$PYTHON, $RST2HTML, '--test-patch', |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Optional arguments to pass to rst2html |
32
|
|
|
|
|
|
|
my @OPTIONS = qw( |
33
|
|
|
|
|
|
|
--no-raw |
34
|
|
|
|
|
|
|
--no-file-insertion |
35
|
|
|
|
|
|
|
--stylesheet= |
36
|
|
|
|
|
|
|
--cloak-email-address |
37
|
|
|
|
|
|
|
--no-generator |
38
|
|
|
|
|
|
|
--quiet |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Options to improve rendering of Sphinx documents |
42
|
|
|
|
|
|
|
my @SPHINX_OPTIONS = qw( |
43
|
|
|
|
|
|
|
--dir-ignore toctree |
44
|
|
|
|
|
|
|
--dir-ignore highlight |
45
|
|
|
|
|
|
|
--dir-ignore index |
46
|
|
|
|
|
|
|
--dir-ignore default-domain |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
--dir-nested note |
49
|
|
|
|
|
|
|
--dir-nested warning |
50
|
|
|
|
|
|
|
--dir-nested versionadded |
51
|
|
|
|
|
|
|
--dir-nested versionchanged |
52
|
|
|
|
|
|
|
--dir-nested deprecated |
53
|
|
|
|
|
|
|
--dir-nested seealso |
54
|
|
|
|
|
|
|
--dir-nested hlist |
55
|
|
|
|
|
|
|
--dir-nested glossary |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
--dir-notitle code-block |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
--dir-nested module |
60
|
|
|
|
|
|
|
--dir-nested function |
61
|
|
|
|
|
|
|
--output-encoding utf-8 |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
# note: domains directive (last 2 options) incomplete |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub parser { |
66
|
0
|
|
|
0
|
|
|
my ($file, $encoding, $opts) = @_; |
67
|
0
|
|
|
|
|
|
my $html = do { |
68
|
0
|
|
|
|
|
|
my $fh = open_pipe( |
69
|
|
|
|
|
|
|
$PYTHON, $RST2HTML, |
70
|
|
|
|
|
|
|
@OPTIONS, @SPHINX_OPTIONS, |
71
|
|
|
|
|
|
|
'--input-encoding', $encoding, |
72
|
|
|
|
|
|
|
$file |
73
|
|
|
|
|
|
|
); |
74
|
0
|
|
|
|
|
|
local $/; |
75
|
0
|
|
|
|
|
|
<$fh>; |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Make sure we have something. |
79
|
0
|
0
|
|
|
|
|
return undef if $html =~ m{ \s+ }ms; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Alas, --no-generator does not remove the generator meta tag. :-( |
82
|
0
|
|
|
|
|
|
$html =~ s{^\s*]+>\n}{}ms; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return $html; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
__END__ |