aozora2html 0.7.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/bin/aozora2html +3 -50
  3. data/lib/aozora2html.rb +0 -4
  4. data/lib/aozora2html/accent_parser.rb +91 -0
  5. data/lib/aozora2html/error.rb +16 -0
  6. data/lib/aozora2html/header.rb +139 -0
  7. data/lib/aozora2html/i18n.rb +17 -0
  8. data/lib/aozora2html/ruby_buffer.rb +81 -0
  9. data/lib/aozora2html/style_stack.rb +27 -0
  10. data/lib/aozora2html/tag.rb +55 -0
  11. data/lib/aozora2html/tag/accent.rb +39 -0
  12. data/lib/aozora2html/tag/block.rb +19 -0
  13. data/lib/aozora2html/tag/chitsuki.rb +15 -0
  14. data/lib/aozora2html/tag/dakuten_katakana.rb +23 -0
  15. data/lib/aozora2html/tag/decorate.rb +18 -0
  16. data/lib/aozora2html/tag/dir.rb +15 -0
  17. data/lib/aozora2html/tag/editor_note.rb +16 -0
  18. data/lib/aozora2html/tag/embed_gaiji.rb +48 -0
  19. data/lib/aozora2html/tag/font_size.rb +17 -0
  20. data/lib/aozora2html/tag/gaiji.rb +11 -0
  21. data/lib/aozora2html/tag/img.rb +21 -0
  22. data/lib/aozora2html/tag/indent.rb +8 -0
  23. data/lib/aozora2html/tag/inline.rb +13 -0
  24. data/lib/aozora2html/tag/inline_caption.rb +15 -0
  25. data/lib/aozora2html/tag/inline_font_size.rb +18 -0
  26. data/lib/aozora2html/tag/inline_keigakomi.rb +15 -0
  27. data/lib/aozora2html/tag/inline_yokogumi.rb +16 -0
  28. data/lib/aozora2html/tag/jisage.rb +15 -0
  29. data/lib/aozora2html/tag/jizume.rb +16 -0
  30. data/lib/aozora2html/tag/kaeriten.rb +15 -0
  31. data/lib/aozora2html/tag/keigakomi.rb +13 -0
  32. data/lib/aozora2html/tag/kunten.rb +12 -0
  33. data/lib/aozora2html/tag/midashi.rb +18 -0
  34. data/lib/aozora2html/tag/multiline.rb +6 -0
  35. data/lib/aozora2html/tag/multiline_caption.rb +15 -0
  36. data/lib/aozora2html/tag/multiline_chitsuki.rb +8 -0
  37. data/lib/aozora2html/tag/multiline_jisage.rb +8 -0
  38. data/lib/aozora2html/tag/multiline_midashi.rb +22 -0
  39. data/lib/aozora2html/tag/multiline_style.rb +17 -0
  40. data/lib/aozora2html/tag/multiline_yokogumi.rb +17 -0
  41. data/lib/aozora2html/tag/okurigana.rb +15 -0
  42. data/lib/aozora2html/tag/oneline_chitsuki.rb +9 -0
  43. data/lib/aozora2html/tag/oneline_indent.rb +2 -0
  44. data/lib/aozora2html/tag/oneline_jisage.rb +7 -0
  45. data/lib/aozora2html/tag/reference_mentioned.rb +46 -0
  46. data/lib/aozora2html/tag/ruby.rb +98 -0
  47. data/lib/aozora2html/tag/un_embed_gaiji.rb +24 -0
  48. data/lib/aozora2html/tag_parser.rb +53 -0
  49. data/lib/aozora2html/utils.rb +82 -0
  50. data/lib/aozora2html/version.rb +1 -1
  51. data/lib/aozora2html/yaml_loader.rb +31 -0
  52. data/lib/extensions.rb +31 -0
  53. data/lib/jstream.rb +68 -0
  54. data/lib/t2hs.rb +485 -1490
  55. data/test/test_aozora2html.rb +161 -57
  56. data/test/test_aozora_accent_parser.rb +13 -2
  57. data/test/test_command_parse.rb +213 -0
  58. data/test/test_dakuten_katakana_tag.rb +5 -4
  59. data/test/test_decorate_tag.rb +5 -4
  60. data/test/test_dir_tag.rb +5 -4
  61. data/test/test_editor_note_tag.rb +4 -4
  62. data/test/test_exception.rb +4 -4
  63. data/test/test_font_size_tag.rb +8 -7
  64. data/test/test_gaiji_tag.rb +14 -7
  65. data/test/test_header.rb +60 -0
  66. data/test/test_img_tag.rb +5 -4
  67. data/test/test_inline_caption_tag.rb +5 -4
  68. data/test/test_inline_font_size_tag.rb +7 -6
  69. data/test/test_inline_keigakomi_tag.rb +5 -4
  70. data/test/test_inline_yokogumi_tag.rb +5 -4
  71. data/test/test_jizume_tag.rb +7 -6
  72. data/test/test_jstream.rb +5 -5
  73. data/test/test_kaeriten_tag.rb +5 -4
  74. data/test/test_keigakomi_tag.rb +8 -7
  75. data/test/test_midashi_tag.rb +38 -0
  76. data/test/test_multiline_caption_tag.rb +7 -6
  77. data/test/test_multiline_midashi_tag.rb +12 -11
  78. data/test/test_multiline_style_tag.rb +7 -6
  79. data/test/test_multiline_yokogumi_tag.rb +7 -6
  80. data/test/test_okurigana_tag.rb +5 -4
  81. data/test/test_ruby_parse.rb +116 -0
  82. data/test/test_ruby_tag.rb +5 -4
  83. data/test/test_tag_parser.rb +10 -10
  84. data/yml/accent_table.yml +240 -0
  85. data/yml/command_table.yml +61 -0
  86. data/yml/jis2ucs.yml +11234 -0
  87. metadata +63 -6
  88. data/lib/accent_tag.rb +0 -23
  89. data/lib/aozora2html/jis2ucs.rb +0 -11237
  90. data/lib/embed_gaiji_tag.rb +0 -34
