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
@@ -6,6 +6,9 @@ require 'tmpdir'
6
6
 
7
7
  class Aozora2HtmlTest < Test::Unit::TestCase
8
8
  def setup
9
+ input = StringIO.new("abc\r\n")
10
+ output = StringIO.new
11
+ @parser = Aozora2Html.new(input, output)
9
12
  end
10
13
 
11
14
  def test_aozora2html_new
@@ -22,7 +25,7 @@ class Aozora2HtmlTest < Test::Unit::TestCase
22
25
  end
23
26
  end
24
27
 
25
- def test_scount
28
+ def test_line_number
26
29
  Dir.mktmpdir do |dir|
27
30
  input = File.join(dir,'dummy.txt')
28
31
  output = File.join(dir,'dummy2.txt')
@@ -30,89 +33,190 @@ class Aozora2HtmlTest < Test::Unit::TestCase
30
33
  parser = Aozora2Html.new(input, output)
31
34
 
32
35
  begin
33
- assert_equal 0, parser.scount
36
+ assert_equal 0, parser.line_number
34
37
  ch = parser.read_char
35
38
  assert_equal "a",ch
36
- assert_equal 1, parser.scount
39
+ assert_equal 1, parser.line_number
37
40
  ch = parser.read_char
38
41
  assert_equal "\r\n",ch
39
- assert_equal 1, parser.scount
42
+ assert_equal 1, parser.line_number
40
43
  ch = parser.read_char
41
44
  assert_equal "b",ch
42
- assert_equal 2, parser.scount
45
+ assert_equal 2, parser.line_number
43
46
  ch = parser.read_char
44
47
  assert_equal "\r\n",ch
45
- assert_equal 2, parser.scount
48
+ assert_equal 2, parser.line_number
46
49
  ch = parser.read_char
47
50
  assert_equal "c",ch
48
- assert_equal 3, parser.scount
51
+ assert_equal 3, parser.line_number
49
52
  ensure
50
53
  parser.close
51
54
  end
52
55
  end
53
56
  end
54
57
 
58
+ def test_line_number_2
59
+ input = StringIO.new("a\r\nb\r\nc\r\n")
60
+ output = StringIO.new
61
+ parser = Aozora2Html.new(input, output)
62
+ assert_equal 0, parser.line_number
63
+ ch = parser.read_char
64
+ assert_equal "a",ch
65
+ assert_equal 1, parser.line_number
66
+ ch = parser.read_char
67
+ assert_equal "\r\n",ch
68
+ assert_equal 1, parser.line_number
69
+ ch = parser.read_char
70
+ assert_equal "b",ch
71
+ assert_equal 2, parser.line_number
72
+ ch = parser.read_char
73
+ assert_equal "\r\n",ch
74
+ assert_equal 2, parser.line_number
75
+ ch = parser.read_char
76
+ assert_equal "c",ch
77
+ assert_equal 3, parser.line_number
78
+ end
79
+
55
80
  def test_read_line
56
- Dir.mktmpdir do |dir|
57
- input = File.join(dir,'dummy.txt')
58
- output = File.join(dir,'dummy2.txt')
59
- File.binwrite(input, "ab\r\nc\r\n")
60
- parser = Aozora2Html.new(input, output)
61
- begin
62
- parsed = parser.read_line
63
- assert_equal "ab", parsed
64
- ensure
65
- parser.close
66
- end
67
- end
81
+ input = StringIO.new("ab\r\nc\r\n")
82
+ output = StringIO.new
83
+ parser = Aozora2Html.new(input, output)
84
+ parsed = parser.read_line
85
+ assert_equal "ab", parsed
68
86
  end
69
87
 
70
88
  def test_char_type
