| 1 | |||||||||||||||||||||
| 2 | =head1 NAME | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | Templer::Plugin::Markdown - A simple markdown-formatting plugin | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | =cut | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 DESCRIPTION | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | This class implements a formatter plugin for C<templer> which allows | ||||||||||||||||||||
| 11 | pages to be written using markdown. | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | This allows input such as this to be executed: | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =for example begin | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | Title: This is my page | ||||||||||||||||||||
| 18 | format: markdown | ||||||||||||||||||||
| 19 | ---- | ||||||||||||||||||||
| 20 | **Bold** | ||||||||||||||||||||
| 21 | _italic_ | ||||||||||||||||||||
| 22 | Content! | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | =for example end | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =head1 LICENSE | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | This module is free software; you can redistribute it and/or modify it | ||||||||||||||||||||
| 31 | under the terms of either: | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | a) the GNU General Public License as published by the Free Software | ||||||||||||||||||||
| 34 | Foundation; either version 2, or (at your option) any later version, | ||||||||||||||||||||
| 35 | or | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | b) the Perl "Artistic License". | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | =head1 AUTHOR | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | Steve Kemp <steve@steve.org.uk> | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | Copyright (C) 2012-2015 Steve Kemp <steve@steve.org.uk>. | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | This library is free software. You can modify and or distribute it under | ||||||||||||||||||||
| 52 | the same terms as Perl itself. | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =head1 METHODS | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 62 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | package Templer::Plugin::Markdown; | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | =head2 new | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | Constructor. No arguments are supported/expected. | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | sub new | ||||||||||||||||||||
| 75 | 5 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||
| 76 | 5 | my ( $proto, %supplied ) = (@_); | |||||||||||||||||||
| 77 | 5 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 5 | my $self = {}; | |||||||||||||||||||
| 80 | 5 | bless( $self, $class ); | |||||||||||||||||||
| 81 | 5 | return $self; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | =head2 available | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | This plugin is available if we've got the L<Text::Markdown> module. | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =cut | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | sub available | ||||||||||||||||||||
| 92 | 2 | ▶ | { | ||||||||||||||||||
|
Subroutine
available: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 93 | 2 | my $str = "use Text::Markdown;"; | |||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | ## no critic (Eval) | ||||||||||||||||||||
| 96 | 2 | ▶ | eval($str); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 97 | ## use critic | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 2 | ▶ | return ( $@ ? undef : 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | =head2 format | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | Format the given text. | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | sub format | ||||||||||||||||||||
| 110 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
format: called CC=2 SCAR=8.4
Pod
documented
| |||||||||||||||||||||
| 111 | 1 | my ( $self, $str, $data ) = (@_); | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 1 | ▶ | if ( $self->available() ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | { | ||||||||||||||||||||
| 115 | 1 | Text::Markdown::markdown($str); | |||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | else | ||||||||||||||||||||
| 118 | { | ||||||||||||||||||||
| 119 | 0 | warn | |||||||||||||||||||
| 120 | "Markdown formatting disabled as the Text::Markdown module isn't present.\n"; | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 0 | $str; | |||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 11 | Templer::Plugin::Factory->new() | |||||||||||||||||||
| 127 | ->register_formatter( "markdown", "Templer::Plugin::Markdown" ); | ||||||||||||||||||||