Markdent/Simple/Document.pm

filter: Statementstmt 100% 39 / 39 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 96.3% 52 / 54 CC 3 SCAR 3.9
CC
3
Cov
95%
markdown_to_html
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« Markdent/Handler/HTMLStream/Document.pm ↑ Summary Markdent/CheckedOutput.pm »
1 package Markdent::Simple::Document;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.39';
8  
9 1 ▶use Markdent::Handler::HTMLStream::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Markdent::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Params::ValidationCompiler qw( validation_for );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Specio::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 with 'Markdent::Role::Simple';
18  
19 {
20 my $validator = validation_for(
21 params => [
22 dialects => {
23 type => union(
24 of => [
25 t('Str'),
26 t( 'ArrayRef', of => t('Str') )
27 ]
28 ),
29 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
30 },
31 1 title => { type => t('Str') },
32 charset => {
33 type => t('Str'),
34 optional => 1,
35 },
36 language => {
37 type => t('Str'),
38 optional => 1,
39 },
40 markdown => { type => t('Str') },
41 ],
42 named_to_list => 1,
43 );
44  
45 sub markdown_to_html {
46 1 ▶ my $self = shift;
Subroutine markdown_to_html: called CC=3 SCAR=11.3
47 1 my ( $dialects, $title, $charset, $language, $markdown )
48 = $validator->(@_);
49  
50 1 my $handler_class = 'Markdent::Handler::HTMLStream::Document';
51 1 ▶ my %handler_p = (
Branch: 2 branches
BranchTrueFalseTotal
$charset ? : 0 1 1
$language ? : 0 1 1
52 title => $title,
53 ( $charset ? ( charset => $charset ) : () ),
54 ( $language ? ( language => $language ) : () ),
55 );
56  
57 1 return $self->_parse_markdown(
58 $markdown,
59 $dialects,
60 $handler_class,
61 \%handler_p
62 );
63 }
64 }
65  
66 1 __PACKAGE__->meta->make_immutable;
67  
68 1 1;
69  
70 # ABSTRACT: Convert Markdown to an HTML Document
71  
72 __END__
73  
74 =pod
75  
76 =encoding UTF-8
77  
78 =head1 NAME
79  
80 Markdent::Simple::Document - Convert Markdown to an HTML Document
81  
82 =head1 VERSION
83  
84 version 0.39
85  
86 =head1 SYNOPSIS
87  
88 use Markdent::Simple::Document;
89  
90 my $mds = Markdent::Simple::Document->new;
91 my $html = $mds->markdown_to_html(
92 title => 'My Document',
93 markdown => $markdown,
94 );
95  
96 =head1 DESCRIPTION
97  
98 This class provides a very simple interface for converting Markdown to a
99 complete HTML document.
100  
101 =head1 METHODS
102  
103 This class provides the following methods:
104  
105 =head2 Markdent::Simple::Document->new
106  
107 Creates a new Markdent::Simple::Document object.
108  
109 =head2 $mds->markdown_to_html( title => $title, markdown => $markdown )
110  
111 This method turns Markdown into HTML. It accepts the following parameters:
112  
113 =over 4
114  
115 =item * title => $title
116  
117 The title of the document. This is required.
118  
119 =item * charset => $charset
120  
121 If provided, a C<< <meta charset="..."> >> tag will be added to the document's
122 C<< <head> >>.
123  
124 =item * language => $language
125  
126 If provided, a "lang" attribute will be added to the document's C<< <html> >>
127 tag.
128  
129 =item * dialects => [...]
130  
131 This can either be a single string or an array ref of strings containing the
132 class names of dialects. This parameter is optional.
133  
134 =back
135  
136 =head1 ROLES
137  
138 This class does the L<Markdent::Role::Simple> role.
139  
140 =head1 BUGS
141  
142 See L<Markdent> for bug reporting details.
143  
144 Bugs may be submitted at L<https://github.com/houseabsolute/Markdent/issues>.
145  
146 I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
147  
148 =head1 SOURCE
149  
150 The source code repository for Markdent can be found at L<https://github.com/houseabsolute/Markdent>.
151  
152 =head1 AUTHOR
153  
154 Dave Rolsky <autarch@urth.org>
155  
156 =head1 COPYRIGHT AND LICENSE
157  
158 This software is copyright (c) 2021 by Dave Rolsky.
159  
160 This is free software; you can redistribute it and/or modify it under
161 the same terms as the Perl 5 programming language system itself.
162  
163 The full text of the license can be found in the
164 F<LICENSE> file included with this distribution.
165  
166 =cut
« Markdent/Handler/HTMLStream/Document.pm ↑ Summary Markdent/CheckedOutput.pm »