Permalink
Browse files

見出しに対応

  • Loading branch information...
yappo committed Feb 17, 2010
1 parent c5347dc commit 7ab06f50f00f9348b90b92eb98ddea2f716ab5fc
Showing with 43 additions and 29 deletions.
  1. +23 −1 lib/Acme/Text/Inao.pm
  2. +20 −28 t/to_html/head.t
View
@@ -29,13 +29,18 @@ my $_inao_syntax = q(
my $inao_syntax = q(
+ head1: LF SQUARE ...!SQUARE all_chars_without_lf LF { $return = { data => [ $item[0], $item[4] ] } }
+ head2: LF SQUARE SQUARE ...!SQUARE all_chars_without_lf LF { $return = { data => [ $item[0], $item[5] ] } }
+ head3: LF SQUARE SQUARE SQUARE ...!SQUARE all_chars_without_lf LF { $return = { data => [ $item[0], $item[6] ] } }
+ column_head: LF SQUARE SQUARE SQUARE SQUARE ...!SQUARE all_chars_without_lf LF { $return = { data => [ $item[0], $item[7] ] } }
+
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 ] } }
+ paragraph : line(s) { $return = { data => [ $item[0], $item[2] ] } }
line : brank
| SPACE phrase(s?) LF { $return = { data => [ $item[0], $item[1], $item[2] ] } }
brank : LF { $return = { data => [ @item ] } }
@@ -162,6 +167,23 @@ sub _to_html_line {
join '', '<P>', $prefix, $self->stack_walker($items), '</P>', "\n";
}
+sub _to_html_head1 {
+ my($self, $text) = @_;
+ join '', '<H1>', $text, '</H1>', "\n";
+}
+sub _to_html_head2 {
+ my($self, $text) = @_;
+ join '', '<H2>', $text, '</H2>', "\n";
+}
+sub _to_html_head3 {
+ my($self, $text) = @_;
+ join '', '<H3>', $text, '</H3>', "\n";
+}
+sub _to_html_column_head {
+ my($self, $text) = @_;
+ join '', '<H1>', $text, '</H1>', "\n";
+}
+
sub _to_html_list {
my($self, $items, $text) = @_;
join '', '<PRE>', $self->stack_walker($items), $text, '</PRE>', "\n";
View
@@ -6,34 +6,26 @@ use Acme::Text::Inao;
my $square = "\x{25a0}";
-sub run_tests {
- my($text, $expected) = @_;
-}
-
-my $text = "
-${square}foo
-text1
-${square}${square}bar
-text2
-${square}${square}${square}baz
-text3
-${square}${square}${square}${square}column
-column
-${square}foo2
-text12
-";
-my $expected = "
-<H1>foo</H1>
-<P>text1</P>
-<H2>bar</H2>
-<P>text2</P>
-<H3>baz</H3>
-<P>text3</P>
-<H4>column</H4>
-<P>column</P>
-";
-my $inao = Acme::Text::Inao->new->parse($text);
-#is $inao->to_html, $expected, $expected;
+
+my $inao = Acme::Text::Inao->new( parser_start => 'head1' );
+my $text = "\n${square}${square}イトル${square}\n";
+my $expected = "<H1>タ${square}イトル${square}</H1>\n";
+is $inao->from_inao($text)->to_html, $expected;
+
+$inao = Acme::Text::Inao->new( parser_start => 'head2' );
+$text = "\n${square}${square}${square}イトル${square}\n";
+$expected = "<H2>タ${square}イトル${square}</H2>\n";
+is $inao->from_inao($text)->to_html, $expected;
+
+$inao = Acme::Text::Inao->new( parser_start => 'head3' );
+$text = "\n${square}${square}${square}${square}イトル${square}\n";
+$expected = "<H3>タ${square}イトル${square}</H3>\n";
+is $inao->from_inao($text)->to_html, $expected;
+
+$inao = Acme::Text::Inao->new( parser_start => 'column_head' );
+$text = "\n${square}${square}${square}${square}コラム${square}タイトル\n";
+$expected = "<H1>コラム${square}タイトル</H1>\n";
+is $inao->from_inao($text)->to_html, $expected;
done_testing;

0 comments on commit 7ab06f5

Please sign in to comment.