| 1 | package Text::Markdown::Discount; | ||||||||||
| 2 | |||||||||||
| 3 | 8 | ▶ | use 5.008001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 8 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 8 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 8 | require Exporter; | |||||||||
| 10 | |||||||||||
| 11 | 8 | our @ISA = qw(Exporter); | |||||||||
| 12 | |||||||||||
| 13 | # Items to export into callers namespace by default. Note: do not export | ||||||||||
| 14 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||
| 15 | # Do not simply export all your public functions/methods/constants. | ||||||||||
| 16 | |||||||||||
| 17 | # This allows declaration use Text::Markdown::XS ':all'; | ||||||||||
| 18 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||
| 19 | # will save memory. | ||||||||||
| 20 | 8 | our %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||
| 21 | markdown | ||||||||||
| 22 | ) ] ); | ||||||||||
| 23 | |||||||||||
| 24 | 8 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||
| 25 | |||||||||||
| 26 | 8 | our @EXPORT = qw( | |||||||||
| 27 | |||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | 8 | our $VERSION = '0.19'; | |||||||||
| 31 | |||||||||||
| 32 | 8 | require XSLoader; | |||||||||
| 33 | 8 | XSLoader::load('Text::Markdown::Discount', $VERSION); | |||||||||
| 34 | |||||||||||
| 35 | 8 | my %DISCOUNT_OPTION_FLAG = ( | |||||||||
| 36 | normal_listitem => 0x01, | ||||||||||
| 37 | alt_as_title => 0x02, | ||||||||||
| 38 | extended_attr => 0x04, | ||||||||||
| 39 | ); | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub with_html5_tags { | ||||||||
|
Subroutine
with_html5_tags: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 42 | # nop, just for compatibility | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 28 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 46 | 28 | return bless {}, 'Text::Markdown::Discount'; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 54 | ▶ | sub markdown { | ||||||||
|
Subroutine
markdown: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||
| 50 | 54 | my ($self, $text, $flags) = @_; | |||||||||
| 51 | |||||||||||
| 52 | # Detect functional mode, and create an instance for this run.. | ||||||||||
| 53 | 54 | ▶ | unless (ref $self) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 27 | ▶ | if ( $self ne __PACKAGE__ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 27 | my $ob = __PACKAGE__->new(); | |||||||||
| 56 | # $self is text, $text is options | ||||||||||
| 57 | 27 | return $ob->markdown($self, $text, $flags); | |||||||||
| 58 | } | ||||||||||
| 59 | else { | ||||||||||
| 60 | 0 | croak('Calling ' . $self . '->markdown (as a class method) is not supported.'); | |||||||||
| 61 | } | ||||||||||
| 62 | } | ||||||||||
| 63 | 27 | ▶ | if (not defined $flags) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 16 | $flags = MKD_NOHEADER()|MKD_NOPANTS()|MKD_DLEXTRA()|MKD_FENCEDCODE(); | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 27 | ▶ | if (ref $flags) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 8 | ▶ | croak('markdown options must be a hash reference') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | unless ref $flags eq 'HASH'; | ||||||||||
| 70 | |||||||||||
| 71 | 8 | my %options = %{$flags}; | |||||||||
| 72 | 8 | my $legacy_flags = delete $options{flags}; | |||||||||
| 73 | 8 | ▶ | if (not defined $legacy_flags) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 6 | $legacy_flags = MKD_NOHEADER()|MKD_NOPANTS()|MKD_DLEXTRA()|MKD_FENCEDCODE(); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 8 | my $option_flags = 0; | |||||||||
| 78 | 8 | for my $name (keys %DISCOUNT_OPTION_FLAG) { | |||||||||
| 79 | $option_flags |= $DISCOUNT_OPTION_FLAG{$name} | ||||||||||
| 80 | 24 | ▶ | if delete $options{$name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | } | ||||||||||
| 82 | 8 | ▶ | if (keys %options) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 1 | croak('unknown markdown option(s): ' . join(', ', sort keys %options)); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 7 | return _markdown_with_options($text, $legacy_flags, $option_flags); | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 19 | return _markdown($text, $flags); | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | |||||||||||
| 93 | 8 | 1; | |||||||||
| 94 | __END__ | ||||||||||