File: markdown_to_html.pm

package info (click to toggle)
libcatmandu-markdown-perl 0.011-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 120 kB
  • sloc: perl: 91; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 923 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package Catmandu::Fix::markdown_to_html;
use Catmandu::Sane;
use Moo;
use Catmandu::Util qw(:is :check);
use Text::Markdown::Discount;

our $VERSION = "0.011";

has field => (
    is => 'ro' ,
    required => 1
);
around BUILDARGS => sub {
    my($orig,$class,$field) = @_;
    $orig->($class,field => $field);
};

sub emit {
    my($self,$fixer) = @_;

    my $perl = "";

    my $field = $fixer->split_path($self->field());
    my $key = pop @$field;

    $perl .= $fixer->emit_walk_path($fixer->var,$field,sub{
        my $var = shift;
        $fixer->emit_get_key($var,$key, sub {
            my $var = shift;
            "${var} = is_string(${var}) ? Text::Markdown::Discount::markdown(${var}) : \"\";";
        });
    });

    $perl;
}

=head1 NAME

Catmandu::Fix::markdown_to_html - converts markdown to html elements

=head1 SYNOPSIS

markdown_to_html('text_markdown')

=head1 SEE ALSO

L<Catmandu::Fix>

=cut

1;