71
- Dir.mktmpdir do |dir|
72
- input = File.join(dir,'dummy.txt')
73
- output = File.join(dir,'dummy2.txt')
74
- File.binwrite(input, "ab\r\nc\r\n")
75
- parser = Aozora2Html.new(input, output)
89
+ assert_equal :kanji, @parser.char_type(Aozora2Html::Tag::EmbedGaiji.new(nil,"foo","1-2-3","name"))
90
+ assert_equal :kanji, @parser.char_type(Aozora2Html::Tag::UnEmbedGaiji.new(nil,"foo"))
91
+ assert_equal :hankaku, @parser.char_type(Aozora2Html::Tag::Accent.new(nil,123,"abc"))
92
+ assert_equal :else, @parser.char_type(Aozora2Html::Tag::Okurigana.new(nil,"abc"))
93
+ assert_equal :else, @parser.char_type(Aozora2Html::Tag::InlineKeigakomi.new(nil,"abc"))
94
+ assert_equal :katakana, @parser.char_type(Aozora2Html::Tag::DakutenKatakana.new(nil,1,"abc"))
76
95
 
77
- begin
78
- assert_equal :kanji, parser.char_type(Embed_Gaiji_tag.new(nil,"foo","1-2-3","name"))
79
- assert_equal :kanji, parser.char_type(UnEmbed_Gaiji_tag.new(nil,"foo"))
80
- assert_equal :hankaku, parser.char_type(Accent_tag.new(nil,123,"abc"))
81
- assert_equal :else, parser.char_type(Okurigana_tag.new(nil,"abc"))
82
- assert_equal :else, parser.char_type(Inline_keigakomi_tag.new(nil,"abc"))
83
- assert_equal :katakana, parser.char_type(Dakuten_katakana_tag.new(nil,1,"abc"))
84
-
85
- assert_equal :hiragana, parser.char_type("".encode("shift_jis"))
86
- assert_equal :hiragana, parser.char_type("".encode("shift_jis"))
87
- assert_equal :katakana, parser.char_type("".encode("shift_jis"))
88
- assert_equal :katakana, parser.char_type("ー".encode("shift_jis"))
89
- assert_equal :zenkaku, parser.char_type("w".encode("shift_jis"))
90
- assert_equal :hankaku, parser.char_type("z".encode("shift_jis"))
91
- assert_equal :kanji, parser.char_type("漢".encode("shift_jis"))
92
- assert_equal :hankaku_terminate, parser.char_type("!".encode("shift_jis"))
93
- assert_equal :else, parser.char_type("?".encode("shift_jis"))
94
- ensure
95
- parser.close
96
- end
97
- end
96
+ assert_equal :hiragana, @parser.char_type("あ".encode("shift_jis"))
97
+ assert_equal :hiragana, @parser.char_type("っ".encode("shift_jis"))
98
+ assert_equal :katakana, @parser.char_type("ヴ".encode("shift_jis"))
99
+ assert_equal :katakana, @parser.char_type("ー".encode("shift_jis"))
100
+ assert_equal :zenkaku, @parser.char_type("A".encode("shift_jis"))
101
+ assert_equal :zenkaku, @parser.char_type("w".encode("shift_jis"))
102
+ assert_equal :hankaku, @parser.char_type("z".encode("shift_jis"))
103
+ assert_equal :kanji, @parser.char_type("漢".encode("shift_jis"))
104
+ assert_equal :hankaku_terminate, @parser.char_type("!".encode("shift_jis"))
105
+ assert_equal :else, @parser.char_type("".encode("shift_jis"))
106
+ assert_equal :else, @parser.char_type("".encode("shift_jis"))
98
107
  end
99
108
 
100
109
  def test_read_char
