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