Skip to content

Commit

Permalink
li なリストに対応(ネスト未対応)
Browse files Browse the repository at this point in the history
  • Loading branch information
yappo committed Feb 17, 2010
1 parent a3b20c8 commit c5347dc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/Acme/Text/Inao.pm
Expand Up @@ -32,6 +32,9 @@ my $inao_syntax = q(
list: tag_start_list list_body(s) all_chars_without_lf tag_end_list { $return = { data => [ $item[0], $item[2], $item[3] ] } }
list_body: all_chars_without_lf ...!tag_end_list LF { $return = { data => [ $item[0], "$item[1]$item[3]" ] } }
ul: li(s) LF { $return = { data => [ @item ] } }
li: LF LI_DOT all_chars_without_lf ...LF { $return = { data => [ $item[0], $item[3] ] } }
paragraph : line(s) { $return = { data => [ @item ] } }
line : brank
| SPACE phrase(s?) LF { $return = { data => [ $item[0], $item[1], $item[2] ] } }
Expand Down Expand Up @@ -87,6 +90,7 @@ my $inao_syntax = q(
MARU : /\x{3002}/
SQUARE : /\x{25a0}/
RHOMBUS : /\x{25c6}/
LI_DOT : /\x{30fb}/
SLASH : /\//
LF : /\n/
Expand Down Expand Up @@ -167,6 +171,16 @@ sub _to_html_list_body {
$text;
}

sub _to_html_ul {
my($self, $items) = @_;
join '', '<UL>', $self->stack_walker($items), '</UL>', "\n";
}

sub _to_html_li {
my($self, $text) = @_;
join '', '<LI>', $text, '</LI>';
}

sub _to_html_phrase {
my($self, $items) = @_;
join '', $self->stack_walker($items);
Expand Down
33 changes: 33 additions & 0 deletions t/to_html/li.t
@@ -0,0 +1,33 @@
use strict;
use warnings;
use utf8;
use Test::More;
use Acme::Text::Inao;

my $square = "\x{25a0}";
my $rhombus = "\x{25c6}";
my $li_dot = "\x{30fb}";

sub run_tests {
my($text, $expected) = @_;
}

my $inao = Acme::Text::Inao->new( parser_start => 'ul' );

subtest 'normal' => sub {
my $text = "\n${li_dot}リストだよ\n";
my $expected = "<UL><LI>リストだよ</LI></UL>\n";
is $inao->from_inao($text)->to_html, $expected;

$text = "\n${li_dot}リスト1だよ\n${li_dot}リスト2だよ\n";
$expected = "<UL><LI>リスト1だよ</LI><LI>リスト2だよ</LI></UL>\n";
is $inao->from_inao($text)->to_html, $expected;

$text = "\n${li_dot}リスト1だよ\n${li_dot}${rhombus}b/${rhombus}タグ記号を含めるよ${rhombus}/b${rhombus}\n${li_dot}リスト3だよ\n";
$expected = "<UL><LI>リスト1だよ</LI><LI>${rhombus}b/${rhombus}タグ記号を含めるよ${rhombus}/b${rhombus}</LI><LI>リスト3だよ</LI></UL>\n";
is $inao->from_inao($text)->to_html, $expected;

done_testing;
};

done_testing;

0 comments on commit c5347dc

Please sign in to comment.