101
- Dir.mktmpdir do |dir|
102
- input = File.join(dir,'dummy.txt')
103
- output = File.join(dir,'dummy2.txt')
104
- File.binwrite(input, "/\\r\n".encode("shift_jis"))
105
- parser = Aozora2Html.new(input, output)
106
- begin
107
- char = parser.read_char
108
- assert_equal "/".encode("shift_jis"), char
109
- assert_equal Aozora2Html.class_eval("@@ku"), char
110
- ensure
111
- parser.close
112
- end
110
+ input = StringIO.new("/\\r\n".encode("shift_jis"))
111
+ output = StringIO.new
112
+ parser = Aozora2Html.new(input, output)
113
+ char = parser.read_char
114
+ assert_equal "/".encode("shift_jis"), char
115
+ assert_equal Aozora2Html::KU, char
116
+ end
117
+
118
+ def test_illegal_char_check
119
+ input = StringIO.new("abc\r\n")
120
+ output = StringIO.new
121
+ parser = Aozora2Html.new(input, output)
122
+ out = StringIO.new
123
+ $stdout = out
124
+ begin
125
+ parser.illegal_char_check("#", 123)
126
+ outstr = out.string
127
+ assert_equal "警告(123行目):1バイトの「#」が使われています\n", outstr.encode("utf-8")
128
+ ensure
129
+ $stdout = STDOUT
130
+ end
131
+ end
132
+
133
+ def test_illegal_char_check_sharp
134
+ input = StringIO.new("abc\r\n")
135
+ output = StringIO.new
136
+ parser = Aozora2Html.new(input, output)
137
+ out = StringIO.new
138
+ $stdout = out
139
+ begin
140
+ parser.illegal_char_check("♯".encode("shift_jis"), 123)
141
+ outstr = out.string
142
+ assert_equal "警告(123行目):注記記号の誤用の可能性がある、「♯」が使われています\n", outstr.encode("utf-8")
143
+ ensure
144
+ $stdout = STDOUT
113
145
  end
114
146
  end
115
147
 
148
+ def test_illegal_char_check_notjis
149
+ input = StringIO.new("abc\r\n")
150
+ output = StringIO.new
151
+ parser = Aozora2Html.new(input, output)
152
+ out = StringIO.new
153
+ $stdout = out
154
+ begin
155
+ parser.illegal_char_check("①".encode("cp932").force_encoding("shift_jis"), 123)
156
+ outstr = out.string
157
+ assert_equal "警告(123行目):JIS外字「①」が使われています\n", outstr.force_encoding("cp932").encode("utf-8")
158
+ ensure
159
+ $stdout = STDOUT
160
+ end
161
+ end
162
+
163
+ def test_illegal_char_check_ok
164
+ input = StringIO.new("abc\r\n")
165
+ output = StringIO.new
166
+ parser = Aozora2Html.new(input, output)
167
+ out = StringIO.new
168
+ $stdout = out
169
+ begin
170
+ parser.illegal_char_check("あ".encode("shift_jis"), 123)
171
+ outstr = output.string
172
+ assert_equal "", outstr
173
+ ensure
174
+ $stdout = STDOUT
175
+ end
176
+ end
177
+
178
+ def test_convert_japanese_number
179
+ assert_equal "3字下げ",
180
+ @parser.convert_japanese_number("三字下げ".encode("shift_jis")).encode("utf-8")
181
+ assert_equal "10字下げ",
182
+ @parser.convert_japanese_number("十字下げ".encode("shift_jis")).encode("utf-8")
183
+ assert_equal "12字下げ",
184
+ @parser.convert_japanese_number("十二字下げ".encode("shift_jis")).encode("utf-8")
185
+ assert_equal "20字下げ",
186
+ @parser.convert_japanese_number("二十字下げ".encode("shift_jis")).encode("utf-8")
187
+ assert_equal "20字下げ",
188
+ @parser.convert_japanese_number("二〇字下げ".encode("shift_jis")).encode("utf-8")
189
+ assert_equal "23字下げ",
190
+ @parser.convert_japanese_number("二十三字下げ".encode("shift_jis")).encode("utf-8")
191
+ assert_equal "2字下げ",
192
+ @parser.convert_japanese_number("2字下げ".encode("shift_jis")).encode("utf-8")
193
+
194
+ end
195
+
196
+ def test_kuten2png
197
+ assert_equal %q|<img src="../../../gaiji/1-84/1-84-77.png" alt="※(「てへん+劣」、第3水準1-84-77)" class="gaiji" />|,
198
+ @parser.kuten2png("#「てへん+劣」、第3水準1-84-77".encode("shift_jis")).to_s.encode("utf-8")
199
+ assert_equal %q|<img src="../../../gaiji/1-02/1-02-22.png" alt="※(二の字点、1-2-22)" class="gaiji" />|,
200
+ @parser.kuten2png("#二の字点、1-2-22".encode("shift_jis")).to_s.encode("utf-8")
201
+ assert_equal %q|<img src="../../../gaiji/1-06/1-06-57.png" alt="※(ファイナルシグマ、1-6-57)" class="gaiji" />|,
202
+ @parser.kuten2png("#ファイナルシグマ、1-6-57".encode("shift_jis")).to_s.encode("utf-8")
203
+ assert_equal %q|#「口+世」、151-23|,
204
+ @parser.kuten2png("#「口+世」、151-23".encode("shift_jis")).to_s.encode("utf-8")
205
+ end
206
+
207
+ def test_terpri?
208
+ assert_equal true, @parser.terpri?([])
209
+ assert_equal true, @parser.terpri?([""])
210
+ assert_equal true, @parser.terpri?(["a"])
211
+ tag = Aozora2Html::Tag::MultilineMidashi.new(@parser,"小".encode("shift_jis"),:normal)
212
+ assert_equal false, @parser.terpri?([tag])
213
+ assert_equal false, @parser.terpri?([tag,tag])
214
+ assert_equal false, @parser.terpri?([tag,"",""])
215
+ assert_equal false, @parser.terpri?(["",tag,""])
216
+ assert_equal true, @parser.terpri?([tag,"a"])
217
+ assert_equal true, @parser.terpri?(["a",tag])
218
+ end
219
+
116
220
  def teardown
