| 1 | package Text::Xatena::Node::Blockquote; | ||||||||||
| 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 constant { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 19 | BEGINNING => qr/^>(.*?)>$/, | |||||||||
| 8 | ENDOFNODE => qr/^<<$/, | ||||||||||
| 9 | 19 | }; | |||||||||
| 10 | |||||||||||
| 11 | 391 | ▶ | sub parse { | ||||||||
|
Subroutine
parse: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||
| 12 | 391 | my ($class, $s, $parent, $stack) = @_; | |||||||||
| 13 | 391 | ▶ | if ($s->scan(BEGINNING)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | 14 | my $node = $class->new; | |||||||||
| 15 | 14 | $node->{beginning} = $s->matched; | |||||||||
| 16 | 14 | push @$parent, $node; | |||||||||
| 17 | 14 | push @$stack, $node; | |||||||||
| 18 | 14 | return 1; | |||||||||
| 19 | } | ||||||||||
| 20 | 377 | ▶ | if ($s->scan(ENDOFNODE)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 14 | ▶ | pop @$stack while ref($stack->[-1]) eq 'Text::Xatena::Node::Section'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 14 | my $node = pop @$stack; | |||||||||
| 23 | 14 | ▶ | ref($node) eq $class or warn sprintf("syntax error: unmatched syntax got:%s expected:%s", ref($node), $class); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 14 | $node->{endofnode} = $s->matched; | |||||||||
| 25 | 14 | return 1; | |||||||||
| 26 | } | ||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 10 | ▶ | sub as_html { | ||||||||
|
Subroutine
as_html: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 30 | 10 | my ($self, $context, %opts) = @_; | |||||||||
| 31 | |||||||||||
| 32 | 10 | my $text = $self->{beginning}->[1]; | |||||||||
| 33 | |||||||||||
| 34 | 10 | ▶ | my $title = ($text =~ /^http/) ? | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | $context->inline->format('[' . $text . ']'): | ||||||||||
| 36 | $context->inline->format($text); | ||||||||||
| 37 | |||||||||||
| 38 | 10 | my ($uri) = ($title =~ m{(https?://[^\s"':]+)}); | |||||||||
| 39 | |||||||||||
| 40 | 10 | $context->_tmpl(__PACKAGE__, q[ | |||||||||
| 41 | <blockquote {{if ($cite) { }}cite="{{= $cite }}"{{ } }}> | ||||||||||
| 42 | {{= $content }} | ||||||||||
| 43 | {{ if ($title) { }} | ||||||||||
| 44 | <cite>{{= $title }}</cite> | ||||||||||
| 45 | {{ } }} | ||||||||||
| 46 | </blockquote> | ||||||||||
| 47 | ], { | ||||||||||
| 48 | cite => $uri, | ||||||||||
| 49 | title => $title, | ||||||||||
| 50 | content => $self->SUPER::as_html($context, %opts), | ||||||||||
| 51 | }); | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 19 | 1; | |||||||||
| 55 | __END__ | ||||||||||