@@ -3,24 +3,25 @@ require 'aozora2html'
3
3
 
4
4
  class KeigakomiTagTest < Test::Unit::TestCase
5
5
  def setup
6
- stub(@parser).block_allowed_context?{true}
6
+ @parser = Object.new
7
+ stub(@parser).block_allowed_context?{true}
7
8
  end
8
9
 
9
10
  def test_keigakomi_new
10
- tag = Keigakomi_tag.new(@parser,2)
11
- assert_equal Keigakomi_tag, tag.class
12
- assert_equal true, tag.kind_of?(Block_tag)
13
- assert_equal true, tag.kind_of?(Multiline_tag)
11
+ tag = Aozora2Html::Tag::Keigakomi.new(@parser,2)
12
+ assert_equal Aozora2Html::Tag::Keigakomi, tag.class
13
+ assert_equal true, tag.kind_of?(Aozora2Html::Tag::Block)
14
+ assert_equal true, tag.kind_of?(Aozora2Html::Tag::Multiline)
14
15
  end
15
16
 
16
17
  def test_to_s
17
- tag = Keigakomi_tag.new(@parser)
18
+ tag = Aozora2Html::Tag::Keigakomi.new(@parser)
18
19
  assert_equal "<div class=\"keigakomi\" style=\"border: solid 1px\">", tag.to_s
19
20
  assert_equal "</div>", tag.close_tag
20
21
  end
21
22
 
22
23
  def test_to_s2
23
- tag = Keigakomi_tag.new(@parser,2)
24
+ tag = Aozora2Html::Tag::Keigakomi.new(@parser,2)
24
25
  assert_equal "<div class=\"keigakomi\" style=\"border: solid 2px\">", tag.to_s
25
26
  assert_equal "</div>", tag.close_tag
26
27
  end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+ require 'aozora2html'