117
221
  end
118
222
  end
@@ -2,7 +2,7 @@
2
2
  require 'test_helper'
3
3
  require 'aozora2html'
4
4
 
5
- class Aozora2HtmlTest < Test::Unit::TestCase
5
+ class Aozora2HtmlAccentParserTest < Test::Unit::TestCase
6
6
  def setup
7
7
  end
8
8
 
@@ -10,11 +10,22 @@ class Aozora2HtmlTest < Test::Unit::TestCase
10
10
  str = "〔e'tiquette〕\r\n".encode("shift_jis")
11
11
  strio = StringIO.new(str)
12
12
  stream = Jstream.new(strio)
13
- parsed = Aozora_accent_parser.new(stream,"〕".encode("shift_jis"),{},[]).process
13
+ parsed = Aozora2Html::AccentParser.new(stream,"〕".encode("shift_jis"),{},[]).process
14
14
  expected = "〔<img src=\"../../../gaiji/1-09/1-09-63.png\" alt=\"※(アキュートアクセント付きE小文字)\" class=\"gaiji\" />tiquette"
15
15
  assert_equal expected, parsed.to_s.encode("utf-8")
16
16
  end
17
17
 
18
+ def test_use_jisx0213
19
+ Aozora2Html::Tag::Accent.use_jisx0213 = true
20
+ str = "〔e'tiquette〕\r\n".encode("shift_jis")
21
+ strio = StringIO.new(str)
22
+ stream = Jstream.new(strio)
23
+ parsed = Aozora2Html::AccentParser.new(stream,"〕".encode("shift_jis"),{},[]).process
24
+ expected = "〔&#x00E9;tiquette"
25
+ assert_equal expected, parsed.to_s.encode("utf-8")
26
+ end
27
+
18
28
  def teardown
29
+ Aozora2Html::Tag::Accent.use_jisx0213 = nil
19
30
  end
20
31
  end
