root/trunk/plagger/lib/Plagger/Plugin/Filter/Markdown.pm

Revision 712 (checked in by s_nobu, 14 years ago)

add Filter::Markdown

Line 
1 package Plagger::Plugin::Filter::Markdown;
2 use strict;
3 use warnings;
4 use base qw( Plagger::Plugin );
5
6 our $VERSION = 0.01;
7
8 use Text::Markdown 'markdown';
9
10 sub register {
11     my($self, $context) = @_;
12     $context->register_hook(
13         $self,
14         'update.entry.fixup' => \&filter,
15     );
16 }
17
18 sub filter {
19     my($self, $context, $args) = @_;
20     my $cfg = $self->conf;
21     my $entry = $args->{entry};
22     my $html = markdown($entry->body, {
23       $cfg->{empty_element_suffix} || ' />',
24       $cfg->{tab_width} || '4',
25     } );
26     $entry->body($html);
27 }
28
29 1;
30
31 __END__
32
33 =head1 NAME
34
35 Plagger::Plugin::Filter::Markdown - Text formatting filter with Markdown
36
37 =head1 SYNOPSIS
38
39   - module: Filter::Markdown
40     config:
41       empty_element_suffix: ' />'
42       tab_width: '4'
43
44 =head1 DESCRIPTION
45
46 This filter allows you to format the content with Markdown. You
47 can get html string from simple text with syntax like Wiki.
48
49 =head1 CONFIG
50
51 Any configurations will be passed to the constructor of
52 Text::Markdown. See L<Text::Markdown> in detail.
53
54 =head1 AUTHOR
55
56 Nobuhito Sato
57
58 =head1 SEE ALSO
59
60 L<Plagger>, L<Text::Markdown>
61
62 =cut
Note: See TracBrowser for help on using the browser.