4
+
5
+ class MidashiTagTest < Test::Unit::TestCase
6
+ def setup
7
+ @parser = Object.new
8
+ stub(@parser).block_allowed_context?{true}
9
+ stub(@parser).new_midashi_id{2}
10
+ end
11
+
12
+ def test_midashi_new
13
+ tag = Aozora2Html::Tag::Midashi.new(@parser, "テスト見出し".encode("shift_jis"), "小".encode("shift_jis"), :normal)
14
+ assert_equal Aozora2Html::Tag::Midashi, tag.class
15
+ assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
16
+ end
17
+
18
+ def test_to_s
19
+ tag = Aozora2Html::Tag::Midashi.new(@parser, "テスト見出し".encode("shift_jis"), "小".encode("shift_jis"), :normal)
20
+ assert_equal "<h5 class=\"ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">"+"テスト見出し".encode("shift_jis")+"</a></h5>", tag.to_s
21
+ end
22
+
23
+ def test_to_s_mado
24
+ tag = Aozora2Html::Tag::Midashi.new(@parser, "テスト見出し".encode("shift_jis"), "小".encode("shift_jis"), :mado)
25
+ assert_equal "<h5 class=\"mado-ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">"+"テスト見出し".encode("shift_jis")+"</a></h5>", tag.to_s
26
+ end
27
+
28
+ def test_undeined_midashi
29
+ begin
30
+ Aozora2Html::Tag::Midashi.new(@parser, "テスト見出し".encode("shift_jis"), "あ".encode("shift_jis"), :normal)
31
+ rescue Aozora2Html::Error => e
32
+ assert_equal e.message(123).encode("utf-8"), "エラー(123行目):未定義な見出しです. \r\n処理を停止します"
33
+ end
34
+ end
35
+
36
+ def teardown
37
+ end
38
+ end
@@ -3,18 +3,19 @@ require 'aozora2html'
3
3
 
4
4
  class MultilineCaptionTagTest < Test::Unit::TestCase
5
5
  def setup
6
- stub(@parser).block_allowed_context?{true}
6
+ @parser = Object.new
7
+ stub(@parser).block_allowed_context?{true}
7
8
  end
8
9
 
9
10
  def test_multiline_caption_new
10
- tag = Multiline_caption_tag.new(@parser0)
11
- assert_equal Multiline_caption_tag, tag.class
12
- assert_equal true, tag.kind_of?(Block_tag)
13
- assert_equal true, tag.kind_of?(Multiline_tag)
11
+ tag = Aozora2Html::Tag::MultilineCaption.new(@parser)
12
+ assert_equal Aozora2Html::Tag::MultilineCaption, tag.class
13
+ assert_equal true, tag.kind_of?(Aozora2Html::Tag::Block)
14
+ assert_equal true, tag.kind_of?(Aozora2Html::Tag::Multiline)
14
15
  end
15
16
 
16
17
  def test_to_s
17
- tag = Multiline_caption_tag.new(@parser)
18
+ tag = Aozora2Html::Tag::MultilineCaption.new(@parser)
18
19
  assert_equal "<div class=\"caption\">", tag.to_s
19
20
  assert_equal "</div>", tag.close_tag
20
21
  end
@@ -4,47 +4,48 @@ require 'aozora2html'
4
4
 
5
5
  class MultilineMidashiTagTest < Test::Unit::TestCase
6
6
  def setup
7
+ @parser = Object.new
7
8
  stub(@parser).block_allowed_context?{true}
8
9
  stub(@parser).new_midashi_id{2}
9
10
  end
10
11
 
11
12
  def test_multiline_midashi_new
12
- tag = Multiline_midashi_tag.new(@parser,"小".encode("shift_jis"),:normal)
13
- assert_equal Multiline_midashi_tag, tag.class
14
- assert_equal true, tag.kind_of?(Block_tag)
15
- assert_equal true, tag.kind_of?(Multiline_tag)
13
+ tag = Aozora2Html::Tag::MultilineMidashi.new(@parser,"小".encode("shift_jis"),:normal)
14
+ assert_equal Aozora2Html::Tag::MultilineMidashi, tag.class
15
+ assert_equal true, tag.kind_of?(Aozora2Html::Tag::Block)
16
+ assert_equal true, tag.kind_of?(Aozora2Html::Tag::Multiline)
16
17
  end
17
18
 
18
19
  def test_to_s