@@ -0,0 +1,213 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+ require 'aozora2html'
4
+
5
+ class CommandParseTest < Test::Unit::TestCase
6
+ def setup
7
+ end
8
+
9
+ def test_parse_command1
10
+ src = "デボルド―※[#濁点付き片仮名ワ、1-7-82]ルモオル\r\n"
11
+ parsed = parse_text(src)
12
+ expected = "デボルド—<img src=\"../../../gaiji/1-07/1-07-82.png\" alt=\"※(濁点付き片仮名ワ、1-7-82)\" class=\"gaiji\" />ルモオル<br />\r\n"
13
+ assert_equal expected, parsed
14
+ end
15
+
16
+ def test_parse_command2
17
+ src = "繁雑な日本の 〔e'tiquette〕 も、\r\n"
18
+ parsed = parse_text(src)
19
+ expected = %Q|繁雑な日本の <img src="../../../gaiji/1-09/1-09-63.png" alt="※(アキュートアクセント付きE小文字)" class="gaiji" />tiquette も、<br />\r\n|
20
+ assert_equal expected, parsed
21
+ end
22
+
23
+ def test_parse_command3
24
+ src = "〔Sito^t qu'on le touche il re'sonne.〕\r\n"
25
+ parsed = parse_text(src)
26
+ expected = %Q|Sit<img src="../../../gaiji/1-09/1-09-74.png" alt="※(サーカムフレックスアクセント付きO小文字)" class="gaiji" />t q<img src="../../../gaiji/1-09/1-09-79.png" alt="※(アキュートアクセント付きU小文字)" class="gaiji" />on le touche il r<img src="../../../gaiji/1-09/1-09-63.png" alt="※(アキュートアクセント付きE小文字)" class="gaiji" />sonne.<br />\r\n|
27
+ assert_equal expected, parsed
28
+ end
29
+
30
+ def test_parse_command4
31
+ src = "presqu'〔i^le〕\r\n"
32
+ parsed = parse_text(src)
33
+ expected = %Q|presqu'<img src="../../../gaiji/1-09/1-09-68.png" alt="※(サーカムフレックスアクセント付きI小文字)" class="gaiji" />le<br />\r\n|
34
+ assert_equal expected, parsed
35
+ end
36
+
37
+ def test_parse_command5
38
+ src = "[二十歳の 〔E'tude〕]\r\n"
39
+ parsed = parse_text(src)
40
+ expected = %Q|[二十歳の <img src="../../../gaiji/1-09/1-09-32.png" alt="※(アキュートアクセント付きE)" class="gaiji" />tude]<br />\r\n|
41
+ assert_equal expected, parsed
42
+ end
43
+
44
+ def test_parse_command6
45
+ src = "責[#「責」に白ゴマ傍点]空文庫\r\n"
46
+ parsed = parse_text(src)
47
+ expected = %Q|<em class="white_sesame_dot">責</em>空文庫<br />\r\n|
48
+ assert_equal expected, parsed
49
+ end
50
+
51
+ def test_parse_command7
52
+ src = "[#丸傍点]青空文庫で読書しよう[#丸傍点終わり]。\r\n"
53
+ parsed = parse_text(src)
54
+ expected = %Q|<em class="black_circle">青空文庫で読書しよう</em>。<br />\r\n|
55
+ assert_equal expected, parsed
56
+ end
57
+
58
+ def test_parse_command8
59
+ src = "この形は傍線[#「傍線」に傍線]と書いてください。\r\n"
60
+ parsed = parse_text(src)
61
+ expected = %Q|この形は<em class="underline_solid">傍線</em>と書いてください。<br />\r\n|
62
+ assert_equal expected, parsed
63
+ end
64
+
65
+ def test_parse_command9
66
+ src = "[#左に鎖線]青空文庫で読書しよう[#左に鎖線終わり]。\r\n"
67
+ parsed = parse_text(src)
68
+ expected = %Q|<em class="overline_dotted">青空文庫で読書しよう</em>。<br />\r\n|
69
+ assert_equal expected, parsed
70
+ end
71
+
72
+ def test_parse_command10
73
+ src = "「クリス、宇宙航行委員会が選考[#「選考」は太字]するんだ。きみは志願できない。待つ[#「待つ」は太字]んだ」\r\n"
74
+ parsed = parse_text(src)
75
+ expected = %Q|「クリス、宇宙航行委員会が<span class="futoji">選考</span>するんだ。きみは志願できない。<span class="futoji">待つ</span>んだ」<br />\r\n|
76
+ assert_equal expected, parsed
77
+ end
78
+
79
+ def test_parse_command11
80
+ src = "Which, teaching us, hath this exordium: Nothing from nothing ever yet was born.[#「Nothing from nothing ever yet was born.」は斜体]\r\n"
81
+ parsed = parse_text(src)
82
+ expected = %Q|Which, teaching us, hath this exordium: <span class="shatai">Nothing from nothing ever yet was born.</span><br />\r\n|
83
+ assert_equal expected, parsed
84
+ end
85
+
86
+ def test_parse_command_warichu
87
+ src = "[#割り注]価は四百円であった。[#割り注終わり]\r\n"
88
+ parsed = parse_text(src)
89
+ expected = %Q|<span class="warichu">(価は四百円であった。)</span><br />\r\n|
90
+ assert_equal expected, parsed
91
+ end
92
+
93
+ def test_parse_command_warichu2
94
+ src = "飽海郡南平田村大字飛鳥[#割り注]東は字大林四三七[#改行]西は字神内一一一ノ一[#割り注終わり]\r\n"
95
+ parsed = parse_text(src)
96
+ expected = %Q|飽海郡南平田村大字飛鳥<span class="warichu">(東は字大林四三七<span class="notes">[#改行]</span>西は字神内一一一ノ一)</span><br />\r\n|
97
+ assert_equal expected, parsed
98
+ end
99
+
100
+ def test_parse_command_unicode
101
+ Aozora2Html::Tag::EmbedGaiji.use_unicode = true
102
+ src = "※[#「衄のへん+卩」、U+5379、287-2]\r\n"
103
+ parsed = parse_text(src)
104
+ expected = "&#x5379;<br />\r\n"
105
+ assert_equal expected, parsed
106
+ end
107
+
108
+ def test_parse_command_teisei1
109
+ Aozora2Html::Tag::EmbedGaiji.use_unicode = true
110
+ src = "吹喋[#「喋」に「ママ」の注記]\r\n"
111
+ parsed = parse_text(src)
112
+ expected = "吹<ruby><rb>喋</rb><rp>(</rp><rt>ママ</rt><rp>)</rp></ruby><br />\r\n"
113
+ assert_equal expected, parsed
114
+ end
115
+
116
+ def test_parse_command_teisei2
117
+ Aozora2Html::Tag::EmbedGaiji.use_unicode = true
118
+ src = "紋附だとか[#「紋附だとか」は底本では「絞附だとか」]\r\n"
119
+ parsed = parse_text(src)
120
+ expected = %Q|紋附だとか<span class="notes">[#「紋附だとか」は底本では「絞附だとか」]</span><br />\r\n|
121
+ assert_equal expected, parsed
122
+ end
123
+
124
+ def test_parse_command_teisei3
125
+ Aozora2Html::Tag::EmbedGaiji.use_unicode = true
126
+ src = "私は籠《ざる》[#ルビの「ざる」は底本では「さる」]をさげ\r\n"
127
+ parsed = parse_text(src)
128
+ expected = %Q|私は<ruby><rb>籠</rb><rp>(</rp><rt>ざる</rt><rp>)</rp></ruby><span class="notes">[#ルビの「ざる」は底本では「さる」]</span>をさげ<br />\r\n|
129
+ assert_equal expected, parsed
130
+ end
131
+
132
+ def test_parse_command_teisei4
133
+ Aozora2Html::Tag::EmbedGaiji.use_unicode = true
134
+ src = "広場へに[#「広場へに」はママ]店でもだそう。\r\n"
135
+ parsed = parse_text(src)
136
+ expected = %Q|広場へに<span class="notes">[#「広場へに」はママ]</span>店でもだそう。<br />\r\n|
137
+ assert_equal expected, parsed
138
+ end
139
+
140
+ def test_parse_command_teisei5
141
+ Aozora2Html::Tag::EmbedGaiji.use_unicode = true
142
+ src = "お湯《ゆう》[#ルビの「ゆう」はママ]\r\n"
143
+ parsed = parse_text(src)
144
+ expected = %Q|お<ruby><rb>湯</rb><rp>(</rp><rt>ゆう</rt><rp>)</rp></ruby><span class="notes">[#ルビの「ゆう」はママ]</span><br />\r\n|
145
+ assert_equal expected, parsed
146
+ end
147
+
148
+ def test_parse_command_tcy
149
+ Aozora2Html::Tag::EmbedGaiji.use_unicode = true
150
+ src = "米機B29[#「29」は縦中横]の編隊は、\r\n"
151
+ parsed = parse_text(src)
152
+ expected = %Q|米機B<span dir="ltr">29</span>の編隊は、<br />\r\n|
153
+ assert_equal expected, parsed
154
+ end
155
+
156
+ def test_parse_command_tcy2
157
+ Aozora2Html::Tag::EmbedGaiji.use_unicode = true
158
+ src = "[#縦中横](※[#ローマ数字1、1-13-21])[#縦中横終わり]\r\n"
159
+ parsed = parse_text(src)
160
+ expected = %Q|<span dir="ltr">(<img src="../../../gaiji/1-13/1-13-21.png" alt="※(ローマ数字1、1-13-21)" class="gaiji" />)</span><br />\r\n|
161
+ assert_equal expected, parsed
162
+ end
163
+
164
+ def test_parse_command_kogaki
165
+ Aozora2Html::Tag::EmbedGaiji.use_unicode = true
166
+ src = "それ以上である。(5)[#「(5)」は行右小書き]\r\n"
167
+ parsed = parse_text(src)
168
+ expected = %Q|それ以上である。<sup class="superscript">(5)</sup><br />\r\n|
169
+ assert_equal expected, parsed
170
+ end
171
+
172
+ def test_parse_command_uetsuki
173
+ Aozora2Html::Tag::EmbedGaiji.use_unicode = true
174
+ src = "22[#「2」は上付き小文字]\r\n"
175
+ parsed = parse_text(src)
176
+ expected = %Q|2<sup class="superscript">2</sup><br />\r\n|
177
+ assert_equal expected, parsed
178
+ end
179
+
180
+ def test_parse_command_bouki
181
+ Aozora2Html::Tag::EmbedGaiji.use_unicode = true
182
+ src = "支部長の顔にさっと血が流れ[#「血が流れ」に「×」の傍記]た\r\n"
183
+ parsed = parse_text(src)
184
+ expected = %Q|支部長の顔にさっと<ruby><rb>血が流れ</rb><rp>(</rp><rt>×&nbsp;×&nbsp;×&nbsp;×</rt><rp>)</rp></ruby>た<br />\r\n|
185
+ assert_equal expected, parsed
186
+ end
187
+
188
+ def test_parse_command_ruby
189
+ Aozora2Html::Tag::EmbedGaiji.use_unicode = true
190
+ src = "グリーンランドの中央部八千尺の氷河地帯にあるといわれる、[#横組み]“Ser-mik-Suah《セルミク・シュアー》”[#横組み終わり]の冥路《よみじ》の国。\r\n"
191
+ parsed = parse_text(src)
192
+ expected = %Q|グリーンランドの中央部八千尺の氷河地帯にあるといわれる、<span class=\"yokogumi\">“<ruby><rb>Ser-mik-Suah</rb><rp>(</rp><rt>セルミク・シュアー</rt><rp>)</rp></ruby>”</span>の<ruby><rb>冥路</rb><rp>(</rp><rt>よみじ</rt><rp>)</rp></ruby>の国。<br />\r\n|
193
+ assert_equal expected, parsed
194
+ end
195
+
196
+ def parse_text(input_text)
197
+ input = StringIO.new(input_text.encode("shift_jis"))
198
+ output = StringIO.new
199
+ parser = Aozora2Html.new(input, output)
200
+ parser.instance_eval{@section=:tail}
201
+ catch(:terminate) do
202
+ loop do
203
+ parser.parse
204
+ end
205
+ end
206
+ output.string.encode("utf-8")
207
+ end
208
+
209
+ def teardown
210
+ Aozora2Html::Tag::EmbedGaiji.use_jisx0213 = false
211
+ Aozora2Html::Tag::EmbedGaiji.use_unicode = false
212
+ end
213
+ end