| 1 | package Text::Xatena::Node::SuperPre; | ||||||||||
| 2 | |||||||||||
| 3 | 19 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 19 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 19 | ▶ | use base qw(Text::Xatena::Node); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 19 | ▶ | use Text::Xatena::Util; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 19 | ▶ | use constant { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 19 | BEGINNING => qr/^>\|([^|]*)\|$/, | |||||||||
| 9 | ENDOFNODE => qr/^\|\|<$/, | ||||||||||
| 10 | 19 | }; | |||||||||
| 11 | |||||||||||
| 12 | 19 | our $SUPERPRE_CLASS_NAME = 'code'; | |||||||||
| 13 | |||||||||||
| 14 | 418 | ▶ | sub parse { | ||||||||
|
Subroutine
parse: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 15 | 418 | my ($class, $s, $parent, $stack) = @_; | |||||||||
| 16 | 418 | ▶ | if ($s->scan(BEGINNING)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 18 | my $lang = $s->matched->[1]; | |||||||||
| 18 | 18 | my $content = $s->scan_until(ENDOFNODE); | |||||||||
| 19 | 18 | pop @$content; | |||||||||
| 20 | 18 | my $node = $class->new([join("\n", @$content)]); | |||||||||
| 21 | 18 | $node->{lang} = $lang; | |||||||||
| 22 | 18 | push @$parent, $node; | |||||||||
| 23 | 18 | return 1; | |||||||||
| 24 | } | ||||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 17 | ▶ | sub lang { $_[0]->{lang} } | ||||||||
|
Subroutine
lang: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 28 | |||||||||||
| 29 | 17 | ▶ | sub as_html { | ||||||||
|
Subroutine
as_html: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 30 | 17 | my ($self, $context, %opts) = @_; | |||||||||
| 31 | $context->_tmpl(__PACKAGE__, q[ | ||||||||||
| 32 | ? if ($lang) { | ||||||||||
| 33 | <pre class="{{= $class }} {{= "lang-$lang" }}">{{= $content }}</pre> | ||||||||||
| 34 | ? } else { | ||||||||||
| 35 | <pre class="{{= $class }}">{{= $content }}</pre> | ||||||||||
| 36 | ? } | ||||||||||
| 37 | ], { | ||||||||||
| 38 | class => $SUPERPRE_CLASS_NAME, | ||||||||||
| 39 | lang => $self->lang, | ||||||||||
| 40 | 17 | content => escape_html(join "", @{ $self->children }) | |||||||||
| 41 | }); | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 19 | 1; | |||||||||
| 45 | __END__ | ||||||||||