19
- tag = Multiline_midashi_tag.new(@parser,"小".encode("shift_jis"),:normal)
20
+ tag = Aozora2Html::Tag::MultilineMidashi.new(@parser,"小".encode("shift_jis"),:normal)
20
21
  assert_equal "<h5 class=\"ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">", tag.to_s
21
22
  assert_equal "</a></h5>", tag.close_tag
22
23
  end
23
24
 
24
25
  def test_to_s_chu
25
- tag = Multiline_midashi_tag.new(@parser,"中".encode("shift_jis"),:dogyo)
26
+ tag = Aozora2Html::Tag::MultilineMidashi.new(@parser,"中".encode("shift_jis"),:dogyo)
26
27
  assert_equal "<h4 class=\"dogyo-naka-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">", tag.to_s
27
28
  assert_equal "</a></h4>", tag.close_tag
28
29
  end
29
30
 
30
31
  def test_to_s_dai
31
- tag = Multiline_midashi_tag.new(@parser,"大".encode("shift_jis"),:mado)
32
+ tag = Aozora2Html::Tag::MultilineMidashi.new(@parser,"大".encode("shift_jis"),:mado)
32
33
  assert_equal "<h3 class=\"mado-o-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">", tag.to_s
33
34
  assert_equal "</a></h3>", tag.close_tag
34
35
  end
35
36
 
36
37
  def test_undeined_midashi
37
38
  begin
38
- Multiline_midashi_tag.new(@parser,"あ".encode("shift_jis"),:mado)
39
- rescue Aozora_Error => e
39
+ Aozora2Html::Tag::MultilineMidashi.new(@parser,"あ".encode("shift_jis"),:mado)
40
+ rescue Aozora2Html::Error => e
40
41
  assert_equal e.message(123).encode("utf-8"), "エラー(123行目):未定義な見出しです. \r\n処理を停止します"
41
42
  end
42
43
  end
43
44
 
44
45
  def test_undeined_midashi2
45
46
  begin
46
- Multiline_midashi_tag.new(@parser,"大".encode("shift_jis"),:madoo)
47
- rescue Aozora_Error => e
47
+ Aozora2Html::Tag::MultilineMidashi.new(@parser,"大".encode("shift_jis"),:madoo)
48
+ rescue Aozora2Html::Error => e
48
49
  assert_equal e.message(123).encode("utf-8"), "エラー(123行目):未定義な見出しです. \r\n処理を停止します"
49
50
  end
50
51
  end
@@ -3,18 +3,19 @@ require 'aozora2html'
3
3
 
4
4
  class MultilineStyleTagTest < Test::Unit::TestCase
5
5
  def setup
6
- stub(@parser).block_allowed_context?{true}
6
+ @parser = Object.new
7
+ stub(@parser).block_allowed_context?{true}
7
8
  end
8
9
 
9
10
  def test_multiline_style_new
10
- tag = Multiline_style_tag.new(@parser,"style1")
11
- assert_equal Multiline_style_tag, tag.class
12
- assert_equal true, tag.kind_of?(Block_tag)
13
- assert_equal true, tag.kind_of?(Multiline_tag)
11
+ tag = Aozora2Html::Tag::MultilineStyle.new(@parser,"style1")
12
+ assert_equal Aozora2Html::Tag::MultilineStyle, tag.class
13
+ assert_equal true, tag.kind_of?(Aozora2Html::Tag::Block)
14
+ assert_equal true, tag.kind_of?(Aozora2Html::Tag::Multiline)
14
15
  end
15
16
 
16
17
  def test_to_s
17
- tag = Multiline_style_tag.new(@parser,"s1")
18
+ tag = Aozora2Html::Tag::MultilineStyle.new(@parser,"s1")
18
19
  assert_equal "<div class=\"s1\">", tag.to_s
19
20
  assert_equal "</div>", tag.close_tag
20
21
  end
@@ -3,18 +3,19 @@ require 'aozora2html'
3
3
 
4
4
  class MultilineYokogumiTagTest < Test::Unit::TestCase
5
5
  def setup
6
- stub(@parser).block_allowed_context?{true}
6
+ @parser = Object.new
7
+ stub(@parser).block_allowed_context?{true}
7
8
  end
