| blib/lib/Text/Xatena/Node.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 35 | 35 | 100.0 |
| branch | 10 | 10 | 100.0 |
| condition | 2 | 2 | 100.0 |
| subroutine | 8 | 8 | 100.0 |
| pod | 0 | 4 | 0.0 |
| total | 55 | 59 | 93.2 |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package Text::Xatena::Node; | ||||||
| 2 | |||||||
| 3 | 20 | 20 | 106 | use strict; | |||
| 20 | 36 | ||||||
| 20 | 619 | ||||||
| 4 | 20 | 20 | 102 | use warnings; | |||
| 20 | 45 | ||||||
| 20 | 729 | ||||||
| 5 | use overload | ||||||
| 6 | 20 | 212 | '@{}' => \&children, | ||||
| 7 | 20 | 20 | 8449 | fallback => 1; | |||
| 20 | 5612 | ||||||
| 8 | |||||||
| 9 | 20 | 20 | 9648 | use Text::Xatena::Util; | |||
| 20 | 65 | ||||||
| 20 | 155 | ||||||
| 10 | |||||||
| 11 | sub new { | ||||||
| 12 | 243 | 243 | 0 | 421 | my ($class, $children) = @_; | ||
| 13 | 243 | 100 | 1879 | bless { | |||
| 14 | children => $children || [], | ||||||
| 15 | }, $class; | ||||||
| 16 | } | ||||||
| 17 | |||||||
| 18 | 481 | 481 | 0 | 2171 | sub children { $_[0]->{children} }; | ||
| 19 | |||||||
| 20 | sub as_html { | ||||||
| 21 | 160 | 160 | 0 | 347 | my ($self, $context, %opts) = @_; | ||
| 22 | 160 | 242 | my $ret = ""; | ||||
| 23 | |||||||
| 24 | 160 | 495 | my $children = $_[0]->{children}; | ||||
| 25 | 160 | 201 | my @texts; | ||||
| 26 | 160 | 302 | for my $child (@$children) { | ||||
| 27 | 337 | 100 | 830 | if (ref($child)) { | |||
| 28 | 104 | 100 | 436 | $ret .= $self->as_html_paragraph($context, join("\n", @texts), %opts) if join '', @texts; | |||
| 29 | 104 | 197 | @texts = (); | ||||
| 30 | 104 | 474 | $ret .= $child->as_html($context, %opts); | ||||
| 31 | } else { | ||||||
| 32 | 233 | 560 | push @texts, $child; | ||||
| 33 | } | ||||||
| 34 | } | ||||||
| 35 | 160 | 100 | 1099 | $ret .= $self->as_html_paragraph($context, join("\n", @texts), %opts) if join '', @texts; | |||
| 36 | |||||||
| 37 | 160 | 1119 | $ret; | ||||
| 38 | } | ||||||
| 39 | |||||||
| 40 | ## NOT COMPATIBLE WITH Hatena Syntax: Auto br insertation as \n | ||||||
| 41 | sub as_html_paragraph { | ||||||
| 42 | 90 | 90 | 0 | 226 | my ($self, $context, $text, %opts) = @_; | ||
| 43 | 90 | 284 | $text = $context->inline->format($text, $context); | ||||
| 44 | |||||||
| 45 | 90 | 100 | 262 | if ($opts{stopp}) { | |||
| 46 | 11 | 36 | $text; | ||||
| 47 | } else { | ||||||
| 48 | " " . join("", |
||||||
| 49 | map { | ||||||
| 50 | 79 | 100 | 311 | if (/^(\n+)$/) { | |||
| 97 | 258 | ||||||
| 51 | 9 | 46 | "" . (" \n" x (length($1) - 2)) . " "; |
||||
| 52 | } else { | ||||||
| 53 | 88 | 567 | join(" \n", split /\n/); |
||||
| 54 | } | ||||||
| 55 | } | ||||||
| 56 | split(/(\n\n+)/, $text) | ||||||
| 57 | ) . "\n"; | ||||||
| 58 | } | ||||||
| 59 | } | ||||||
| 60 | |||||||
| 61 | 1; | ||||||
| 62 | __END__ |