8
9
 
9
10
  def test_multiline_yokogumi_new
10
- tag = Multiline_yokogumi_tag.new(@parser0)
11
- assert_equal Multiline_yokogumi_tag, tag.class
12
- assert_equal true, tag.kind_of?(Block_tag)
13
- assert_equal true, tag.kind_of?(Multiline_tag)
11
+ tag = Aozora2Html::Tag::MultilineYokogumi.new(@parser)
12
+ assert_equal Aozora2Html::Tag::MultilineYokogumi, tag.class
13
+ assert_equal true, tag.kind_of?(Aozora2Html::Tag::Block)
14
+ assert_equal true, tag.kind_of?(Aozora2Html::Tag::Multiline)
14
15
  end
15
16
 
16
17
  def test_to_s
17
- tag = Multiline_yokogumi_tag.new(@parser)
18
+ tag = Aozora2Html::Tag::MultilineYokogumi.new(@parser)
18
19
  assert_equal "<div class=\"yokogumi\">", tag.to_s
19
20
  assert_equal "</div>", tag.close_tag
20
21
  end
@@ -4,17 +4,18 @@ require 'aozora2html'
4
4
 
5
5
  class OkuriganaTagTest < Test::Unit::TestCase
6
6
  def setup
7
+ @parser = Object.new
7
8
  stub(@parser).block_allowed_context?{true}
8
9
  end
9
10
 
10
11
  def test_okurigana_new
11
- tag = Okurigana_tag.new(@parser,"aaa")
12
- assert_equal Okurigana_tag, tag.class
13
- assert_equal true, tag.kind_of?(Inline_tag)
12
+ tag = Aozora2Html::Tag::Okurigana.new(@parser,"aaa")
13
+ assert_equal Aozora2Html::Tag::Okurigana, tag.class
14
+ assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
14
15
  end
15
16
 
16
17
  def test_to_s
17
- tag = Okurigana_tag.new(@parser,"テスト".encode("shift_jis"))
18
+ tag = Aozora2Html::Tag::Okurigana.new(@parser,"テスト".encode("shift_jis"))
18
19
  assert_equal "<sup class=\"okurigana\">テスト</sup>", tag.to_s.encode("utf-8")
19
20
  end
20
21
 
@@ -0,0 +1,116 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+ require 'aozora2html'
4
+
5
+ class RubyParseTest < Test::Unit::TestCase
6
+ def setup
7
+ end
8
+
9
+ def test_parse_ruby1
10
+ src = "青空文庫《あおぞらぶんこ》\r\n"
11
+ parsed = parse_text(src)
12
+ expected = "<ruby><rb>青空文庫</rb><rp>(</rp><rt>あおぞらぶんこ</rt><rp>)</rp></ruby><br />\r\n"
13
+ assert_equal expected, parsed
14
+ end
15
+
16
+ def test_parse_ruby1b
17
+ src = "身装《みなり》\r\n"
18
+ parsed = parse_text(src)
19
+ expected = "<ruby><rb>身装</rb><rp>(</rp><rt>みなり</rt><rp>)</rp></ruby><br />\r\n"
20
+ assert_equal expected, parsed
21
+ end
22
+
23
+ def test_parse_ruby2
24
+ src = "霧の|ロンドン警視庁《スコットランドヤード》\r\n"
25
+ parsed = parse_text(src)
26
+ expected = "霧の<ruby><rb>ロンドン警視庁</rb><rp>(</rp><rt>スコットランドヤード</rt><rp>)</rp></ruby><br />\r\n"
27
+ assert_equal expected, parsed
28
+ end
29
+
30
+ def test_parse_ruby2b
31
+ src = "いかにも最|猛者《もさ》のように\r\n"
32
+ parsed = parse_text(src)
33
+ expected = "いかにも最<ruby><rb>猛者</rb><rp>(</rp><rt>もさ</rt><rp>)</rp></ruby>のように<br />\r\n"
34
+ assert_equal expected, parsed
35
+ end
36
+
37
+ def test_parse_ruby3
38
+ src = "〆切《しめきり》を逃れるために、市ヶ谷《いちがや》から転々《てんてん》と、居を移した。\r\n"
39
+ parsed = parse_text(src)
40
+ expected = "<ruby><rb>〆切</rb><rp>(</rp><rt>しめきり</rt><rp>)</rp></ruby>を逃れるために、<ruby><rb>市ヶ谷</rb><rp>(</rp><rt>いちがや</rt><rp>)</rp></ruby>から<ruby><rb>転々</rb><rp>(</rp><rt>てんてん</rt><rp>)</rp></ruby>と、居を移した。<br />\r\n"
41
+ assert_equal expected, parsed
42
+ end
43
+
44
+ def test_parse_ruby4
45
+ src = "水鉢を置いた※[#「木+靈」、第3水準1-86-29]子窓《れんじまど》の下には\r\n"
46
+ parsed = parse_text(src)
47
+ expected = "水鉢を置いた<ruby><rb><img src=\"../../../gaiji/1-86/1-86-29.png\" alt=\"※(「木+靈」、第3水準1-86-29)\" class=\"gaiji\" />子窓</rb><rp>(</rp><rt>れんじまど</rt><rp>)</rp></ruby>の下には<br />\r\n"
48
+ assert_equal expected, parsed
49
+ end
50
+
51
+ def test_parse_ruby5
52
+ src = "それが彼の 〔E'tude〕《エチュード》 だった。\r\n"
53
+ parsed = parse_text(src)
54
+ expected = "それが彼の <ruby><rb><img src=\"../../../gaiji/1-09/1-09-32.png\" alt=\"※(アキュートアクセント付きE)\" class=\"gaiji\" />tude</rb><rp>(</rp><rt>エチュード</rt><rp>)</rp></ruby> だった。<br />\r\n"
55
+ assert_equal expected, parsed
56
+ end
57
+
58
+ def test_parse_ruby6
59
+ src = "青空文庫[#「青空文庫」の左に「あおぞらぶんこ」のルビ]\r\n"
60
+ parsed = parse_text(src)
61
+ expected = "青空文庫<span class=\"notes\">[#「青空文庫」の左に「あおぞらぶんこ」のルビ]</span><br />\r\n"
62
+ assert_equal expected, parsed
63
+ end
64
+
65
+ def test_parse_ruby7
66
+ src = "青空文庫《あおぞらぶんこ》[#「青空文庫」の左に「aozora bunko」のルビ]\r\n"
67
+ parsed = parse_text(src)
68
+ expected = %Q|<ruby><rb>青空文庫</rb><rp>(</rp><rt>あおぞらぶんこ</rt><rp>)</rp></ruby><span class="notes">[#「青空文庫」の左に「aozora bunko」のルビ]</span><br />\r\n|
69
+ assert_equal expected, parsed
70
+ end
71
+
72
+ def test_parse_ruby8
73
+ src = "大空文庫[#「大空文庫」に「ママ」の注記]\r\n"
74
+ parsed = parse_text(src)
75
+ expected = %Q|<ruby><rb>大空文庫</rb><rp>(</rp><rt>ママ</rt><rp>)</rp></ruby><br />\r\n|
76
+ assert_equal expected, parsed
77
+ end
78
+
79
+ def test_parse_ruby9
80
+ src = "大空文庫[#「大空文庫」の左に「ママ」の注記]\r\n"
81
+ parsed = parse_text(src)
82
+ expected = %Q|大空文庫<span class="notes">[#「大空文庫」の左に「ママ」の注記]</span><br />\r\n|
83
+ assert_equal expected, parsed
84
+ end
85
+
86
+ def test_parse_ruby10
87
+ src = "大空文庫《あおぞらぶんこ》[#「大空文庫」の左に「ママ」の注記]\r\n"
88
+ parsed = parse_text(src)
89
+ expected = %Q|<ruby><rb>大空文庫</rb><rp>(</rp><rt>あおぞらぶんこ</rt><rp>)</rp></ruby><span class="notes">[#「大空文庫」の左に「ママ」の注記]</span><br />\r\n|
90
+ assert_equal expected, parsed
91
+ end
92
+
93
+ def test_parse_ruby11
94
+ src = "大空文庫《あおぞらぶんこ》[#「大空文庫」の左に「ママ」の注記]\r\n"
95
+ parsed = parse_text(src)
96
+ expected = %Q|<ruby><rb>大空文庫</rb><rp>(</rp><rt>あおぞらぶんこ</rt><rp>)</rp></ruby><span class="notes">[#「大空文庫」の左に「ママ」の注記]</span><br />\r\n|
97
+ assert_equal expected, parsed
98
+ end
99
+
100
+ def parse_text(input_text)
101
+ input = StringIO.new(input_text.encode("shift_jis"))
102
+ output = StringIO.new
103
+ parser = Aozora2Html.new(input, output)
104
+ parser.instance_eval{@section=:tail}
105
+ catch(:terminate) do
106
+ loop do
107
+ parser.parse
108
+ end
109
+ end
110
+
111
+ output.string.encode("utf-8")
112
+ end
113
+
114
+ end
115
+
116
+
@@ -4,17 +4,18 @@ require 'aozora2html'
4
4
 
5
5
  class RubyTagTest < Test::Unit::TestCase
6
6
  def setup
7
+ @parser = Object.new
7
8
  stub(@parser).block_allowed_context?{true}
8
9
  end
9
10
 
10
11
  def test_ruby_new
11
- tag = Ruby_tag.new(@parser,"aaa".encode("shift_jis"),"bb")
12
- assert_equal Ruby_tag, tag.class
13
- assert_equal true, tag.kind_of?(Inline_tag)
12
+ tag = Aozora2Html::Tag::Ruby.new(@parser,"aaa".encode("shift_jis"),"bb")
13
+ assert_equal Aozora2Html::Tag::Ruby, tag.class
14
+ assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
14
15
  end
15
16
 
16
17
  def test_to_s
17
- tag = Ruby_tag.new(@parser,"テスト".encode("shift_jis"),"てすと".encode("shift_jis"))
18
+ tag = Aozora2Html::Tag::Ruby.new(@parser,"テスト".encode("shift_jis"),"てすと".encode("shift_jis"))
18
19
  assert_equal "<ruby><rb>テスト</rb><rp>(</rp><rt>てすと</rt><rp>)</rp></ruby>", tag.to_s.encode("utf-8")
19
20
  end
20
21
 
@@ -6,14 +6,14 @@ require 'tmpdir'
6
6
 
7
7
  class TagParserTest < Test::Unit::TestCase
8
8
  def setup
9
- @jisx0213 = Embed_Gaiji_tag.use_jisx0213
9
+ @jisx0213 = Aozora2Html::Tag::EmbedGaiji.use_jisx0213
10
10
  end
11
11
 
12
12
  def test_parse_katakana
13
13
  str = "テスト!あいうえお\r\n".encode("shift_jis")
14
14
  strio = StringIO.new(str)
15
15
  stream = Jstream.new(strio)
16
- command, raw = Aozora_tag_parser.new(stream,"!".encode("shift_jis"),{},[]).process
16
+ command, _raw = Aozora2Html::TagParser.new(stream,"!".encode("shift_jis"),{},[]).process
17
17
  expected = "テスト"
18
18
  assert_equal expected, command.to_s.encode("utf-8")
19
19
  end
@@ -22,7 +22,7 @@ class TagParserTest < Test::Unit::TestCase
22
22
  str = "腹がへっても[#「腹がへっても」に傍点]、ひもじゅうない[#「ひもじゅうない」に傍点]とかぶりを振っている…\r\n".encode("shift_jis")
23
23
  strio = StringIO.new(str)
24
24
  stream = Jstream.new(strio)
25
- command, raw = Aozora_tag_parser.new(stream,"…".encode("shift_jis"),{},[]).process
25
+ command, _raw = Aozora2Html::TagParser.new(stream,"…".encode("shift_jis"),{},[]).process
26
26
  expected = '<em class="sesame_dot">腹がへっても</em>、<em class="sesame_dot">ひもじゅうない</em>とかぶりを振っている'
27
27
  assert_equal expected, command.to_s.encode("utf-8")
28
28
  end
@@ -31,7 +31,7 @@ class TagParserTest < Test::Unit::TestCase
31
31
  str = "※[#「てへん+劣」、第3水準1-84-77]…\r\n".encode("shift_jis")
32
32
  strio = StringIO.new(str)
33
33
  stream = Jstream.new(strio)
34
- command, raw = Aozora_tag_parser.new(stream,"…".encode("shift_jis"),{},[]).process
34
+ command, _raw = Aozora2Html::TagParser.new(stream,"…".encode("shift_jis"),{},[]).process
35
35
  expected = '<img src="../../../gaiji/1-84/1-84-77.png" alt="※(「てへん+劣」、第3水準1-84-77)" class="gaiji" />'
36
36
  assert_equal expected, command.to_s.encode("utf-8")
37
37
  end
@@ -40,7 +40,7 @@ class TagParserTest < Test::Unit::TestCase
40
40
  str = "※[#「口+世」、ページ数-行数]…\r\n".encode("shift_jis")
41
41
  strio = StringIO.new(str)
42
42
  stream = Jstream.new(strio)
43
- command, raw = Aozora_tag_parser.new(stream,"…".encode("shift_jis"),{},[]).process
43
+ command, _raw = Aozora2Html::TagParser.new(stream,"…".encode("shift_jis"),{},[]).process
44
44
  expected = '※<span class="notes">[#「口+世」、ページ数-行数]</span>'
45
45
  assert_equal expected, command.to_s.encode("utf-8")
46
46
  end
@@ -49,7 +49,7 @@ class TagParserTest < Test::Unit::TestCase
49
49
  str = "※[#二の字点、1-2-22]…\r\n".encode("shift_jis")
50
50
  strio = StringIO.new(str)
51
51
  stream = Jstream.new(strio)
52
- command, raw = Aozora_tag_parser.new(stream,"…".encode("shift_jis"),{},[]).process
52
+ command, _raw = Aozora2Html::TagParser.new(stream,"…".encode("shift_jis"),{},[]).process
53
53
  expected = '<img src="../../../gaiji/1-02/1-02-22.png" alt="※(二の字点、1-2-22)" class="gaiji" />'
54
54
  assert_equal expected, command.to_s.encode("utf-8")
55
55
  end
@@ -58,23 +58,23 @@ class TagParserTest < Test::Unit::TestCase
58
58
  str = "自[#二]女王國[#一]東度[#レ]海千餘里。…\r\n".encode("shift_jis")
59
59
  strio = StringIO.new(str)
60
60
  stream = Jstream.new(strio)
61
- command, raw = Aozora_tag_parser.new(stream,"…".encode("shift_jis"),{},[]).process
61
+ command, _raw = Aozora2Html::TagParser.new(stream,"…".encode("shift_jis"),{},[]).process
62
62
  expected = '自<sub class="kaeriten">二</sub>女王國<sub class="kaeriten">一</sub>東度<sub class="kaeriten">レ</sub>海千餘里。'
63
63
  assert_equal expected, command.to_s.encode("utf-8")
64
64
  end
65
65
 
66
66
  def test_parse_gaiji_jisx0213
67
- Embed_Gaiji_tag.use_jisx0213 = true
67
+ Aozora2Html::Tag::EmbedGaiji.use_jisx0213 = true
68
68
  str = "※[#「てへん+劣」、第3水準1-84-77]…\r\n".encode("shift_jis")
69
69
  strio = StringIO.new(str)
70
70
  stream = Jstream.new(strio)
71
- command, raw = Aozora_tag_parser.new(stream,"…".encode("shift_jis"),{},[]).process
71
+ command, _raw = Aozora2Html::TagParser.new(stream,"…".encode("shift_jis"),{},[]).process
72
72
  expected = '&#x6318;'
73
73
  assert_equal expected, command.to_s.encode("utf-8")
74
74
  end
75
75
 
76
76
  def teardown
77
- Embed_Gaiji_tag.use_jisx0213 = @jisx0213
77
+ Aozora2Html::Tag::EmbedGaiji.use_jisx0213 = @jisx0213
78
78
  end
79
79
  end
80
80