aozora2html 0.7.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +34 -0
  3. data/.gitignore +8 -3
  4. data/.rubocop.yml +227 -0
  5. data/.travis.yml +5 -0
  6. data/CHANGELOG.md +33 -0
  7. data/LICENSE +116 -0
  8. data/README.md +16 -11
  9. data/aozora2html.gemspec +6 -6
  10. data/bin/aozora2html +6 -54
  11. data/lib/aozora2html/accent_parser.rb +91 -0
  12. data/lib/aozora2html/error.rb +16 -0
  13. data/lib/aozora2html/header.rb +139 -0
  14. data/lib/aozora2html/i18n.rb +28 -0
  15. data/lib/aozora2html/ruby_buffer.rb +81 -0
  16. data/lib/aozora2html/style_stack.rb +27 -0
  17. data/lib/aozora2html/tag/accent.rb +39 -0
  18. data/lib/aozora2html/tag/block.rb +19 -0
  19. data/lib/aozora2html/tag/chitsuki.rb +15 -0
  20. data/lib/aozora2html/tag/dakuten_katakana.rb +23 -0
  21. data/lib/aozora2html/tag/decorate.rb +18 -0
  22. data/lib/aozora2html/tag/dir.rb +15 -0
  23. data/lib/aozora2html/tag/editor_note.rb +16 -0
  24. data/lib/aozora2html/tag/embed_gaiji.rb +48 -0
  25. data/lib/aozora2html/tag/font_size.rb +17 -0
  26. data/lib/aozora2html/tag/gaiji.rb +11 -0
  27. data/lib/aozora2html/tag/img.rb +21 -0
  28. data/lib/aozora2html/tag/indent.rb +8 -0
  29. data/lib/aozora2html/tag/inline.rb +13 -0
  30. data/lib/aozora2html/tag/inline_caption.rb +15 -0
  31. data/lib/aozora2html/tag/inline_font_size.rb +18 -0
  32. data/lib/aozora2html/tag/inline_keigakomi.rb +15 -0
  33. data/lib/aozora2html/tag/inline_yokogumi.rb +16 -0
  34. data/lib/aozora2html/tag/jisage.rb +15 -0
  35. data/lib/aozora2html/tag/jizume.rb +16 -0
  36. data/lib/aozora2html/tag/kaeriten.rb +15 -0
  37. data/lib/aozora2html/tag/keigakomi.rb +13 -0
  38. data/lib/aozora2html/tag/kunten.rb +12 -0
  39. data/lib/aozora2html/tag/midashi.rb +18 -0
  40. data/lib/aozora2html/tag/multiline.rb +6 -0
  41. data/lib/aozora2html/tag/multiline_caption.rb +15 -0
  42. data/lib/aozora2html/tag/multiline_chitsuki.rb +8 -0
  43. data/lib/aozora2html/tag/multiline_jisage.rb +8 -0
  44. data/lib/aozora2html/tag/multiline_midashi.rb +22 -0
  45. data/lib/aozora2html/tag/multiline_style.rb +17 -0
  46. data/lib/aozora2html/tag/multiline_yokogumi.rb +17 -0
  47. data/lib/aozora2html/tag/okurigana.rb +15 -0
  48. data/lib/aozora2html/tag/oneline_chitsuki.rb +9 -0
  49. data/lib/aozora2html/tag/oneline_indent.rb +2 -0
  50. data/lib/aozora2html/tag/oneline_jisage.rb +7 -0
  51. data/lib/aozora2html/tag/reference_mentioned.rb +46 -0
  52. data/lib/aozora2html/tag/ruby.rb +98 -0
  53. data/lib/aozora2html/tag/un_embed_gaiji.rb +24 -0
  54. data/lib/aozora2html/tag.rb +55 -0
  55. data/lib/aozora2html/tag_parser.rb +53 -0
  56. data/lib/aozora2html/utils.rb +93 -0
  57. data/lib/aozora2html/version.rb +1 -1
  58. data/lib/aozora2html/yaml_loader.rb +31 -0
  59. data/lib/aozora2html.rb +0 -4
  60. data/lib/extensions.rb +44 -0
  61. data/lib/jstream.rb +68 -0
  62. data/lib/t2hs.rb +837 -1765
  63. data/test/test_aozora2html.rb +320 -43
  64. data/test/test_aozora_accent_parser.rb +13 -2
  65. data/test/test_command_parse.rb +213 -0
  66. data/test/test_dakuten_katakana_tag.rb +5 -4
  67. data/test/test_decorate_tag.rb +5 -4
  68. data/test/test_dir_tag.rb +5 -4
  69. data/test/test_editor_note_tag.rb +4 -4
  70. data/test/test_exception.rb +4 -4
  71. data/test/test_font_size_tag.rb +15 -7
  72. data/test/test_gaiji_tag.rb +14 -7
  73. data/test/test_header.rb +60 -0
  74. data/test/test_i18n.rb +23 -0
  75. data/test/test_img_tag.rb +5 -4
  76. data/test/test_inline_caption_tag.rb +5 -4
  77. data/test/test_inline_font_size_tag.rb +7 -6
  78. data/test/test_inline_keigakomi_tag.rb +5 -4
  79. data/test/test_inline_yokogumi_tag.rb +5 -4
  80. data/test/test_jizume_tag.rb +7 -6
  81. data/test/test_jstream.rb +5 -5
  82. data/test/test_kaeriten_tag.rb +5 -4
  83. data/test/test_keigakomi_tag.rb +8 -7
  84. data/test/test_midashi_tag.rb +38 -0
  85. data/test/test_multiline_caption_tag.rb +7 -6
  86. data/test/test_multiline_midashi_tag.rb +24 -7
  87. data/test/test_multiline_style_tag.rb +7 -6
  88. data/test/test_multiline_yokogumi_tag.rb +7 -6
  89. data/test/test_okurigana_tag.rb +5 -4
  90. data/test/test_ruby_parse.rb +130 -0
  91. data/test/test_ruby_tag.rb +5 -4
  92. data/test/test_tag_parser.rb +10 -10
  93. data/vendor/jis2ucs/README.md +3 -6
  94. data/yml/accent_table.yml +240 -0
  95. data/yml/command_table.yml +61 -0
  96. data/yml/jis2ucs.yml +11234 -0
  97. metadata +74 -42
  98. data/appveyor.yml +0 -19
  99. data/lib/accent_tag.rb +0 -23
  100. data/lib/aozora2html/jis2ucs.rb +0 -11237
  101. data/lib/embed_gaiji_tag.rb +0 -34
data/lib/t2hs.rb CHANGED
@@ -1,958 +1,283 @@
1
- # -*- coding:shift_jis -*-
2
- # �‹󕶌Ɍ`���̃e�L�X�g�t�@�C���� html �ɐ��`���� ruby �X�N���v�g
3
- require "cgi"
1
+ # -*- coding:utf-8 -*-
2
+ # 青空文庫形式のテキストファイルを html に整形する ruby スクリプト
3
+ require "extensions"
4
+ require "aozora2html/error"
5
+ require "jstream"
6
+ require "aozora2html/tag"
7
+ require "aozora2html/tag_parser"
8
+ require "aozora2html/accent_parser"
9
+ require "aozora2html/style_stack"
10
+ require "aozora2html/header"
11
+ require "aozora2html/ruby_buffer"
12
+ require "aozora2html/yaml_loader"
13
+ require "aozora2html/utils"
4
14
 
5
15
  $gaiji_dir = "../../../gaiji/"
6
16
 
7
17
  $css_files = Array["../../aozora.css"]
8
18
 
9
- # 1.8 like to_s method to Array
10
- class Array
11
- def to_s
12
- self.join
13
- end
14
- end
15
-
16
- # ��Oclass
17
- class Aozora_Exception < Exception
18
- def initialize (message)
19
- @message=message
20
- end
21
- end
22
-
23
- class Aozora_Error < Aozora_Exception
24
- def message (line)
25
- "�G���[(#{line}�s��):#{@message}. \r\n�������~���܂�"
26
- end
27
- end
28
-
29
- class Jstream
30
- attr_accessor :line
31
- def store_to_buffer
32
- if tmp = @file.readline.chomp!("\r\n")
33
- @buffer = tmp.each_char.to_a
34
- else
35
- raise Aozora_Error.new("���s�R�[�h���A�uCR+LF�v�ɂ��炽�߂Ă�������")
36
- end
37
- @entry = true
38
- end
39
- def initialize (file_io)
40
- @line = 0
41
- @entry = false
42
- @file = file_io
43
- begin
44
- store_to_buffer
45
- rescue Aozora_Exception => e
46
- puts e.message(1)
47
- if e.is_a?(Aozora_Error)
48
- exit(2)
49
- end
50
- end
51
- end
52
- def inspect
53
- "#<jcode-stream input " + @file.inspect + ">"
54
- end
55
- def read_char
56
- found = @buffer.shift
57
- if @entry
58
- @line = @line + 1
59
- @entry = false
60
- end
61
- if found
62
- found
63
- else
64
- begin
65
- store_to_buffer
66
- "\r\n"
67
- rescue EOFError
68
- @buffer = [:eof]
69
- "\r\n"
70
- end
71
- end
72
- end
73
- def peek_char (pos)
74
- found = @buffer[pos]
75
- if found
76
- found
77
- else
78
- "\r\n"
79
- end
80
- end
81
- def close
82
- @file.close
83
- end
84
- end
85
-
86
- # �ϊ������‹�L�@class
87
- class Aozora_tag
88
- # debug�p
89
- def inspect
90
- to_s
91
- end
92
-
93
- def syntax_error
94
- raise Aozora_Error.new("���L���d�˂�ۂ̌����A�u�����͈͂��ɁA�L���͈͂���Ɂv������Ă��܂���B�����N��̎w�j���Q�l�ɁA�����������炽�߂Ă�������")
95
- end
96
- end
97
-
98
- # �S�Ă̐‹�L�@��HTML element�ɕϊ������
99
- # ���������āAblock/inline�̋�ʂ�����
100
- # �S�Ă̖��[�‹�class�͂ǂ��炩��module��include����K�v������
101
- module Inline_tag
102
- def initialize (*args)
103
- true
104
- end
105
- end
106
-
107
- module Block_tag
108
- # �K�v�Ɋ�Â�method override����
109
- def close_tag
110
- "</div>"
111
- end
112
- def initialize (parser, *args)
113
- if parser.block_allowed_context?
114
- nil
115
- else
116
- syntax_error
117
- end
118
- end
119
- end
120
-
121
- class Accent_tag < Aozora_tag
122
- include Inline_tag
123
- def initialize (parser, code, name)
124
- @code = code
125
- @name = name
126
- super
127
- end
128
- def to_s
129
- "<img src=\"#{$gaiji_dir}#{@code}.png\" alt=\"��(#{@name})\" class=\"gaiji\" />"
130
- end
131
- end
132
-
133
- class Gaiji_tag < Aozora_tag
134
- include Inline_tag
135
- end
136
-
137
- class Embed_Gaiji_tag < Gaiji_tag
138
- def initialize (parser, folder, code, name)
139
- @folder = folder
140
- @code = code
141
- @name = name
142
- super
143
- end
144
- def to_s
145
- "<img src=\"#{$gaiji_dir}#{@folder}/#{@code}.png\" alt=\"��(#{@name})\" class=\"gaiji\" />"
146
- end
147
- end
148
-
149
- class UnEmbed_Gaiji_tag < Gaiji_tag
150
- def initialize (parser, desc)
151
- @desc = desc; @escaped = false
152
- super
153
- end
154
- def to_s
155
- '<span class="notes">�m' + @desc + '�n</span>'
156
- end
157
- def escaped?
158
- @escaped
159
- end
160
- def escape!
161
- @escaped = true
162
- end
163
- end
164
-
165
- class Editor_note_tag < Aozora_tag
166
- include Inline_tag
167
- def initialize (parser, desc)
168
- @desc = desc
169
- super
170
- end
171
- def to_s
172
- '<span class="notes">�m��' + @desc + '�n</span>'
173
- end
174
- end
175
-
176
- class Indent_tag < Aozora_tag
177
- include Block_tag
178
- end
179
-
180
- module Oneline_Indent_tag
181
- end
182
-
183
- module Multiline_tag
184
- end
185
-
186
- class Multiline_style_tag < Aozora_tag
187
- include Block_tag, Multiline_tag
188
- def initialize (parser, style)
189
- @style = style
190
- super
191
- end
192
- def to_s
193
- "<div class=\"#{@style}\">"
194
- end
195
- end
196
-
197
- class Font_size_tag < Aozora_tag
198
- include Block_tag, Multiline_tag
199
- def initialize (parser, times, daisho)
200
- @class = daisho.to_s + times.to_s
201
- @style = case times
202
- when 1
203
- ""
204
- when 2
205
- "x-"
206
- else
207
- if times >= 3
208
- "xx-"
209
- else
210
- raise Aozora_Error.new("�����T�C�Y�̎w�肪�s���ł�")
211
- end
212
- end + case daisho
213
- when :dai
214
- "large"
215
- when :sho
216
- "small"
217
- end
218
- super
219
- end
220
- def to_s
221
- "<div class=\"#{@class}\" style=\"font-size: #{@style};\">"
222
- end
223
- end
224
-
225
- class Jizume_tag < Indent_tag
226
- include Multiline_tag
227
- def initialize (parser, width)
228
- @w = width
229
- super
230
- end
231
- def to_s
232
- "<div class=\"jizume_#{@w}\" style=\"width: #{@w}em\">"
233
- end
234
- end
235
-
236
- class Keigakomi_tag < Aozora_tag
237
- include Block_tag, Multiline_tag
238
- def initialize (parser, size = 1)
239
- @size = size
240
- super
241
- end
242
- def to_s
243
- "<div class=\"keigakomi\" style=\"border: solid #{@size}px\">"
244
- end
245
- end
246
-
247
- class Multiline_yokogumi_tag < Aozora_tag
248
- include Block_tag, Multiline_tag
249
- def initialize (parser)
250
- super
251
- end
252
- def to_s
253
- "<div class=\"yokogumi\">"
254
- end
255
- end
256
-
257
- class Multiline_caption_tag < Aozora_tag
258
- include Block_tag, Multiline_tag
259
- def initialize (parser)
260
- super
261
- end
262
- def to_s
263
- "<div class=\"caption\">"
264
- end
265
- end
266
-
267
- class Multiline_midashi_tag < Aozora_tag
268
- include Block_tag, Multiline_tag
269
- def initialize (parser,size,type)
270
- super
271
- @tag = if size.match("��")
272
- @id = parser.new_midashi_id(1)
273
- "h5"
274
- elsif size.match("��")
275
- @id = parser.new_midashi_id(10)
276
- "h4"
277
- elsif size.match("��")
278
- @id = parser.new_midashi_id(100)
279
- "h3"
280
- else
281
- raise Aozora_Error.new("����`�Ȍ��o���ł�")
282
- end
283
- @class = case type
284
- when :normal
285
- case @tag
286
- when "h5"
287
- "ko-midashi"
288
- when "h4"
289
- "naka-midashi"
290
- when "h3"
291
- "o-midashi"
292
- end
293
- when :dogyo
294
- case @tag
295
- when "h5"
296
- "dogyo-ko-midashi"
297
- when "h4"
298
- "dogyo-naka-midashi"
299
- when "h3"
300
- "dogyo-o-midashi"
301
- end
302
- when :mado
303
- case @tag
304
- when "h5"
305
- "mado-ko-midashi"
306
- when "h4"
307
- "mado-naka-midashi"
308
- when "h3"
309
- "mado-o-midashi"
310
- end
311
- else
312
- raise Aozora_Error.new("����`�Ȍ��o���ł�")
313
- end
314
- end
315
- def to_s
316
- "<#{@tag} class=\"#{@class}\"><a class=\"midashi_anchor\" id=\"midashi#{@id}\">"
317
- end
318
- def close_tag
319
- "</a></#{@tag}>"
320
- end
321
- end
322
-
323
- class Jisage_tag < Indent_tag
324
- def initialize (parser, width)
325
- @width = width
326
- super
327
- end
328
- def to_s
329
- "<div class=\"jisage_#{@width}\" style=\"margin-left: #{@width}em\">"
330
- end
331
- end
332
-
333
- class Oneline_Jisage_tag < Jisage_tag
334
- include Oneline_Indent_tag
335
- end
336
- class Multiline_Jisage_tag < Jisage_tag
337
- include Multiline_tag
338
- end
339
-
340
- class Chitsuki_tag < Indent_tag
341
- def initialize (parser, length)
342
- @length = length
343
- super
344
- end
345
- def to_s
346
- '<div class="chitsuki_' + @length + '" style="text-align:right; margin-right: ' + @length + 'em">'
347
- end
348
- end
349
-
350
- class Oneline_Chitsuki_tag < Chitsuki_tag
351
- include Oneline_Indent_tag
352
- end
353
-
354
-
355
- class Multiline_Chitsuki_tag < Chitsuki_tag
356
- include Multiline_tag
357
- end
19
+ # 変換器本体
20
+ class Aozora2Html
358
21
 
359
- # �O���Q�Ƃł����‚����͒��g���`�F�b�N����
360
- # �q�v�f������Inline_tag�͑S�Ă����‚̃T�u�N���X
361
- class Reference_mentioned_tag < Aozora_tag
362
- include Inline_tag
363
- attr_accessor :target
364
- def block_element? (elt)
365
- if elt.is_a?(Array)
366
- elt.each{|x|
367
- if block_element?(x)
368
- return true
369
- end
370
- }
371
- nil
372
- elsif elt.is_a?(String)
373
- elt.match(/<div/)
374
- else
375
- elt.is_a?(Block_tag)
376
- end
377
- end
378
- def initialize (*args)
379
- if block_element?(@target)
380
- syntax_error
381
- end
382
- end
383
- def target_string
384
- if @target.is_a?(Reference_mentioned_tag)
385
- @target.target_string
386
- elsif @target.is_a?(Array)
387
- @target.collect{|x|
388
- if x.is_a?(Reference_mentioned_tag)
389
- x.target_string
390
- else
391
- x
392
- end}.to_s
393
- else
394
- @target
395
- end
396
- end
397
- end
22
+ # 全角バックスラッシュが出せないから直打ち
23
+ KU = ["18e5"].pack("h*").force_encoding("shift_jis")
24
+ NOJI = ["18f5"].pack("h*").force_encoding("shift_jis")
25
+ DAKUTEN = ["18d8"].pack("h*").force_encoding("shift_jis")
26
+ GAIJI_MARK = "※".to_sjis
27
+ IGETA_MARK = "#".to_sjis
28
+ RUBY_BEGIN_MARK = "《".to_sjis
29
+ RUBY_END_MARK = "》".to_sjis
30
+ PAREN_BEGIN_MARK = "(".to_sjis
31
+ PAREN_END_MARK = ")".to_sjis
32
+ SIZE_SMALL = "小".to_sjis
33
+ SIZE_MIDDLE = "中".to_sjis
34
+ SIZE_LARGE = "大".to_sjis
35
+ TEIHON_MARK = "底本:".to_sjis
36
+ COMMAND_BEGIN = "[".to_sjis
37
+ COMMAND_END = "]".to_sjis
38
+ ACCENT_BEGIN = "〔".to_sjis
39
+ ACCENT_END = "〕".to_sjis
40
+ AOZORABUNKO = "青空文庫".to_sjis
41
+ #PAT_EDITOR = /[校訂|編|編集|編集校訂|校訂編集]$/
42
+ PAT_EDITOR = "(校訂|編|編集)$".to_sjis
43
+ PAT_HENYAKU = "編訳$".to_sjis
44
+ PAT_TRANSLATOR = "訳$".to_sjis
45
+ RUBY_PREFIX = "|".to_sjis
46
+ PAT_RUBY = /#{"《.*?》".to_sjis}/
47
+ PAT_DIRECTION = "(右|左|上|下)に(.*)".to_sjis
48
+ PAT_REF = "^「.+」".to_sjis
49
+ CHUUKI_COMMAND = "注記付き".to_sjis
50
+ TCY_COMMAND = "縦中横".to_sjis
51
+ KEIGAKOMI_COMMAND = "罫囲み".to_sjis
52
+ YOKOGUMI_COMMAND = "横組み".to_sjis
53
+ CAPTION_COMMAND = "キャプション".to_sjis
54
+ WARIGAKI_COMMAND = "割書".to_sjis
55
+ KAERITEN_COMMAND = "返り点".to_sjis
56
+ KUNTEN_OKURIGANA_COMMAND = "訓点送り仮名".to_sjis
57
+ MIDASHI_COMMAND = "見出し".to_sjis
58
+ OMIDASHI_COMMAND = "大見出し".to_sjis
59
+ NAKAMIDASHI_COMMAND = "中見出し".to_sjis
60
+ KOMIDASHI_COMMAND = "小見出し".to_sjis
61
+ DOGYO_OMIDASHI_COMMAND = "同行大見出し".to_sjis
62
+ DOGYO_NAKAMIDASHI_COMMAND = "同行中見出し".to_sjis
63
+ DOGYO_KOMIDASHI_COMMAND = "同行小見出し".to_sjis
64
+ MADO_OMIDASHI_COMMAND = "窓大見出し".to_sjis
65
+ MADO_NAKAMIDASHI_COMMAND = "窓中見出し".to_sjis
66
+ MADO_KOMIDASHI_COMMAND = "窓小見出し".to_sjis
67
+ LEFT_MARK = "左".to_sjis
68
+ UNDER_MARK = "下".to_sjis
69
+ OVER_MARK = "上".to_sjis
70
+ MAIN_MARK = "本文".to_sjis
71
+ END_MARK = "終わり".to_sjis
72
+ TEN_MARK = "点".to_sjis
73
+ SEN_MARK = "線".to_sjis
74
+ OPEN_MARK = "ここから".to_sjis
75
+ CLOSE_MARK = "ここで".to_sjis
76
+ MADE_MARK = "まで".to_sjis
77
+ DOGYO_MARK = "同行".to_sjis
78
+ MADO_MARK = "窓".to_sjis
79
+ JIAGE_COMMAND = "字上げ".to_sjis
80
+ JISAGE_COMMAND = "字下げ".to_sjis
81
+ PHOTO_COMMAND = "写真".to_sjis
82
+ ORIKAESHI_COMMAND = "折り返して".to_sjis
83
+ ONELINE_COMMAND = "この行".to_sjis
84
+ NON_0213_GAIJI = "非0213外字".to_sjis
85
+ WARICHU_COMMAND = "割り注".to_sjis
86
+ TENTSUKI_COMMAND = "天付き".to_sjis
87
+ PAT_REST_NOTES = "(左|下)に「(.*)」の(ルビ|注記|傍記)".to_sjis
88
+ PAT_KUTEN = /#{"「※」[は|の]".to_sjis}/
89
+ PAT_KUTEN_DUAL = "※.*※".to_sjis
90
+ PAT_GAIJI = "(?:#)(.*)(?:、)(.*)".to_sjis
91
+ PAT_KAERITEN = "^([一二三四五六七八九十レ上中下甲乙丙丁天地人]+)$".to_sjis
92
+ PAT_OKURIGANA = "^((.+))$".to_sjis
93
+ PAT_REMOVE_OKURIGANA = /#{"[()]".to_sjis}/
94
+ PAT_CHITSUKI = /#{"(地付き|字上げ)(終わり)*$".to_sjis}/
95
+ PAT_ORIKAESHI_JISAGE = "折り返して(\\d*)字下げ".to_sjis
96
+ PAT_ORIKAESHI_JISAGE2 = "(\\d*)字下げ、折り返して(\\d*)字下げ".to_sjis
97
+ PAT_JI_LEN = "([0-9]+)字".to_sjis
98
+ PAT_INLINE_RUBY = "「(.*)」の注記付き".to_sjis
99
+ PAT_IMAGE = "(.*)((fig.+\\.png)(、横([0-9]+)×縦([0-9]+))*)入る".to_sjis
100
+ PAT_FRONTREF = "「([^「」]*(?:「.+」)*[^「」]*)」[にはの](「.+」の)*(.+)".to_sjis
101
+ PAT_RUBY_DIR = "(左|下)に「([^」]*)」の(ルビ|注記)".to_sjis
102
+ PAT_CHUUKI = /#{"「(.+?)」の注記".to_sjis}/
103
+ PAT_BOUKI = /#{"「(.)」の傍記".to_sjis}/
104
+ PAT_CHARSIZE = /#{"(.*)段階(..)な文字".to_sjis}/
105
+
106
+ DYNAMIC_CONTENTS = ("<div id=\"card\">\r\n<hr />\r\n<br />\r\n" +
107
+ "<a href=\"JavaScript:goLibCard();\" id=\"goAZLibCard\">●図書カード</a>" +
108
+ "<script type=\"text/javascript\" src=\"../../contents.js\"></script>\r\n" +
109
+ "<script type=\"text/javascript\" src=\"../../golibcard.js\"></script>\r\n" +
110
+ "</div>").to_sjis
111
+
112
+ # KUNOJI = ["18e518f5"].pack("h*")
113
+ # utf8 ["fecbf8fecbcb"].pack("h*")
114
+ # DAKUTENKUNOJI = ["18e518d818f5"].pack("h*")
115
+ # utf8 ["fecbf82e083bfecbcb"].pack("h*")
398
116
 
399
- class Midashi_tag < Reference_mentioned_tag
400
- def initialize (parser,target,size,type)
401
- super
402
- @target = target
403
- @tag = if size.match("��")
404
- @id = parser.new_midashi_id(1)
405
- "h5"
406
- elsif size.match("��")
407
- @id = parser.new_midashi_id(10)
408
- "h4"
409
- elsif size.match("��")
410
- @id = parser.new_midashi_id(100)
411
- "h3"
412
- else
413
- raise Aozora_Error.new("����`�Ȍ��o���ł�")
414
- end
415
- @class = case type
416
- when :normal
417
- case @tag
418
- when "h5"
419
- "ko-midashi"
420
- when "h4"
421
- "naka-midashi"
422
- when "h3"
423
- "o-midashi"
424
- end
425
- when :dogyo
426
- case @tag
427
- when "h5"
428
- "dogyo-ko-midashi"
429
- when "h4"
430
- "dogyo-naka-midashi"
431
- when "h3"
432
- "dogyo-o-midashi"
433
- end
434
- when :mado
435
- case @tag
436
- when "h5"
437
- "mado-ko-midashi"
438
- when "h4"
439
- "mado-naka-midashi"
440
- when "h3"
441
- "mado-o-midashi"
442
- end
443
- else
444
- raise Aozora_Error.new("����`�Ȍ��o���ł�")
445
- end
446
- end
447
- def to_s
448
- "<#{@tag} class=\"#{@class}\"><a class=\"midashi_anchor\" id=\"midashi#{@id}\">#{@target}</a></#{@tag}>"
449
- end
450
- end
117
+ loader = Aozora2Html::YamlLoader.new(File.dirname(__FILE__))
118
+ ACCENT_TABLE = loader.load("../yml/accent_table.yml")
451
119
 
452
- # complex ruby markup
453
- # if css3 is major supported, please fix ruby position with property "ruby-position"
454
- # see also: http://www.w3.org/TR/2001/WD-css3-ruby-20010216/
455
- class Ruby_tag < Reference_mentioned_tag
456
- attr_accessor :ruby, :under_ruby
457
- def initialize (parser, string, ruby, under_ruby = "")
458
- @target = string; @ruby = ruby; @under_ruby = under_ruby
459
- super
460
- end
461
-
462
- def gen_rt (string)
463
- if string != ""
464
- "<rt class=\"real_ruby\">#{string}</rt>"
465
- else
466
- "<rt class=\"dummy_ruby\"></rt>"
467
- end
468
- end
120
+ # [class, tag]
121
+ COMMAND_TABLE = loader.load("../yml/command_table.yml")
122
+ JIS2UCS = loader.load("../yml/jis2ucs.yml")
123
+
124
+ INDENT_TYPE = {
125
+ :jisage => "字下げ".to_sjis,
126
+ :chitsuki => "地付き".to_sjis,
127
+ :midashi => "見出し".to_sjis,
128
+ :jizume => "字詰め".to_sjis,
129
+ :yokogumi => "横組み".to_sjis,
130
+ :keigakomi => "罫囲み".to_sjis,
131
+ :caption => "キャプション".to_sjis,
132
+ :futoji => "太字".to_sjis,
133
+ :shatai => "斜体".to_sjis,
134
+ :dai => "大きな文字".to_sjis,
135
+ :sho => "小さな文字".to_sjis,
136
+ }
469
137
 
470
- def to_s
471
- "<ruby><rb>#{@target.to_s}</rb><rp>�i</rp><rt>#{@ruby.to_s}</rt><rp>�j</rp></ruby>"
472
- end
138
+ DAKUTEN_KATAKANA_TABLE = {
139
+ "2" => "ワ゛".to_sjis,
140
+ "3" => "ヰ゛".to_sjis,
141
+ "4" => "ヱ゛".to_sjis,
142
+ "5" => "ヲ゛".to_sjis,
143
+ }
473
144
 
474
- # complex ruby is waiting for IE support and CSS3 candidate
475
- =begin
476
- def to_s
477
- ans = "<ruby class=\"complex_ruby\"><rbc>" # indicator of new version of aozora ruby
478
- if @ruby.is_a?(Array) and @ruby.length > 0
479
- # cell is used
480
- @rbspan = @ruby.length
481
- end
482
- if @under_ruby.is_a?(Array) and @under_ruby.length > 0
483
- # cell is used, but two way cell is not supported
484
- if @rbspan
485
- raise Aozora_Error.new("�T�|�[�g����Ă��Ȃ����G�ȃ��r�t���ł�")
486
- else
487
- @rbspan = @under_ruby.length
488
- end
489
- end
490
-
491
- # target
492
- if @rbspan
493
- @target.each{|x|
494
- ans.concat("<rb>#{x.to_s}</rb>")
495
- }
145
+ def initialize(input, output)
146
+ if input.respond_to?(:read) ## readable IO?
147
+ @stream = Jstream.new(input)
496
148
  else
497
- ans.concat("<rb>#{@target.to_s}</rb>")
149
+ @stream = Jstream.new(File.open(input,"rb:Shift_JIS"))
498
150
  end
499
-
500
- ans.concat("</rbc><rtc>")
501
-
502
- # upper ruby
503
- if @ruby.is_a?(Array)
504
- @ruby.each{|x|
505
- ans.concat(gen_rt(x))
506
- }
507
- elsif @rbspan
508
- if @ruby != ""
509
- ans.concat("<rt class=\"real_ruby\" rbspan=\"#{@rbspan}\">#{@ruby}</rt>")
510
- else
511
- ans.concat("<rt class=\"dummy_ruby\" rbspan=\"#{@rbspan}\"></rt>")
512
- end
151
+ if output.respond_to?(:print) ## writable IO?
152
+ @out = output
513
153
  else
514
- ans.concat(gen_rt(@ruby))
515
- end
516
-
517
- ans.concat("</rtc>")
518
-
519
- # under_ruby (if exists)
520
- if @under_ruby.length > 0
521
- ans.concat("<rtc>")
522
- if @under_ruby.is_a?(Array)
523
- @under_ruby.each{|x|
524
- ans.concat(gen_rt(x))
525
- }
526
- elsif @rbspan
527
- ans.concat("<rt class=\"real_ruby\" rbspan=\"#{@rbspan}\">#{@under_ruby}</rt>")
528
- else
529
- ans.concat(gen_rt(@under_ruby))
530
- end
531
- ans.concat("</rtc>")
532
- end
533
-
534
- # finalize
535
- ans.concat("</ruby>")
536
-
537
- ans
538
- end
539
- =end
540
- end
541
-
542
- class Kunten_tag < Aozora_tag
543
- include Inline_tag
544
- end
545
-
546
- class Kaeriten_tag < Kunten_tag
547
- def initialize (parser, string)
548
- @string = string
549
- super
550
- end
551
- def to_s
552
- "<sub class=\"kaeriten\">#{@string.to_s}</sub>"
553
- end
554
- end
555
-
556
- class Okurigana_tag < Kunten_tag
557
- def initialize (parser, string)
558
- @string = string
559
- super
560
- end
561
- def to_s
562
- "<sup class=\"okurigana\">#{@string.to_s}</sup>"
563
- end
564
- end
565
-
566
- class Inline_keigakomi_tag < Reference_mentioned_tag
567
- def initialize (parser, target)
568
- @target = target
569
- super
570
- end
571
- def to_s
572
- "<span class=\"keigakomi\">#{@target.to_s}</span>"
573
- end
574
- end
575
-
576
- class Inline_yokogumi_tag < Reference_mentioned_tag
577
- def initialize (parser, target)
578
- @target = target
579
- super
580
- end
581
- def to_s
582
- "<span class=\"yokogumi\">#{@target.to_s}</span>"
583
- end
584
- end
585
-
586
- class Inline_caption_tag < Reference_mentioned_tag
587
- def initialize (parser, target)
588
- @target = target
589
- super
590
- end
591
- def to_s
592
- "<span class=\"caption\">#{@target.to_s}</span>"
593
- end
594
- end
595
-
596
- class Inline_font_size_tag < Reference_mentioned_tag
597
- def initialize (parser, target, times, daisho)
598
- @target = target
599
- @class = daisho.to_s + times.to_s
600
- @style = case times
601
- when 1
602
- ""
603
- when 2
604
- "x-"
605
- else
606
- if times >= 3
607
- "xx-"
608
- else
609
- raise Aozora_Error.new("�����T�C�Y�̎w�肪�s���ł�")
610
- end
611
- end + case daisho
612
- when :dai
613
- "large"
614
- when :sho
615
- "small"
616
- end
617
- super
618
- end
619
- def to_s
620
- "<span class=\"#{@class}\" style=\"font-size: #{@style};\">" + @target.to_s + "</span>"
621
- end
622
- end
623
-
624
- class Decorate_tag < Reference_mentioned_tag
625
- def initialize (parser, target, html_class, html_tag)
626
- @target = target; @close = "</#{html_tag}>"
627
- @open = "<#{html_tag} class=\"#{html_class}\">"
628
- super
629
- end
630
- def to_s
631
- @open+@target.to_s+@close
632
- end
633
- end
634
-
635
- class Dakuten_katakana_tag < Aozora_tag
636
- include Inline_tag
637
- def initialize (parser, n, katakana)
638
- @n = n; @katakana = katakana
639
- super
640
- end
641
- def to_s
642
- "<img src=\"#{$gaiji_dir}/1-07/1-07-8#{@n}.png\" alt=\"��(���_�t���Љ����u#{@katakana}�v�A1-07-8#{@n})\" class=\"gaiji\" />"
643
- end
644
- end
645
-
646
- class Dir_tag < Reference_mentioned_tag
647
- def initialize (parser, target)
648
- @target = target
649
- super
650
- end
651
- def to_s
652
- "<span dir=\"ltr\">#{@target.to_s}</span>"
653
- end
654
- end
655
-
656
- class Img_tag < Aozora_tag
657
- include Inline_tag
658
- def initialize (parser, filename, css_class, alt, width, height)
659
- @filename = filename; @css_class = css_class; @alt = alt; @width = width; @height = height
660
- super
661
- end
662
- def to_s
663
- "<img class=\"#{@css_class}\" width=\"#{@width}\" height=\"#{@height}\" src=\"#{@filename}\" alt=\"#{@alt}\" />"
664
- end
665
- end
666
-
667
- # tag��`�I���
668
-
669
- # �ϊ���{��
670
- class Aozora2Html
671
- # �S�p�o�b�N�X���b�V�����o���Ȃ����璼�ł�
672
- @@ku = ["18e5"].pack("h*")
673
- @@noji = ["18f5"].pack("h*")
674
- @@dakuten = ["18d8"].pack("h*")
675
- # @@kunoji = ["18e518f5"].pack("h*")
676
- # utf8 ["fecbf8fecbcb"].pack("h*")
677
- # @@dakutenkunoji = ["18e518d818f5"].pack("h*")
678
- # utf8 ["fecbf82e083bfecbcb"].pack("h*")
679
- @@accent_table = {
680
- "!"=>{
681
- "@"=>["1-09/1-09-03","�t���Q��"]
682
- },
683
- "?"=>{
684
- "@"=>["1-09/1-09-22","�t�^�╄"]
685
- },
686
- "A"=>{
687
- "`"=>["1-09/1-09-23","�O���[�u�A�N�Z���g�t��A"],
688
- "'"=>["1-09/1-09-24","�A�L���[�g�A�N�Z���g�t��A"],
689
- "^"=>["1-09/1-09-25","�T�[�J���t���b�N�X�A�N�Z���g�t��"],
690
- "~"=>["1-09/1-09-26","�`���h�t��A"],
691
- ":"=>["1-09/1-09-27","�_�C�G���V�X�t��A"],
692
- "&"=>["1-09/1-09-28","�ナ���O�t��A"],
693
- "_"=>["1-09/1-09-85","�}�N�����t��A"],
694
- "E"=>{"&"=>["1-09/1-09-29","���K�`��AE"]}
695
- },
696
- "C"=>{
697
- ","=>["1-09/1-09-30","�Z�f�B���t��C"]
698
- },
699
- "E"=>{
700
- "`"=>["1-09/1-09-31","�O���[�u�A�N�Z���g�t��E"],
701
- "'"=>["1-09/1-09-32","�A�L���[�g�A�N�Z���g�t��E"],
702
- "^"=>["1-09/1-09-33","�T�[�J���t���b�N�X�A�N�Z���g�t��E"],
703
- ":"=>["1-09/1-09-34","�_�C�G���V�X�t��E"],
704
- "_"=>["1-09/1-09-88","�}�N�����t��E"]
705
- },
706
- "I"=>{
707
- "`"=>["1-09/1-09-35","�O���[�u�A�N�Z���g�t��I"],
708
- "'"=>["1-09/1-09-36","�A�L���[�g�A�N�Z���g�t��I"],
709
- "^"=>["1-09/1-09-37","�T�[�J���t���b�N�X�A�N�Z���g�t��I"],
710
- ":"=>["1-09/1-09-38","�_�C�G���V�X�t��I"],
711
- "_"=>["1-09/1-09-86","�}�N�����t��I"]
712
- },
713
- "N"=>{
714
- "~"=>["1-09/1-09-40","�`���h�t��N"]
715
- },
716
- "O"=>{
717
- "`"=>["1-09/1-09-41","�O���[�u�A�N�Z���g�t��O"],
718
- "'"=>["1-09/1-09-42","�A�L���[�g�A�N�Z���g�t��O"],
719
- "^"=>["1-09/1-09-43","�T�[�J���t���b�N�X�A�N�Z���g�t��O"],
720
- "~"=>["1-09/1-09-44","�`���h�t��O"],
721
- ":"=>["1-09/1-09-45","�_�C�G���V�X�t��O"],
722
- "/"=>["1-09/1-09-46","�X�g���[�N�t��O"],
723
- "_"=>["1-09/1-09-89","�}�N�����t��O"],
724
- "E"=>{"&"=>["1-11/1-11-11","���K�`��OE�啶��"]}
725
- },
726
- "U"=>{
727
- "`"=>["1-09/1-09-47","�O���[�u�A�N�Z���g�t��U"],
728
- "'"=>["1-09/1-09-48","�A�L���[�g�A�N�Z���g�t��U"],
729
- "^"=>["1-09/1-09-49","�T�[�J���t���b�N�X�A�N�Z���g�t��U"],
730
- ":"=>["1-09/1-09-50","�_�C�G���V�X�t��U"],
731
- "_"=>["1-09/1-09-87","�}�N�����t��U"]
732
- },
733
- "Y"=>{
734
- "'"=>["1-09/1-09-51","�A�L���[�g�A�N�Z���g�t��Y"]
735
- },
736
- "s"=>{
737
- "&"=>["1-09/1-09-53","�h�C�c��G�X�c�F�b�g"]
738
- },
739
- "a"=>{
740
- "`"=>["1-09/1-09-54","�O���[�u�A�N�Z���g�t��A������"],
741
- "'"=>["1-09/1-09-55","�A�L���[�g�A�N�Z���g�t��A������"],
742
- "^"=>["1-09/1-09-56","�T�[�J���t���b�N�X�A�N�Z���g�t��A������"],
743
- "~"=>["1-09/1-09-57","�`���h�t��A������"],
744
- ":"=>["1-09/1-09-58","�_�C�G���V�X�t��A������"],
745
- "&"=>["1-09/1-09-59","�ナ���O�t��A������"],
746
- "_"=>["1-09/1-09-90","�}�N�����t��A������"],
747
- "e"=>{"&"=>["1-09/1-09-60","���K�`��AE������"]}
748
- },
749
- "c"=>{
750
- ","=>["1-09/1-09-61","�Z�f�B���t��C������"]
751
- },
752
- "e"=>{
753
- "`"=>["1-09/1-09-62","�O���[�u�A�N�Z���g�t��E������"],
754
- "'"=>["1-09/1-09-63","�A�L���[�g�A�N�Z���g�t��E������"],
755
- "^"=>["1-09/1-09-64","�T�[�J���t���b�N�X�A�N�Z���g�t��E������"],
756
- ":"=>["1-09/1-09-65","�_�C�G���V�X�t��E������"],
757
- "_"=>["1-09/1-09-93","�}�N�����t��E������"]
758
- },
759
- "i"=>{
760
- "`"=>["1-09/1-09-66","�O���[�u�A�N�Z���g�t��I������"],
761
- "'"=>["1-09/1-09-67","�A�L���[�g�A�N�Z���g�t��I������"],
762
- "^"=>["1-09/1-09-68","�T�[�J���t���b�N�X�A�N�Z���g�t��I������"],
763
- ":"=>["1-09/1-09-69","�_�C�G���V�X�t��I������"],
764
- "_"=>["1-09/1-09-91","�}�N�����t��I������"]
765
- },
766
- "n"=>{
767
- "~"=>["1-09/1-09-71","�`���h�t��N������"]
768
- },
769
- "o"=>{
770
- "`"=>["1-09/1-09-72","�O���[�u�A�N�Z���g�t��O������"],
771
- "'"=>["1-09/1-09-73","�A�L���[�g�A�N�Z���g�t��O������"],
772
- "^"=>["1-09/1-09-74","�T�[�J���t���b�N�X�A�N�Z���g�t��O������"],
773
- "~"=>["1-09/1-09-75","�`���h�t��O������"],
774
- ":"=>["1-09/1-09-76","�_�C�G���V�X�t��O������"],
775
- "_"=>["1-09/1-09-94","�}�N�����t��O������"],
776
- "/"=>["1-09/1-09-77","�X�g���[�N�t��O������"],
777
- "e"=>{"&"=>["1-11/1-11-10","���K�`��OE������"]}
778
- },
779
- "u"=>{
780
- "`"=>["1-09/1-09-78","�O���[�u�A�N�Z���g�t��U������"],
781
- "'"=>["1-09/1-09-79","�A�L���[�g�A�N�Z���g�t��U������"],
782
- "^"=>["1-09/1-09-80","�T�[�J���t���b�N�X�A�N�Z���g�t��U������"],
783
- "_"=>["1-09/1-09-92","�}�N�����t��U������"],
784
- ":"=>["1-09/1-09-81","�_�C�G���V�X�t��U������"]
785
- },
786
- "y"=>{
787
- "'"=>["1-09/1-09-82","�A�L���[�g�A�N�Z���g�t��Y������"],
788
- ":"=>["1-09/1-09-84","�_�C�G���V�X�t��Y������"]
789
- }
790
- }
791
- # [class, tag]
792
- @@command_table = {
793
- "�T�_" => ["sesame_dot","em"],
794
- "���S�}�T�_" => ["white_sesame_dot","em"],
795
- "�ۖT�_" => ["black_circle","em"],
796
- "���ۖT�_" => ["white_circle","em"],
797
- "���O�p�T�_" => ["black_up-pointing_triangle","em"],
798
- "���O�p�T�_" => ["white_up-pointing_triangle","em"],
799
- "��d�ۖT�_" => ["bullseye","em"],
800
- "�ւ̖ږT�_" => ["fisheye","em"],
801
- "�΂–T�_" => ["saltire", "em"],
802
- "�T��"=> ["underline_solid","em"],
803
- "��d�T��"=> ["underline_double","em"],
804
- "����"=> ["underline_dotted","em"],
805
- "�j��"=> ["underline_dashed","em"],
806
- "�g��"=> ["underline_wave","em"],
807
- "����"=> ["futoji","span"],
808
- "�Α�"=> ["shatai","span"],
809
- "���t��������"=>["subscript","sub"],
810
- "��t��������"=>["superscript","sup"],
811
- "�s�E������"=>["superscript","sup"],
812
- "�s��������"=>["subscript","sub"]
813
- }
814
- def initialize (input, output)
815
- @stream = Jstream.new(File.open(input,"rb:Shift_JIS"))
816
- @buffer = []; @ruby_buf = [""]; @ruby_char_type = nil
817
- @out = File.open(output,"w"); @section = :head; @header = []; @style_stack = []
818
- @chuuki_table = {}; @images = []; @indent_stack = []; @tag_stack = []
819
- @midashi_id = 0; @terprip = true
820
- @endchar = :eof
821
- end
822
-
823
- def scount
154
+ @out = File.open(output,"w")
155
+ end
156
+ @buffer = []
157
+ @ruby_buf = RubyBuffer.new
158
+ @section = :head ## 現在処理中のセクション(:head,:head_end,:chuuki,:chuuki_in,:body,:tail)
159
+ @header = Aozora2Html::Header.new() ## ヘッダ行の配列
160
+ @style_stack = StyleStack.new ##スタイルのスタック
161
+ @chuuki_table = {} ## 最後にどの注記を出すかを保持しておく
162
+ @images = [] ## 使用した外字の画像保持用
163
+ @indent_stack = [] ## 基本はシンボルだが、ぶらさげのときはdivタグの文字列が入る
164
+ @tag_stack = []
165
+ @midashi_id = 0 ## 見出しのカウンタ、見出しの種類によって増分が異なる
166
+ @terprip = true ## 改行制御用 (terpriはLisp由来?)
167
+ @endchar = :eof ## 解析終了文字、AccentParserやTagParserでは異なる
168
+ @noprint = nil ## 行末を読み込んだとき、何も出力しないかどうかのフラグ
169
+ end
170
+
171
+ def line_number
824
172
  @stream.line
825
173
  end
826
174
 
827
175
  def block_allowed_context?
828
- # inline_tag���J���Ă��Ȃ����`�F�b�N����Ώ\��
829
- not(@style_stack.last)
176
+ # inline_tagが開いていないかチェックすれば十分
177
+ @style_stack.empty?
830
178
  end
831
179
 
180
+ # 一文字読み込む
832
181
  def read_char
833
182
  @stream.read_char
834
183
  end
835
184
 
836
- def read_to (endchar)
837
- buf=""
838
- loop{
839
- char=@stream.read_char
840
- if char==endchar
185
+ # 指定された終端文字(1文字のStringかCRLF)まで読み込む
186
+ #
187
+ # @param [String] endchar 終端文字
188
+ def read_to(endchar)
189
+ buf = ""
190
+ loop do
191
+ char = @stream.read_char
192
+ if char == endchar
841
193
  break
842
194
  else
843
195
  if char.kind_of?(Symbol)
844
196
  print endchar
845
197
  end
846
198
  buf.concat(char)
847
- end}
199
+ end
200
+ end
848
201
  buf
849
202
  end
850
203
 
851
204
  def read_accent
852
- Aozora_accent_parser.new(@stream,"�l",@chuuki_table,@images).process
205
+ Aozora2Html::AccentParser.new(@stream, ACCENT_END, @chuuki_table, @images).process
853
206
  end
854
207
 
855
- def read_to_nest (endchar)
856
- Aozora_tag_parser.new(@stream,endchar,@chuuki_table,@images).process
208
+ def read_to_nest(endchar)
209
+ Aozora2Html::TagParser.new(@stream, endchar, @chuuki_table, @images).process
857
210
  end
858
211
 
212
+ # 1行読み込み
213
+ #
214
+ # 合わせて@bufferもクリアする
215
+ # @return [String] 読み込んだ文字列を返す
216
+ #
859
217
  def read_line
860
- tmp=read_to("\r\n")
861
- @buffer=[]
218
+ tmp = read_to("\r\n")
219
+ @buffer = []
862
220
  tmp
863
221
  end
864
222
 
865
- def process ()
866
- catch(:terminate){
867
- loop{
868
- begin
869
- parse
870
- rescue Aozora_Exception => e
871
- puts e.message(scount)
872
- if e.is_a?(Aozora_Error)
873
- exit(2)
223
+ # parseする
224
+ #
225
+ # 終了時(終端まで来た場合)にはthrow :terminateで脱出する
226
+ #
227
+ def process
228
+ begin
229
+ catch(:terminate) do
230
+ loop do
231
+ begin
232
+ parse
233
+ rescue Aozora2Html::Error => e
234
+ puts e.message(line_number)
235
+ if e.is_a?(Aozora2Html::Error)
236
+ exit(2)
237
+ end
874
238
  end
875
239
  end
876
- }
877
- }
878
- tail_output # final call
879
- finalize
880
- close
881
- end
882
-
883
- def char_type (char)
884
- if char.is_a?(Accent_tag)
885
- :hankaku
886
- elsif char.is_a?(Gaiji_tag)
887
- :kanji
888
- elsif char.is_a?(Kunten_tag) # just remove this line
889
- :else
890
- elsif char.is_a?(Dakuten_katakana_tag)
891
- :katakana
892
- elsif char.is_a?(Aozora_tag)
893
- :else
894
- elsif char.match(/[��-��T�U]/)
895
- :hiragana
896
- elsif char.match(/[�@-���[�R�S��]/)
897
- :katakana
898
- elsif char.match(/[�O-�X�`-�y��-����-����-�ք@-�`�p-���|���f�C�D]/)
899
- :zenkaku
900
- elsif char.match(/[A-Za-z0-9#\-\&'\,]/)
901
- :hankaku
902
- elsif char.match(/[��-꤁X���W�Y�Z��]/)
903
- :kanji
904
- elsif char.match(/[\.\;\"\?\!\)]/)
905
- :hankaku_terminate
906
- else
240
+ end
241
+ tail_output # final call
242
+ finalize
243
+ close
244
+ rescue => e
245
+ puts "ERROR: line: #{line_number}"
246
+ raise e
247
+ end
248
+ end
249
+
250
+ def char_type(char)
251
+ begin
252
+ ## `String#char_type`も定義されているのに注意
253
+ char.char_type
254
+ rescue
907
255
  :else
908
256
  end
909
257
  end
910
-
911
- def finalize ()
258
+
259
+ def finalize
912
260
  hyoki
913
261
  dynamic_contents
914
262
  @out.print("</body>\r\n</html>\r\n")
915
263
  end
916
-
264
+
917
265
  def dynamic_contents
918
- @out.print("<div id=\"card\">\r\n<hr />\r\n<br />\r\n")
919
- @out.print("<a href=\"JavaScript:goLibCard();\" id=\"goAZLibCard\">���}���J�[�h</a>")
920
- @out.print("<script type=\"text/javascript\" src=\"../../contents.js\"></script>\r\n")
921
- @out.print("<script type=\"text/javascript\" src=\"../../golibcard.js\"></script>\r\n")
922
- @out.print("</div>")
266
+ @out.print DYNAMIC_CONTENTS
923
267
  end
924
268
 
925
- def close ()
269
+ def close
926
270
  @stream.close
927
271
  @out.close
928
272
  end
929
-
930
- def convert_indent_type (type)
931
- case type
932
- when :jisage
933
- "������"
934
- when :chitsuki
935
- "�n�t��"
936
- when :keigakomi
937
- "�r�͂�"
938
- when :caption
939
- "�L���v�V����"
940
- when :jizume
941
- "���l��"
942
- when :futoji
943
- "����"
944
- when :shatai
945
- "�Α�"
946
- when :sho
947
- "�����ȕ���"
948
- when :dai
949
- "�傫�ȕ���"
950
- else
951
- type
952
- end
273
+
274
+ # 記法のシンボル名から文字列へ変換する
275
+ # シンボルが見つからなければそのまま返す
276
+ def convert_indent_type(type)
277
+ INDENT_TYPE[type] || type
953
278
  end
954
279
 
955
- def check_close_match (type)
280
+ def check_close_match(type)
956
281
  ind = if @indent_stack.last.is_a?(String)
957
282
  @noprint = true
958
283
  :jisage
@@ -966,9 +291,9 @@ class Aozora2Html
966
291
  end
967
292
  end
968
293
 
969
- def implicit_close (type)
294
+ def implicit_close(type)
970
295
  if @indent_stack.last
971
- if n = check_close_match(type)
296
+ if check_close_match(type)
972
297
  # ok, nested multiline tags, go ahead
973
298
  else
974
299
  # not nested, please close
@@ -980,21 +305,23 @@ class Aozora2Html
980
305
  end
981
306
  end
982
307
 
308
+ # 本文が終わってよいかチェックし、終わっていなければ例外をあげる
983
309
  def ensure_close
984
310
  if n = @indent_stack.last
985
- raise Aozora_Error.new("#{convert_indent_type(n)}���ɖ{�����I�����܂���")
311
+ raise Aozora2Html::Error, I18n.t(:terminate_in_style, convert_indent_type(n))
986
312
  end
987
- end
988
-
989
- def explicit_close (type)
990
- if n = check_close_match(type)
991
- raise Aozora_Error.new("#{n}��‚��悤�Ƃ��܂������A#{n}���ł͂���܂���")
313
+ end
314
+
315
+ def explicit_close(type)
316
+ n = check_close_match(type)
317
+ if n
318
+ raise Aozora2Html::Error, I18n.t(:invalid_closing, n, n)
992
319
  end
993
320
  if tag = @tag_stack.pop
994
321
  push_chars(tag)
995
322
  end
996
323
  end
997
-
324
+
998
325
  # main loop
999
326
  def parse
1000
327
  case @section
@@ -1009,175 +336,49 @@ class Aozora2Html
1009
336
  when :tail
1010
337
  parse_tail
1011
338
  else
1012
- Aozora_Error.new("encount undefined condition")
339
+ raise Aozora2Html::Error, "encount undefined condition"
1013
340
  end
1014
341
  end
1015
342
 
1016
343
  def judge_chuuki
1017
- # ���L�����邩�ǂ����`�F�b�N
1018
- i=0
1019
- loop{
344
+ # 注記が入るかどうかチェック
345
+ i = 0
346
+ loop do
1020
347
  case @stream.peek_char(i)
1021
348
  when "-"
1022
- i=i+1
349
+ i += 1
1023
350
  when "\r\n"
1024
- @section = :chuuki
351
+ if i == 0 && @stream.peek_char(1) == "\r\n"
352
+ @section = :body
353
+ else
354
+ @section = :chuuki
355
+ end
1025
356
  return
1026
357
  else
1027
358
  @section = :body
1028
359
  @out.print("<br />\r\n")
1029
360
  return
1030
361
  end
1031
- }
362
+ end
1032
363
  end
1033
364
 
1034
- # header�͈�s���“ǂ�
365
+ # headerは一行ずつ読む
1035
366
  def parse_header
1036
367
  string = read_line
1037
368
  # refine from Tomita 09/06/14
1038
- if (string == "") # ��s������΁A�����Ńw�b�_�[�I���Ƃ݂Ȃ�
369
+ if string == "" # 空行がくれば、そこでヘッダー終了とみなす
1039
370
  @section = :head_end
1040
- process_header
371
+ @out.print @header.to_html
1041
372
  else
1042
- string.gsub!(/�b/,"")
1043
- string.gsub!(/�s.*?�t/,"")
373
+ string.gsub!(RUBY_PREFIX,"")
374
+ string.gsub!(PAT_RUBY,"")
1044
375
  @header.push(string)
1045
376
  end
1046
377
  end
1047
-
1048
- def html_title_push (string, hash, attr)
1049
- found = hash[attr]
1050
- if found
1051
- if found != ""
1052
- string + " " + found
1053
- else
1054
- found
1055
- end
1056
- else
1057
- string
1058
- end
1059
- end
1060
-
1061
- def out_header_info (hash, attr, true_name = nil)
1062
- found = hash[attr]
1063
- if found
1064
- @out.print("<h2 class=\"#{true_name or attr}\">#{found}</h2>\r\n")
1065
- end
1066
- end
1067
-
1068
- def header_element_type (string)
1069
- original = true
1070
- string.each_char{|x|
1071
- code = x.unpack("H*")[0]
1072
- if ("00" <= code and code <= "7f") or # 1byte
1073
- ("8140" <= code and code <= "8258") or # 1-1, 3-25
1074
- ("839f" <= code and code <= "8491") # 6-1, 7-81
1075
- # continue
1076
- else
1077
- original = false
1078
- break
1079
- end
1080
- }
1081
- if original
1082
- :original
1083
- elsif string.match(/[�Z��|��|�ҏW|�ҏW�Z��|�Z���ҏW]$/)
1084
- :editor
1085
- elsif string.match(/�Җ�$/)
1086
- :henyaku
1087
- elsif string.match(/��$/)
1088
- :translator
1089
- end
1090
- end
1091
-
1092
- def process_person (string,header_info)
1093
- type = header_element_type(string)
1094
- case type
1095
- when :editor
1096
- header_info[:editor] = string
1097
- when :translator
1098
- header_info[:translator] = string
1099
- when :henyaku
1100
- header_info[:henyaku] = string
1101
- else
1102
- type = :author
1103
- header_info[:author] = string
1104
- end
1105
- type
1106
- end
1107
-
1108
- def process_header()
1109
- header_info = {:title=>@header[0]}
1110
- case @header.length
1111
- when 2
1112
- process_person(@header[1],header_info)
1113
- when 3
1114
- if header_element_type(@header[1]) == :original
1115
- header_info[:original_title] = @header[1]
1116
- process_person(@header[2],header_info)
1117
- elsif process_person(@header[2],header_info) == :author
1118
- header_info[:subtitle] = @header[1]
1119
- else
1120
- header_info[:author] = @header[1]
1121
- end
1122
- when 4
1123
- if header_element_type(@header[1]) == :original
1124
- header_info[:original_title] = @header[1]
1125
- else
1126
- header_info[:subtitle] = @header[1]
1127
- end
1128
- if process_person(@header[3],header_info) == :author
1129
- header_info[:subtitle] = @header[2]
1130
- else
1131
- header_info[:author] = @header[2]
1132
- end
1133
- when 5
1134
- header_info[:original_title] = @header[1]
1135
- header_info[:subtitle] = @header[2]
1136
- header_info[:author] = @header[3]
1137
- if process_person(@header[4],header_info) == :author
1138
- raise Aozora_Error.new("parser encounted author twice")
1139
- end
1140
- when 6
1141
- header_info[:original_title] = @header[1]
1142
- header_info[:subtitle] = @header[2]
1143
- header_info[:original_subtitle] = @header[3]
1144
- header_info[:author] = @header[4]
1145
- if process_person(@header[5],header_info) == :author
1146
- raise Aozora_Error.new("parser encounted author twice")
1147
- end
1148
- end
1149
-
1150
- # <title> �s���\�z
1151
- html_title = "<title>#{header_info[:author]}"
1152
- html_title = html_title_push(html_title, header_info, :translator)
1153
- html_title = html_title_push(html_title, header_info, :editor)
1154
- html_title = html_title_push(html_title, header_info, :henyaku)
1155
- html_title = html_title_push(html_title, header_info, :title)
1156
- html_title = html_title_push(html_title, header_info, :original_title)
1157
- html_title = html_title_push(html_title, header_info, :subtitle)
1158
- html_title = html_title_push(html_title, header_info, :original_subtitle)
1159
- html_title += "</title>"
1160
-
1161
- # �o��
1162
- @out.print("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\r\n \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ja\" >\r\n<head>\r\n <meta http-equiv=\"Content-Type\" content=\"text/html;charset=Shift_JIS\" />\r\n <meta http-equiv=\"content-style-type\" content=\"text/css\" />\r\n")
1163
- $css_files.each{|css|
1164
- @out.print("\t<link rel=\"stylesheet\" type=\"text/css\" href=\"" + css + "\" />\r\n")
1165
- }
1166
- @out.print("\t#{html_title}\r\n <script type=\"text/javascript\" src=\"../../jquery-1.4.2.min.js\"></script>\r\n <link rel=\"Schema.DC\" href=\"http://purl.org/dc/elements/1.1/\" />\r\n <meta name=\"DC.Title\" content=\"#{header_info[:title]}\" />\r\n <meta name=\"DC.Creator\" content=\"#{header_info[:author]}\" />\r\n <meta name=\"DC.Publisher\" content=\"�‹󕶌�\" />\r\n</head>\r\n<body>\r\n<div class=\"metadata\">\r\n")
1167
- @out.print("<h1 class=\"title\">#{header_info[:title]}</h1>\r\n")
1168
- out_header_info(header_info, :original_title)
1169
- out_header_info(header_info, :subtitle)
1170
- out_header_info(header_info, :original_subtitle)
1171
- out_header_info(header_info, :author)
1172
- out_header_info(header_info, :editor)
1173
- out_header_info(header_info, :translator)
1174
- out_header_info(header_info, :henyaku, "editor-translator")
1175
- @out.print("<br />\r\n<br />\r\n</div>\r\n<div id=\"contents\" style=\"display:none\"></div><div class=\"main_text\">")
1176
- end
1177
378
 
1178
379
  def parse_chuuki
1179
380
  string = read_line
1180
- if (string.match(/^\-+$/))
381
+ if string.match(/^\-+$/)
1181
382
  case @section
1182
383
  when :chuuki
1183
384
  @section = :chuuki_in
@@ -1187,39 +388,49 @@ class Aozora2Html
1187
388
  end
1188
389
  end
1189
390
 
1190
- def illegal_char_check (char)
391
+ # 使うべきではない文字があるかチェックする
392
+ #
393
+ # 警告を出力するだけで結果には影響を与えない。警告する文字は以下:
394
+ #
395
+ # * 1バイト文字
396
+ # * `#`ではなく`♯`
397
+ # * JIS(JIS X 0208)外字
398
+ #
399
+ # @return [void]
400
+ #
401
+ def illegal_char_check(char, line)
1191
402
  if char.is_a?(String)
1192
403
  code = char.unpack("H*")[0]
1193
- if code == "21" or
404
+ if code == "21" or
1194
405
  code == "23" or
1195
- ("a1" <= code and code <= "a5") or
1196
- ("28" <= code and code<= "29") or
406
+ ("a1" <= code and code <= "a5") or
407
+ ("28" <= code and code <= "29") or
1197
408
  code == "5b" or
1198
409
  code == "5d" or
1199
410
  code == "3d" or
1200
411
  code == "3f" or
1201
412
  code == "2b" or
1202
- ("7b" <= code and code <= "7d")
1203
- puts "�x��(#{scount}�s��):1�o�C�g�́u#{char}�v���g���Ă��܂�"
413
+ ("7b" <= code and code <= "7d")
414
+ puts I18n.t(:warn_onebyte, line, char)
1204
415
  end
1205
416
 
1206
417
  if code == "81f2"
1207
- puts "�x��(#{scount}�s��):���L�L���̌�p�̉”\��������A�u#{char}�v���g���Ă��܂�"
418
+ puts I18n.t(:warn_chuki, line, char)
1208
419
  end
1209
-
420
+
1210
421
  if ("81ad" <= code and code <= "81b7") or
1211
422
  ("81c0" <= code and code <= "81c7") or
1212
423
  ("81cf" <= code and code <= "81d9") or
1213
424
  ("81e9" <= code and code <= "81ef") or
1214
425
  ("81f8" <= code and code <= "81fb") or
1215
- ("8240" <= code and code <= "824e") or
1216
- ("8259" <= code and code <= "825f") or
1217
- ("827a" <= code and code <= "8280") or
426
+ ("8240" <= code and code <= "824e") or
427
+ ("8259" <= code and code <= "825f") or
428
+ ("827a" <= code and code <= "8280") or
1218
429
  ("829b" <= code and code <= "829e") or
1219
- ("82f2" <= code and code <= "82fc") or
1220
- ("8397" <= code and code <= "839e") or
1221
- ("83b7" <= code and code <= "83be") or
1222
- ("83d7" <= code and code <= "83fc") or
430
+ ("82f2" <= code and code <= "82fc") or
431
+ ("8397" <= code and code <= "839e") or
432
+ ("83b7" <= code and code <= "83be") or
433
+ ("83d7" <= code and code <= "83fc") or
1223
434
  ("8461" <= code and code <= "846f") or
1224
435
  ("8492" <= code and code <= "849e") or
1225
436
  ("84bf" <= code and code <= "84fc") or
@@ -1234,182 +445,192 @@ class Aozora2Html
1234
445
  ("ed40" <= code and code <= "edfc") or
1235
446
  ("ee40" <= code and code <= "eefc") or
1236
447
  ("ef40" <= code and code <= "effc")
1237
- puts "�x��(#{scount}�s��):JIS�O���u#{char}�v���g���Ă��܂�"
448
+ puts I18n.t(:warn_jis_gaiji, line, char)
1238
449
  end
1239
450
  end
1240
451
  end
1241
452
 
1242
- # �{�̉�͕�
1243
- # 1�������“ǂݍ��݁Adispatch����@buffer,@ruby_buf�ւ��܂�
1244
- # ���s�R�[�h�ɓ��������痭�ߍ��񂾂��̂�general_output����
1245
-
453
+ # 本体解析部
454
+ #
455
+ # 1文字ずつ読み込み、dispatchして@buffer,@ruby_bufへしまう
456
+ # 改行コードに当たったら溜め込んだものをgeneral_outputする
457
+ #
1246
458
  def parse_body
1247
459
  char = read_char
1248
460
  check = true
1249
461
  case char
1250
- when "�k"
462
+ when ACCENT_BEGIN
1251
463
  check = false
1252
464
  char = read_accent
1253
- when "��"
465
+ when TEIHON_MARK[0]
1254
466
  if @buffer.length == 0
1255
467
  ending_check
1256
468
  end
1257
- when "��"
469
+ when GAIJI_MARK
1258
470
  char = dispatch_gaiji
1259
- when "�m"
471
+ when COMMAND_BEGIN
1260
472
  char = dispatch_aozora_command
1261
- when @@ku
473
+ when KU
1262
474
  assign_kunoji
1263
- when "�s"
475
+ when RUBY_BEGIN_MARK
1264
476
  char = apply_ruby
1265
477
  end
1266
- if char == "\r\n"
478
+
479
+ case char
480
+ when "\r\n"
1267
481
  general_output
1268
- elsif char == "�b"
1269
- ruby_buf_dump
1270
- @ruby_buf_protected = true
1271
- elsif char == @endchar
482
+ when RUBY_PREFIX
483
+ @ruby_buf.dump_into(@buffer)
484
+ @ruby_buf.protected = true
485
+ when @endchar
1272
486
  # suddenly finished the file
1273
- puts "�x��(#{scount}�s��):�\�����ʃt�@�C���I�["
1274
- throw :terminate
1275
- elsif char != nil
487
+ puts I18n.t(:warn_unexpected_terminator, line_number)
488
+ throw :terminate
489
+ when nil
490
+ # noop
491
+ else
1276
492
  if check
1277
- illegal_char_check(char)
493
+ illegal_char_check(char, line_number)
1278
494
  end
1279
495
  push_chars(char)
1280
496
  end
1281
497
  end
1282
-
498
+
499
+ # 本文が終了したかどうかチェックする
500
+ #
501
+ #
1283
502
  def ending_check
1284
- if @stream.peek_char(0) == "�{" and @stream.peek_char(1) == "�F"
503
+ # `底本:`でフッタ(:tail)に遷移
504
+ if @stream.peek_char(0) == TEIHON_MARK[1] and @stream.peek_char(1) == TEIHON_MARK[2]
1285
505
  @section = :tail
1286
506
  ensure_close
1287
507
  @out.print "</div>\r\n<div class=\"bibliographical_information\">\r\n<hr />\r\n<br />\r\n"
1288
508
  end
1289
509
  end
1290
-
1291
- # buffer management
1292
- def ruby_buf_dump
1293
- if @ruby_buf_protected
1294
- @ruby_buf.unshift("�b")
1295
- @ruby_buf_protected = nil
1296
- end
1297
- top = @ruby_buf[0]
1298
- if top.is_a?(String) and @buffer.last.is_a?(String)
1299
- @buffer.last.concat(top)
1300
- @buffer = @buffer + @ruby_buf[1,@ruby_buf.length]
1301
- else
1302
- @buffer = @buffer + @ruby_buf
1303
- end
1304
- @ruby_buf = [""]
1305
- end
1306
510
 
1307
- def push_chars (obj)
511
+ # Original Aozora2Html#push_chars does not convert "'" into '&#39;'; it's old behaivor
512
+ # of CGI.escapeHTML().
513
+ #
514
+ def push_chars(obj)
1308
515
  if obj.is_a?(Array)
1309
- obj.each{|x|
516
+ obj.each do |x|
1310
517
  push_chars(x)
1311
- }
518
+ end
1312
519
  elsif obj.is_a?(String)
1313
520
  if obj.length == 1
1314
- obj = CGI.escapeHTML(obj)
521
+ obj = obj.gsub(/[&\"<>]/, {'&' => '&amp;', '"' => '&quot;', '<' => '&lt;', '>' => '&gt;'})
1315
522
  end
1316
- obj.each_char{|x|
523
+ obj.each_char do |x|
1317
524
  push_char(x)
1318
- }
525
+ end
1319
526
  else
1320
527
  push_char(obj)
1321
528
  end
1322
529
  end
1323
530
 
1324
- def push_char (char)
1325
- ctype = char_type(char)
1326
- if ctype == :hankaku_terminate and @ruby_buf_type == :hankaku
1327
- if @ruby_buf.last.is_a?(String)
1328
- @ruby_buf.last.concat(char)
531
+ def push_char(char)
532
+ ctype = char_type(char)
533
+ if ctype == :hankaku_terminate and @ruby_buf.char_type == :hankaku
534
+ if @ruby_buf.last_is_string?
535
+ @ruby_buf.last_concat(char)
1329
536
  else
1330
537
  @ruby_buf.push(char)
1331
538
  end
1332
- @ruby_buf_type = :else
1333
- elsif @ruby_buf_protected or (ctype != :else and ctype == @ruby_buf_type)
1334
- if char.is_a?(String) and @ruby_buf.last.is_a?(String)
1335
- @ruby_buf.last.concat(char)
539
+ @ruby_buf.char_type = :else
540
+ elsif @ruby_buf.protected or (ctype != :else and ctype == @ruby_buf.char_type)
541
+ if char.is_a?(String) and @ruby_buf.last_is_string?
542
+ @ruby_buf.last_concat(char)
1336
543
  else
1337
544
  @ruby_buf.push(char)
1338
545
  @ruby_buf.push("")
1339
546
  end
1340
547
  else
1341
- ruby_buf_dump
1342
- @ruby_buf_type = ctype
1343
- @ruby_buf = [char]
548
+ @ruby_buf.dump_into(@buffer)
549
+ @ruby_buf.clear(char)
550
+ @ruby_buf.char_type = ctype
1344
551
  end
1345
552
  end
1346
-
1347
- def buf_is_blank? (buf)
1348
- buf.each{|token|
1349
- if token.is_a?(String) and not(token=="")
553
+
554
+ # 行出力時に@bufferが空かどうか調べる
555
+ #
556
+ # @bufferの中身によって行末の出力が異なるため
557
+ #
558
+ # @return [true, false, :inline] 空文字ではない文字列が入っていればfalse、1行注記なら:inline、それ以外しか入っていなければtrue
559
+ #
560
+ def buf_is_blank?(buf)
561
+ buf.each do |token|
562
+ if token.is_a?(String) and token != ""
1350
563
  return false
1351
- elsif token.is_a?(Oneline_Indent_tag)
564
+ elsif token.is_a?(Aozora2Html::Tag::OnelineIndent)
1352
565
  return :inline
1353
566
  end
1354
- }
567
+ end
1355
568
  true
1356
569
  end
1357
-
1358
- def terpri? (buf)
570
+
571
+ # 行末で<br />を出力するべきかどうかの判別用
572
+ #
573
+ # @return [true, false] Multilineの注記しか入っていなければfalse、Multilineでも空文字でもない要素が含まれていればtrue
574
+ #
575
+ def terpri?(buf)
1359
576
  flag = true
1360
- buf.each{|x|
1361
- if x.is_a?(Multiline_tag)
577
+ buf.each do |x|
578
+ if x.is_a?(Aozora2Html::Tag::Multiline)
1362
579
  flag = false
1363
- elsif (x.is_a?(String) and x == "")
1364
- nil
580
+ elsif x == ""
581
+ # skip
1365
582
  else
1366
583
  return true
1367
584
  end
1368
- }
585
+ end
1369
586
  flag
1370
587
  end
1371
588
 
589
+ # 読み込んだ行の出力を行う
590
+ #
591
+ # parserが改行文字を読み込んだら呼ばれる。
592
+ # 最終的に@ruby_bufと@bufferは初期化する
593
+ #
594
+ # @return [void]
595
+ #
1372
596
  def general_output
1373
597
  if @style_stack.last
1374
- raise Aozora_Error.new("#{@style_stack.last[0]}���ɉ��s����܂����B���s���܂����v�f�ɂ̓u���b�N�\�L��p���Ă�������")
598
+ raise Aozora2Html::Error, I18n.t(:dont_crlf_in_style, @style_stack.last_command)
1375
599
  end
1376
- # buffer�ɃC���f���g�^�O����������������s���Ȃ��I
600
+ # bufferにインデントタグだけがあったら改行しない!
1377
601
  if @noprint
1378
602
  @noprint = false
1379
603
  return
1380
604
  end
1381
- ruby_buf_dump
605
+ @ruby_buf.dump_into(@buffer)
1382
606
  buf = @buffer
1383
- @ruby_buf = [""]; @ruby_buf_mode = nil; @buffer = []
607
+ @ruby_buf.clear
608
+ @buffer = []
1384
609
  tail = []
1385
610
 
1386
611
  indent_type = buf_is_blank?(buf)
1387
612
  terprip = (terpri?(buf) and @terprip)
1388
613
  @terprip = true
1389
614
 
1390
- if @indent_stack.last.is_a?(String) and not(indent_type)
615
+ if @indent_stack.last.is_a?(String) and !indent_type
1391
616
  @out.print @indent_stack.last
1392
617
  end
1393
-
1394
- buf.each{|s|
1395
- if s.is_a?(Oneline_Indent_tag)
618
+
619
+ buf.each do |s|
620
+ if s.is_a?(Aozora2Html::Tag::OnelineIndent)
1396
621
  tail.unshift(s.close_tag)
1397
- elsif s.is_a?(UnEmbed_Gaiji_tag) and not(s.escaped?)
1398
- # �����Ă��������𕜊�������
1399
- @out.print "��"
1400
- elsif s.is_a?(Multiline_Chitsuki_tag)
1401
- elsif s.is_a?(String) and s.match("</em")
622
+ elsif s.is_a?(Aozora2Html::Tag::UnEmbedGaiji) and !s.escaped?
623
+ # 消してあった※を復活させて
624
+ @out.print GAIJI_MARK
1402
625
  end
1403
626
  @out.print s.to_s
1404
- }
627
+ end
628
+
629
+ # 最後はCRLFを出力する
1405
630
  if @indent_stack.last.is_a?(String)
1406
- # �Ԃ牺��indent
631
+ # ぶら下げindent
1407
632
  # tail always active
1408
- if tail.last
1409
- tail.each{|s|
1410
- @out.print s.to_s
1411
- }
1412
- end
633
+ @out.print tail.map{|s| s.to_s}.join("")
1413
634
  if indent_type == :inline
1414
635
  @out.print "\r\n"
1415
636
  elsif indent_type and terprip
@@ -1417,25 +638,23 @@ class Aozora2Html
1417
638
  else
1418
639
  @out.print "</div>\r\n"
1419
640
  end
1420
- elsif tail.last
1421
- tail.each{|s|
1422
- @out.print s.to_s
1423
- }
1424
- @out.print "\r\n"
1425
- elsif terprip
641
+ elsif tail.empty? and terprip
1426
642
  @out.print "<br />\r\n"
1427
643
  else
644
+ @out.print tail.map{|s| s.to_s}.join("")
1428
645
  @out.print "\r\n"
1429
646
  end
1430
647
  end
1431
-
1432
- # �O���Q�Ƃ̔��� Ruby,style�d�˂������X�̂��߁A�v�f�̔z��ŕԂ�
1433
- def search_front_reference (string)
648
+
649
+ # 前方参照の発見 Ruby,style重ねがけ等々のため、要素の配列で返す
650
+ #
651
+ # 前方参照は`○○[#「○○」に傍点]`、`吹喋[#「喋」に「ママ」の注記]`といった表記
652
+ def search_front_reference(string)
1434
653
  if string.length == 0
1435
654
  return false
1436
655
  end
1437
- searching_buf = if @ruby_buf.length != 0
1438
- @ruby_buf
656
+ searching_buf = if @ruby_buf.present?
657
+ @ruby_buf.to_a
1439
658
  else
1440
659
  @buffer
1441
660
  end
@@ -1443,9 +662,9 @@ class Aozora2Html
1443
662
  if last_string.is_a?(String)
1444
663
  if last_string == ""
1445
664
  searching_buf.pop
1446
- search_front_reference(string.sub(Regexp.new(Regexp.quote(last_string)+"$"),""))
1447
- elsif match = last_string.match(Regexp.new(Regexp.quote(string)+"$"))
1448
- # ���S��v
665
+ search_front_reference(string)
666
+ elsif last_string.match(Regexp.new(Regexp.quote(string)+"$"))
667
+ # 完全一致
1449
668
  # start = match.begin(0)
1450
669
  # tail = match.end(0)
1451
670
  # last_string[start,tail-start] = ""
@@ -1453,7 +672,7 @@ class Aozora2Html
1453
672
  searching_buf.push(last_string.sub(Regexp.new(Regexp.quote(string)+"$"),""))
1454
673
  [string]
1455
674
  elsif string.match(Regexp.new(Regexp.quote(last_string)+"$"))
1456
- # ������v
675
+ # 部分一致
1457
676
  tmp = searching_buf.pop
1458
677
  found = search_front_reference(string.sub(Regexp.new(Regexp.quote(last_string)+"$"),""))
1459
678
  if found
@@ -1463,14 +682,14 @@ class Aozora2Html
1463
682
  false
1464
683
  end
1465
684
  end
1466
- elsif last_string.is_a?(Reference_mentioned_tag)
685
+ elsif last_string.is_a?(Aozora2Html::Tag::ReferenceMentioned)
1467
686
  inner = last_string.target_string
1468
687
  if inner == string
1469
- # ���S��v
688
+ # 完全一致
1470
689
  searching_buf.pop
1471
690
  [last_string]
1472
691
  elsif string.match(Regexp.new(Regexp.quote(inner)+"$"))
1473
- # ������v
692
+ # 部分一致
1474
693
  tmp = searching_buf.pop
1475
694
  found = search_front_reference(string.sub(Regexp.new(Regexp.quote(inner)+"$"),""))
1476
695
  if found
@@ -1484,146 +703,143 @@ class Aozora2Html
1484
703
  false
1485
704
  end
1486
705
  end
1487
-
1488
- # ���������O���Q�Ƃ����ɖ߂�
1489
- def recovery_front_reference (reference)
1490
- reference.each{|elt|
1491
- # if @ruby_buf_protected
1492
- if @ruby_buf.length > 0
1493
- if @ruby_buf.last.is_a?(String)
1494
- if elt.is_a?(String)
1495
- @ruby_buf.last.concat(elt)
1496
- else
1497
- @ruby_buf.push(elt)
1498
- end
706
+
707
+ # 発見した前方参照を元に戻す
708
+ #
709
+ # @ruby_bufがあれば@ruby_bufに、なければ@bufferにpushする
710
+ # バッファの最後と各要素が文字列ならconcatし、どちらが文字列でなければ(concatできないので)pushする
711
+ #
712
+ # @return [void]
713
+ #
714
+ def recovery_front_reference(reference)
715
+ reference.each do |elt|
716
+ # if @ruby_buf.protected
717
+ if @ruby_buf.present?
718
+ if @ruby_buf.last_is_string? && elt.is_a?(String)
719
+ @ruby_buf.last_concat(elt)
1499
720
  else
1500
721
  @ruby_buf.push(elt)
1501
722
  end
1502
- else
1503
- if @buffer.last.is_a?(String)
1504
- if elt.is_a?(String)
1505
- @buffer.last.concat(elt)
1506
- else
1507
- @buffer.push(elt)
1508
- end
723
+ elsif @buffer.last.is_a?(String)
724
+ if elt.is_a?(String)
725
+ @buffer.last.concat(elt)
1509
726
  else
1510
- @ruby_buf.push(elt)
727
+ @buffer.push(elt)
1511
728
  end
729
+ else
730
+ @ruby_buf.push(elt)
1512
731
  end
1513
- }
1514
- end
1515
-
1516
- def convert_japanese_number (command)
1517
- tmp = command.tr("�O-�X", "0-9")
1518
- tmp.tr!("���O�l�ܘZ������Z","1234567890")
1519
- tmp.gsub!(/(\d)�\(\d)/){"#{$1}#{$2}"}
1520
- tmp.gsub!(/(\d)�\/){"#{$1}0"}
1521
- tmp.gsub!(/�\(\d)/){"1#{$1}"}
1522
- tmp.gsub!(/�\/,"10")
1523
- tmp
732
+ end
1524
733
  end
1525
734
 
1526
- def kuten2png (substring)
1527
- desc = substring.gsub(/�u���v[��|��]/,"")
735
+ def kuten2png(substring)
736
+ desc = substring.gsub(PAT_KUTEN,"")
1528
737
  match = desc.match(/[12]\-\d{1,2}\-\d{1,2}/)
1529
- if (match and not(desc.match(/��0213�O��/)) and not(desc.match(/��.*��/)))
738
+ if match and !desc.match(NON_0213_GAIJI) and !desc.match(PAT_KUTEN_DUAL)
1530
739
  @chuuki_table[:newjis] = true
1531
740
  codes = match[0].split("-")
1532
- folder = sprintf("%1d-%02d",*codes)
741
+ folder = sprintf("%1d-%02d", codes[0], codes[1])
1533
742
  code = sprintf("%1d-%02d-%02d",*codes)
1534
- Embed_Gaiji_tag.new(self, folder,code,desc.gsub!("��",""))
1535
- else
1536
- substring
1537
- end
743
+ Aozora2Html::Tag::EmbedGaiji.new(self, folder, code, desc.gsub!(IGETA_MARK,""))
744
+ else
745
+ substring
746
+ end
1538
747
  end
1539
748
 
1540
- def escape_gaiji (command)
1541
- whole, kanji, line = command.match(/(?:��)(.*)(?:�A)(.*)/).to_a
749
+ def escape_gaiji(command)
750
+ _whole, kanji, line = command.match(PAT_GAIJI).to_a
1542
751
  tmp = @images.assoc(kanji)
1543
752
  if tmp
1544
753
  tmp.push(line)
1545
754
  else
1546
- @images.push([kanji,line])
755
+ @images.push([kanji, line])
1547
756
  end
1548
- UnEmbed_Gaiji_tag.new(self, command)
757
+ Aozora2Html::Tag::UnEmbedGaiji.new(self, command)
1549
758
  end
1550
759
 
1551
760
  def dispatch_gaiji
1552
- hook = @stream.peek_char(0)
1553
- if hook == "�m"
1554
- read_char
1555
- # embed?
1556
- command,raw = read_to_nest("�n")
1557
- try_emb = kuten2png(command)
1558
- if try_emb == command
1559
- # Unemb
1560
- escape_gaiji(command)
1561
- else
1562
- try_emb
1563
- end
761
+ # 「※」の次が「[」でなければ外字ではない
762
+ if @stream.peek_char(0) != COMMAND_BEGIN
763
+ return GAIJI_MARK
764
+ end
765
+
766
+ # 「[」を読み捨てる
767
+ _ = read_char
768
+ # embed?
769
+ command, _raw = read_to_nest(COMMAND_END)
770
+ try_emb = kuten2png(command)
771
+ if try_emb != command
772
+ try_emb
773
+ elsif command.match(/U\+([0-9A-F]{4,5})/) && Aozora2Html::Tag::EmbedGaiji.use_unicode
774
+ unicode_num = $1
775
+ Aozora2Html::Tag::EmbedGaiji.new(self, nil, nil, command, unicode_num)
1564
776
  else
1565
- "��"
777
+ # Unemb
778
+ escape_gaiji(command)
1566
779
  end
1567
780
  end
1568
-
781
+
782
+ # 注記記法の場合分け
1569
783
  def dispatch_aozora_command
1570
- if @stream.peek_char(0) != "��"
1571
- "�m"
784
+ # 「[」の次が「#」でなければ注記ではない
785
+ if @stream.peek_char(0) != IGETA_MARK
786
+ return COMMAND_BEGIN
787
+ end
788
+
789
+ # 「#」を読み捨てる
790
+ _ = read_char
791
+ command,raw = read_to_nest(COMMAND_END)
792
+ # 適用順序はこれで大丈夫か? 誤爆怖いよ誤爆
793
+ if command.match(ORIKAESHI_COMMAND)
794
+ apply_burasage(command)
795
+
796
+ elsif command.start_with?(OPEN_MARK)
797
+ exec_block_start_command(command)
798
+ elsif command.start_with?(CLOSE_MARK)
799
+ exec_block_end_command(command)
800
+
801
+ elsif command.match(WARICHU_COMMAND)
802
+ apply_warichu(command)
803
+ elsif command.match(JISAGE_COMMAND)
804
+ apply_jisage(command)
805
+ elsif command.match(/fig(\d)+_(\d)+\.png/)
806
+ exec_img_command(command,raw)
807
+ # avoid to try complex ruby -- escape to notes
808
+ elsif command.match(PAT_REST_NOTES)
809
+ apply_rest_notes(command)
810
+ elsif command.end_with?(END_MARK)
811
+ exec_inline_end_command(command)
812
+ nil
813
+ elsif command.match(PAT_REF)
814
+ exec_frontref_command(command)
815
+ elsif command.match(/1-7-8[2345]/)
816
+ apply_dakuten_katakana(command)
817
+ elsif command.match(PAT_KAERITEN)
818
+ Aozora2Html::Tag::Kaeriten.new(self, command)
819
+ elsif command.match(PAT_OKURIGANA)
820
+ Aozora2Html::Tag::Okurigana.new(self, command.gsub!(PAT_REMOVE_OKURIGANA,""))
821
+ elsif command.match(PAT_CHITSUKI)
822
+ apply_chitsuki(command)
823
+ elsif exec_inline_start_command(command)
824
+ nil
1572
825
  else
1573
- read_char
1574
- command,raw = read_to_nest("�n")
1575
- # �K�p�����͂���ő��v���H�@�딚�|����딚
1576
- if command.match(/�܂�Ԃ���/)
1577
- apply_burasage(command)
1578
-
1579
- elsif command.match(/^��������/)
1580
- exec_block_start_command(command.sub(/^��������/,""))
1581
- elsif command.match(/^������/)
1582
- exec_block_end_command(command.sub(/^������/,""))
1583
-
1584
- elsif command.match(/���蒍/)
1585
- apply_warichu(command)
1586
- elsif command.match(/������/)
1587
- apply_jisage(command)
1588
- elsif command.match(/fig(\d)+_(\d)+\.png/)
1589
- exec_img_command(command,raw)
1590
- # avoid to try complex ruby -- escape to notes
1591
- elsif command.match(/(��|��)�Ɂu(.*)�v��(���r|���L|�T�L)/)
1592
- apply_rest_notes(command)
1593
- elsif command.match(/�I���$/)
1594
- exec_inline_end_command(command)
1595
- nil
1596
- elsif command.match(/^�u.+�v/)
1597
- exec_frontref_command(command)
1598
- elsif command.match(/1-7-8[2345]/)
1599
- apply_dakuten_katakana(command)
1600
- elsif command.match(/^([���O�l�ܘZ������\���㒆���b�������V�n�l]+)$/)
1601
- Kaeriten_tag.new(self, command)
1602
- elsif command.match(/^�i(.+)�j$/)
1603
- Okurigana_tag.new(self, command.gsub!(/[�i�j]/,""))
1604
- elsif command.match(/(�n�t��|���グ)(�I���)*$/)
1605
- apply_chitsuki(command)
1606
- elsif exec_inline_start_command(command)
1607
- nil
1608
- else
1609
- apply_rest_notes(command)
1610
- end
826
+ apply_rest_notes(command)
1611
827
  end
1612
828
  end
1613
829
 
1614
- def apply_burasage (command)
830
+ def apply_burasage(command)
1615
831
  tag = nil
1616
832
  if implicit_close(:jisage)
1617
833
  @terprip = false
1618
834
  general_output
1619
835
  end
1620
836
  @noprint = true # always no print
1621
- command = convert_japanese_number(command)
1622
- if command.match(/�V�t��/)
1623
- width = command.match(/�܂�Ԃ���(\d*)������/)[1]
837
+ command = Utils.convert_japanese_number(command)
838
+ if command.match(TENTSUKI_COMMAND)
839
+ width = command.match(PAT_ORIKAESHI_JISAGE)[1]
1624
840
  tag = '<div class="burasage" style="margin-left: ' + width + 'em; text-indent: -' + width + 'em;">'
1625
841
  else
1626
- match = command.match(/(\d*)�������A�܂�Ԃ���(\d*)������/)
842
+ match = command.match(PAT_ORIKAESHI_JISAGE2)
1627
843
  left, indent = match.to_a[1,2]
1628
844
  left = left.to_i - indent.to_i
1629
845
  tag = "<div class=\"burasage\" style=\"margin-left: #{indent}em; text-indent: #{left}em;\">"
@@ -1632,404 +848,395 @@ class Aozora2Html
1632
848
  @tag_stack.push("") # dummy
1633
849
  nil
1634
850
  end
1635
-
1636
- def jisage_width (command)
1637
- convert_japanese_number(command).match(/(\d*)(?:������)/)[1]
851
+
852
+ def jisage_width(command)
853
+ Utils.convert_japanese_number(command).match(/(\d*)(?:#{JISAGE_COMMAND})/)[1]
1638
854
  end
1639
-
1640
- def apply_jisage (command)
1641
- if command.match(/�܂�/) or command.match(/�I���/)
1642
- # �������I���
1643
- explicit_close(:jisage)
855
+
856
+ def apply_jisage(command)
857
+ if command.match(MADE_MARK) or command.match(END_MARK)
858
+ # 字下げ終わり
859
+ explicit_close(:jisage)
1644
860
  @indent_stack.pop
1645
861
  nil
862
+ elsif command.match(ONELINE_COMMAND)
863
+ # 1行だけ
864
+ @buffer.unshift(Aozora2Html::Tag::OnelineJisage.new(self, jisage_width(command)))
865
+ nil
866
+ elsif @buffer.length == 0 and @stream.peek_char(0) == "\r\n"
867
+ # commandのみ
868
+ @terprip = false
869
+ implicit_close(:jisage)
870
+ # adhook hack
871
+ @noprint = false
872
+ @indent_stack.push(:jisage)
873
+ Aozora2Html::Tag::MultilineJisage.new(self, jisage_width(command))
1646
874
  else
1647
- if command.match(/���̍s/)
1648
- # 1�s����
1649
- @buffer.unshift(Oneline_Jisage_tag.new(self, jisage_width(command)))
1650
- nil
1651
- else
1652
- if @buffer.length == 0 and @stream.peek_char(0) == "\r\n"
1653
- # command�̂�
1654
- @terprip = false
1655
- implicit_close(:jisage)
1656
- # adhook hack
1657
- @noprint = false
1658
- @indent_stack.push(:jisage)
1659
- Multiline_Jisage_tag.new(self, jisage_width(command))
1660
- else
1661
- @buffer.unshift(Oneline_Jisage_tag.new(self, jisage_width(command)))
1662
- nil
1663
- end
1664
- end
875
+ @buffer.unshift(Aozora2Html::Tag::OnelineJisage.new(self, jisage_width(command)))
876
+ nil
1665
877
  end
1666
878
  end
1667
879
 
1668
- def apply_warichu (command)
1669
- if command.match(/�I���/)
1670
- check = @stream.peek_char(0)
1671
- if check == "�j"
1672
- push_chars('</span>')
1673
- else
1674
- push_chars('�j')
1675
- push_chars('</span>')
880
+ def apply_warichu(command)
881
+ if command.match(END_MARK)
882
+ if @stream.peek_char(0) != PAREN_END_MARK
883
+ push_chars(PAREN_END_MARK)
1676
884
  end
885
+ push_chars('</span>')
1677
886
  else
1678
- check = @ruby_buf.last
1679
- if check.is_a?(String) and check.match(/�i$/)
887
+ check = @ruby_buf.last
1680
888
  push_chars('<span class="warichu">')
1681
- else
1682
- push_chars('<span class="warichu">')
1683
- push_chars('�i')
889
+ unless check.is_a?(String) and check.end_with?(PAREN_BEGIN_MARK)
890
+ push_chars(PAREN_BEGIN_MARK)
1684
891
  end
1685
892
  end
1686
893
  nil
1687
894
  end
1688
895
 
1689
- def chitsuki_length (command)
1690
- command = convert_japanese_number(command)
1691
- if match = command.match(/([0-9]+)��/)
896
+ def chitsuki_length(command)
897
+ command = Utils.convert_japanese_number(command)
898
+ if match = command.match(PAT_JI_LEN)
1692
899
  match[1]
1693
900
  else
1694
901
  "0"
1695
902
  end
1696
903
  end
1697
-
1698
- def apply_chitsuki (string, multiline = false)
1699
- if string.match(/�����Œn�t���I���/) or
1700
- string.match(/�����Ŏ��グ�I���/)
904
+
905
+ def apply_chitsuki(string, multiline = false)
906
+ if string.match(CLOSE_MARK+INDENT_TYPE[:chitsuki]+END_MARK) or
907
+ string.match(CLOSE_MARK+JIAGE_COMMAND+END_MARK)
1701
908
  explicit_close(:chitsuki)
1702
909
  @indent_stack.pop
1703
910
  nil
1704
911
  else
1705
- l = chitsuki_length(string)
912
+ len = chitsuki_length(string)
1706
913
  if multiline
1707
- # �����s�w��
914
+ # 複数行指定
1708
915
  implicit_close(:chitsuki)
1709
916
  @indent_stack.push(:chitsuki)
1710
- Multiline_Chitsuki_tag.new(self, l)
917
+ Aozora2Html::Tag::MultilineChitsuki.new(self, len)
1711
918
  else
1712
- # 1�s�̂�
1713
- Oneline_Chitsuki_tag.new(self, l)
919
+ # 1行のみ
920
+ Aozora2Html::Tag::OnelineChitsuki.new(self, len)
1714
921
  end
1715
922
  end
1716
923
  end
1717
924
 
1718
- def new_midashi_id(inc)
925
+ def new_midashi_id(size)
926
+ if size.kind_of?(Integer)
927
+ @midashi_id += size
928
+ return @midashi_id
929
+ end
930
+
931
+ case size
932
+ when /#{SIZE_SMALL}/
933
+ inc = 1
934
+ when /#{SIZE_MIDDLE}/
935
+ inc = 10
936
+ when /#{SIZE_LARGE}/
937
+ inc = 100
938
+ else
939
+ raise Aozora2Html::Error, I18n.t(:undefined_header)
940
+ end
1719
941
  @midashi_id += inc
1720
942
  end
1721
943
 
1722
944
  def apply_midashi(command)
1723
945
  @indent_stack.push(:midashi)
946
+ if command.match(DOGYO_MARK)
947
+ midashi_type = :dogyo
948
+ elsif command.match(MADO_MARK)
949
+ midashi_type = :mado
950
+ else
1724
951
  midashi_type = :normal
1725
- if command.match(/���s/)
1726
- midashi_type = :dogyo
1727
- elsif command.match (/��/)
1728
- midashi_type = :mado
1729
- else
1730
- @terprip = false
1731
- end
1732
- Multiline_midashi_tag.new(self,command,midashi_type)
952
+ @terprip = false
953
+ end
954
+ Aozora2Html::Tag::MultilineMidashi.new(self, command, midashi_type)
1733
955
  end
1734
956
 
1735
957
  def apply_yokogumi(command)
1736
958
  @indent_stack.push(:yokogumi)
1737
- Multiline_yokogumi_tag.new(self)
959
+ Aozora2Html::Tag::MultilineYokogumi.new(self)
1738
960
  end
1739
961
 
1740
962
  def apply_keigakomi(command)
1741
963
  @indent_stack.push(:keigakomi)
1742
- Keigakomi_tag.new(self)
964
+ Aozora2Html::Tag::Keigakomi.new(self)
1743
965
  end
1744
966
 
1745
967
  def apply_caption(command)
1746
968
  @indent_stack.push(:caption)
1747
- Multiline_caption_tag.new(self)
969
+ Aozora2Html::Tag::MultilineCaption.new(self)
1748
970
  end
1749
971
 
1750
972
  def apply_jizume(command)
1751
- w = convert_japanese_number(command).match(/(\d*)(?:���l��)/)[1]
973
+ w = Utils.convert_japanese_number(command).match(/(\d*)(?:#{INDENT_TYPE[:jizume]})/)[1]
1752
974
  @indent_stack.push(:jizume)
1753
- Jizume_tag.new(self, w)
975
+ Aozora2Html::Tag::Jizume.new(self, w)
1754
976
  end
1755
-
1756
- def push_block_tag (tag,closing)
977
+
978
+ def push_block_tag(tag,closing)
1757
979
  push_chars(tag)
1758
980
  closing.concat(tag.close_tag)
1759
981
  end
1760
982
 
1761
- def exec_inline_start_command (command)
983
+ def detect_style_size(style)
984
+ if style.match("小".to_sjis)
985
+ :sho
986
+ else
987
+ :dai
988
+ end
989
+ end
990
+
991
+ def exec_inline_start_command(command)
1762
992
  case command
1763
- when "���L�t��"
993
+ when CHUUKI_COMMAND
1764
994
  @style_stack.push([command,'</ruby>'])
1765
995
  push_char('<ruby><rb>')
1766
- when "�c����"
996
+ when TCY_COMMAND
1767
997
  @style_stack.push([command,'</span>'])
1768
998
  push_char('<span dir="ltr">')
1769
- when "�r�͂�"
999
+ when KEIGAKOMI_COMMAND
1770
1000
  @style_stack.push([command,'</span>'])
1771
1001
  push_chars('<span class="keigakomi">')
1772
- when "���g��"
1002
+ when YOKOGUMI_COMMAND
1773
1003
  @style_stack.push([command,'</span>'])
1774
1004
  push_chars('<span class="yokogumi">')
1775
- when "�L���v�V����"
1005
+ when CAPTION_COMMAND
1776
1006
  @style_stack.push([command,'</span>'])
1777
1007
  push_chars('<span class="caption">')
1778
- when "�匩�o��"
1008
+ when WARIGAKI_COMMAND
1009
+ @style_stack.push([command,'</span>'])
1010
+ push_chars('<span class="warigaki">')
1011
+ when OMIDASHI_COMMAND
1779
1012
  @style_stack.push([command,'</a></h3>'])
1780
1013
  @terprip = false
1781
1014
  push_chars("<h3 class=\"o-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(100)}\">")
1782
- when "�����o��"
1015
+ when NAKAMIDASHI_COMMAND
1783
1016
  @style_stack.push([command,'</a></h4>'])
1784
1017
  @terprip = false
1785
1018
  push_chars("<h4 class=\"naka-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(10)}\">")
1786
- when "�����o��"
1019
+ when KOMIDASHI_COMMAND
1787
1020
  @style_stack.push([command,'</a></h5>'])
1788
1021
  @terprip = false
1789
1022
  push_chars("<h5 class=\"ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(1)}\">")
1790
- when "���s�匩�o��"
1023
+ when DOGYO_OMIDASHI_COMMAND
1791
1024
  @style_stack.push([command,'</a></h3>'])
1792
1025
  push_chars("<h3 class=\"dogyo-o-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(100)}\">")
1793
- when "���s�����o��"
1026
+ when DOGYO_NAKAMIDASHI_COMMAND
1794
1027
  @style_stack.push([command,'</a></h4>'])
1795
1028
  push_chars("<h4 class=\"dogyo-naka-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(10)}\">")
1796
- when "���s�����o��"
1029
+ when DOGYO_KOMIDASHI_COMMAND
1797
1030
  @style_stack.push([command,'</a></h5>'])
1798
1031
  push_chars("<h5 class=\"dogyo-ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(1)}\">")
1799
- when "���匩�o��"
1032
+ when MADO_OMIDASHI_COMMAND
1800
1033
  @style_stack.push([command,'</a></h3>'])
1801
1034
  push_chars("<h3 class=\"mado-o-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(100)}\">")
1802
- when "�������o��"
1035
+ when MADO_NAKAMIDASHI_COMMAND
1803
1036
  @style_stack.push([command,'</a></h4>'])
1804
1037
  push_chars("<h4 class=\"mado-naka-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(10)}\">")
1805
- when "�������o��"
1038
+ when MADO_KOMIDASHI_COMMAND
1806
1039
  @style_stack.push([command,'</a></h5>'])
1807
1040
  push_chars("<h5 class=\"mado-ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(1)}\">")
1041
+ when PAT_CHARSIZE
1042
+ @style_stack.push([command,'</span>'])
1043
+ _whole, nest, style = command.match(PAT_CHARSIZE).to_a
1044
+ times = Utils.convert_japanese_number(nest).to_i
1045
+ daisho = detect_style_size(style)
1046
+ html_class = daisho.to_s + times.to_s
1047
+ size = Utils.create_font_size(times, daisho)
1048
+ push_chars("<span class=\"#{html_class}\" style=\"font-size: #{size};\">")
1808
1049
  else
1809
- if command.match(/(.*)�i�K(..)�ȕ���/)
1810
- @style_stack.push([command,'</span>'])
1811
- whole, nest, style = command.match(/(.*)�i�K(..)�ȕ���/).to_a
1812
- times = convert_japanese_number(nest).to_i
1813
- daisho = if style.match("��")
1814
- :sho
1815
- else
1816
- :dai
1817
- end
1818
- html_class = daisho.to_s + times.to_s
1819
- size = case times
1820
- when 1
1821
- ""
1822
- when 2
1823
- "x-"
1824
- else
1825
- if times >= 3
1826
- "xx-"
1827
- else
1828
- raise Aozora_Error.new("�����T�C�Y�̎w�肪�s���ł�")
1829
- end
1830
- end + case daisho
1831
- when :dai
1832
- "large"
1833
- when :sho
1834
- "small"
1835
- end
1836
- push_chars("<span class=\"#{html_class}\" style=\"font-size: #{size};\">")
1837
- else
1838
- ## Decoration ##
1839
- key = command
1840
- filter = lambda{|x| x}
1841
- if command.match(/(�E|��|��|��)��(.*)/)
1842
- whole, dir, com = command.match(/(�E|��|��|��)��(.*)/).to_a
1843
- # renew command
1844
- key = com
1845
- if command.match(/�_/)
1846
- case dir
1847
- when "��", "��"
1848
- filter = lambda{|x| x + "_after"}
1849
- end
1850
- elsif command.match(/��/)
1851
- case dir
1852
- when "��", "��"
1853
- filter = lambda{|x| x.sub("under","over")}
1854
- end
1050
+ ## Decoration ##
1051
+ key = command
1052
+ filter = lambda{|x| x}
1053
+ if command.match(PAT_DIRECTION)
1054
+ _whole, dir, com = command.match(PAT_DIRECTION).to_a
1055
+ # renew command
1056
+ key = com
1057
+ if command.match(TEN_MARK)
1058
+ case dir
1059
+ when LEFT_MARK, UNDER_MARK
1060
+ filter = lambda{|x| x + "_after"}
1855
1061
  end
1856
- end
1857
-
1858
- found = @@command_table[key]
1859
- # found = [class, tag]
1860
- if found
1861
- @style_stack.push([command,"</#{found[1]}>"])
1862
- if found[1] == "em" # or found[1] == "strong"
1863
- @chuuki_table[:em] = true
1062
+ elsif command.match(SEN_MARK)
1063
+ case dir
1064
+ when LEFT_MARK, OVER_MARK
1065
+ filter = lambda{|x| x.sub("under","over")}
1864
1066
  end
1865
- push_chars("<#{found[1]} class=\"#{filter.call(found[0])}\">")
1866
- else
1867
- nil
1868
1067
  end
1869
1068
  end
1069
+
1070
+ found = COMMAND_TABLE[key]
1071
+ # found = [class, tag]
1072
+ if found
1073
+ @style_stack.push([command,"</#{found[1]}>"])
1074
+ push_chars("<#{found[1]} class=\"#{filter.call(found[0])}\">")
1075
+ else
1076
+ if $DEBUG
1077
+ puts I18n.t(:warn_undefined_command, line_number, key)
1078
+ end
1079
+ nil
1080
+ end
1870
1081
  end
1871
1082
  end
1872
1083
 
1873
- def exec_inline_end_command (command)
1874
- encount = command.sub("�I���","")
1875
- if encount == "�{��"
1084
+ def exec_inline_end_command(command)
1085
+ encount = command.sub(END_MARK,"")
1086
+ if encount == MAIN_MARK
1876
1087
  # force to finish main_text
1877
1088
  @section = :tail
1878
1089
  ensure_close
1879
1090
  @noprint = true
1880
1091
  @out.print "</div>\r\n<div class=\"after_text\">\r\n<hr />\r\n"
1881
- elsif encount.match("���L�t��") and @style_stack.last[0] == "���L�t��"
1092
+ elsif encount.match(CHUUKI_COMMAND) and @style_stack.last_command == CHUUKI_COMMAND
1882
1093
  # special inline ruby
1883
1094
  @style_stack.pop
1884
- whole, ruby = encount.match("�u(.*)�v�̒��L�t��").to_a
1885
- push_char("</rb><rp>�i</rp><rt>#{ruby}</rt><rp>�j</rp></ruby>")
1886
- elsif @style_stack.last[0].match(encount)
1095
+ _whole, ruby = encount.match(PAT_INLINE_RUBY).to_a
1096
+ push_char("</rb><rp>(</rp><rt>".to_sjis + ruby + "</rt><rp>)</rp></ruby>".to_sjis)
1097
+ elsif @style_stack.last_command.match(encount)
1887
1098
  push_chars(@style_stack.pop[1])
1888
1099
  else
1889
- raise Aozora_Error.new("#{encount}���I�����悤�Ƃ��܂������A#{@style_stack.last[0]}���ł�")
1100
+ raise Aozora2Html::Error, I18n.t(:invalid_nesting, encount, @style_stack.last_command)
1890
1101
  end
1891
1102
  end
1892
1103
 
1893
- def exec_block_start_command (command)
1104
+ def exec_block_start_command(command)
1105
+ original_command = command.dup
1106
+ command.sub!(/^#{OPEN_MARK}/, "")
1894
1107
  match = ""
1895
- if command.match(/������/)
1108
+ if command.match(INDENT_TYPE[:jisage])
1896
1109
  push_block_tag(apply_jisage(command),match)
1897
- elsif command.match(/(�n�t��|���グ)$/)
1110
+ elsif command.match(/(#{INDENT_TYPE[:chitsuki]}|#{JIAGE_COMMAND})$/)
1898
1111
  push_block_tag(apply_chitsuki(command,true),match)
1899
1112
  end
1900
1113
 
1901
- if command.match(/���o��/)
1114
+ if command.match(INDENT_TYPE[:midashi])
1902
1115
  push_block_tag(apply_midashi(command),match)
1903
1116
  end
1904
1117
 
1905
- if command.match(/���l��/)
1118
+ if command.match(INDENT_TYPE[:jizume])
1906
1119
  if match != ""
1907
1120
  @indent_stack.pop
1908
1121
  end
1909
1122
  push_block_tag(apply_jizume(command),match)
1910
1123
  end
1911
1124
 
1912
- if command.match(/���g��/)
1125
+ if command.match(INDENT_TYPE[:yokogumi])
1913
1126
  if match != ""
1914
1127
  @indent_stack.pop
1915
1128
  end
1916
1129
  push_block_tag(apply_yokogumi(command),match)
1917
1130
  end
1918
1131
 
1919
- if command.match(/�r�͂�/)
1132
+ if command.match(INDENT_TYPE[:keigakomi])
1920
1133
  if match != ""
1921
1134
  @indent_stack.pop
1922
1135
  end
1923
1136
  push_block_tag(apply_keigakomi(command),match)
1924
1137
  end
1925
1138
 
1926
- if command.match(/�L���v�V����/)
1139
+ if command.match(INDENT_TYPE[:caption])
1927
1140
  if match != ""
1928
1141
  @indent_stack.pop
1929
1142
  end
1930
1143
  push_block_tag(apply_caption(command),match)
1931
1144
  end
1932
-
1933
- if command.match(/����/)
1145
+
1146
+ if command.match(INDENT_TYPE[:futoji])
1934
1147
  if match != ""
1935
1148
  @indent_stack.pop
1936
1149
  end
1937
- push_block_tag(Multiline_style_tag.new(self, "futoji"),match)
1150
+ push_block_tag(Aozora2Html::Tag::MultilineStyle.new(self, "futoji"),match)
1938
1151
  @indent_stack.push(:futoji)
1939
1152
  end
1940
- if command.match(/�Α�/)
1153
+ if command.match(INDENT_TYPE[:shatai])
1941
1154
  if match != ""
1942
1155
  @indent_stack.pop
1943
1156
  end
1944
- push_block_tag(Multiline_style_tag.new(self, "shatai"),match)
1157
+ push_block_tag(Aozora2Html::Tag::MultilineStyle.new(self, "shatai"),match)
1945
1158
  @indent_stack.push(:shatai)
1946
- end
1159
+ end
1947
1160
 
1948
- if command.match(/(.*)�i�K(..)�ȕ���/)
1949
- whole, nest, style = command.match(/(.*)�i�K(..)�ȕ���/).to_a
1161
+ if command.match(PAT_CHARSIZE)
1162
+ _whole, nest, style = command.match(PAT_CHARSIZE).to_a
1950
1163
  if match != ""
1951
1164
  @indent_stack.pop
1952
1165
  end
1953
- daisho = if style == "����"
1954
- :sho
1955
- else
1956
- :dai
1957
- end
1958
- push_block_tag(Font_size_tag.new(self,
1959
- convert_japanese_number(nest).to_i,
1960
- daisho),match)
1166
+ daisho = detect_style_size(style)
1167
+ push_block_tag(Aozora2Html::Tag::FontSize.new(self,
1168
+ Utils.convert_japanese_number(nest).to_i,
1169
+ daisho),
1170
+ match)
1961
1171
  @indent_stack.push(daisho)
1962
1172
  end
1963
1173
 
1964
1174
  if match == ""
1965
- apply_rest_notes("��������" + command)
1175
+ apply_rest_notes(original_command)
1966
1176
  else
1967
1177
  @tag_stack.push(match)
1968
1178
  nil
1969
1179
  end
1970
1180
  end
1971
1181
 
1972
- def exec_block_end_command (command)
1182
+ # コマンド文字列からモードのシンボルを取り出す
1183
+ #
1184
+ # @return [Symbol]
1185
+ #
1186
+ def detect_command_mode(command)
1187
+ if command.match(INDENT_TYPE[:chitsuki]+END_MARK) || command.match(JIAGE_COMMAND+END_MARK)
1188
+ return :chitsuki
1189
+ end
1190
+ INDENT_TYPE.keys.each do |key|
1191
+ if command.match(INDENT_TYPE[key])
1192
+ return key
1193
+ end
1194
+ end
1195
+ return nil
1196
+ end
1197
+
1198
+ def exec_block_end_command(command)
1199
+ original_command = command.dup
1200
+ command.sub!(/^#{CLOSE_MARK}/, "")
1973
1201
  match = false
1974
- if mode = if command.match(/������/)
1975
- :jisage
1976
- elsif command.match(/(�n�t��|���グ)�I���$/)
1977
- :chitsuki
1978
- elsif command.match(/���o��/)
1979
- :midashi
1980
- elsif command.match(/���l��/)
1981
- :jizume
1982
- elsif command.match(/���g��/)
1983
- :yokogumi
1984
- elsif command.match(/�r�͂�/)
1985
- :keigakomi
1986
- elsif command.match(/�L���v�V����/)
1987
- :caption
1988
- elsif command.match(/����/)
1989
- :futoji
1990
- elsif command.match(/�Α�/)
1991
- :shatai
1992
- elsif command.match(/�傫�ȕ���/)
1993
- :dai
1994
- elsif command.match(/�����ȕ���/)
1995
- :sho
1996
- end
1202
+ mode = detect_command_mode(command)
1203
+ if mode
1997
1204
  explicit_close(mode)
1998
1205
  match = @indent_stack.pop
1999
1206
  end
2000
-
1207
+
2001
1208
  if match
2002
- if not(match.is_a?(String))
1209
+ if !match.is_a?(String)
2003
1210
  @terprip = false
2004
1211
  end
2005
1212
  nil
2006
1213
  else
2007
- apply_rest_notes("������" + command)
1214
+ apply_rest_notes(original_command)
2008
1215
  end
2009
1216
  end
2010
-
2011
- def exec_img_command (command,raw)
2012
- match = raw.match(/(.*)�i(fig.+\.png)(�A��([0-9]+)�~�c([0-9]+))*�j����/)
1217
+
1218
+ def exec_img_command(command,raw)
1219
+ match = raw.match(PAT_IMAGE)
2013
1220
  if match
2014
- whole, alt, src, wh, width, height = match.to_a
2015
- css_class = if alt.match(/�ʐ^/)
1221
+ _whole, alt, src, _wh, width, height = match.to_a
1222
+ css_class = if alt.match(PHOTO_COMMAND)
2016
1223
  "photo"
2017
1224
  else
2018
1225
  "illustration"
2019
1226
  end
2020
- Img_tag.new(self, src, css_class, alt, width, height)
1227
+ Aozora2Html::Tag::Img.new(self, src, css_class, alt, width, height)
2021
1228
  else
2022
1229
  apply_rest_notes(command)
2023
1230
  end
2024
1231
  end
2025
1232
 
2026
- def exec_frontref_command (command)
2027
- whole, reference, spec1, spec2 = command.match(/�u([^�u�v]*(?:�u.+�v)*[^�u�v]*)�v[��|��|��](�u.+�v��)*(.+)/).to_a
2028
- spec = if spec1
2029
- spec1 + spec2
2030
- else
2031
- spec2
2032
- end
1233
+ def exec_frontref_command(command)
1234
+ _whole, reference, spec1, spec2 = command.match(PAT_FRONTREF).to_a
1235
+ if spec1
1236
+ spec = spec1 + spec2
1237
+ else
1238
+ spec = spec2
1239
+ end
2033
1240
  if reference and found = search_front_reference(reference)
2034
1241
  tmp = exec_style(found, spec)
2035
1242
  if tmp
@@ -2042,37 +1249,42 @@ class Aozora2Html
2042
1249
  apply_rest_notes(command)
2043
1250
  end
2044
1251
 
2045
- def multiply (bouki, times)
2046
- s = ""
2047
- (times-1).times{
2048
- s += bouki
2049
- s += "<!>"
2050
- }
2051
- s + bouki
1252
+ # 傍記を並べる用
1253
+ #
1254
+ def multiply(bouki, times)
1255
+ sep = "&nbsp;"
1256
+ ([bouki]*times).join(sep)
2052
1257
  end
2053
1258
 
2054
- def include_ruby? (array)
2055
- array.index{|elt|
2056
- if elt.is_a?(Ruby_tag)
1259
+ # arrayがルビを含んでいればそのインデックスを返す
1260
+ #
1261
+ # @return [Integer, nil]
1262
+ #
1263
+ def include_ruby?(array)
1264
+ array.index do |elt|
1265
+ if elt.is_a?(Aozora2Html::Tag::Ruby)
2057
1266
  true
2058
- elsif elt.is_a?(Reference_mentioned_tag)
1267
+ elsif elt.is_a?(Aozora2Html::Tag::ReferenceMentioned)
2059
1268
  if elt.target.is_a?(Array)
2060
1269
  include_ruby?(elt.target)
2061
1270
  else
2062
- elt.target.is_a?(Ruby_tag)
1271
+ elt.target.is_a?(Aozora2Html::Tag::Ruby)
2063
1272
  end
2064
1273
  end
2065
- }
1274
+ end
2066
1275
  end
2067
-
1276
+
1277
+ # rubyタグの再生成(本体はrearrange_ruby)
1278
+ #
2068
1279
  # complex ruby wrap up utilities -- don't erase! we will use soon ...
2069
- def rearrange_ruby_tag (targets, upper_ruby, under_ruby = "")
2070
- target,upper,under = rearrange_ruby(targets, upper_ruby, under_ruby)
2071
- Ruby_tag.new(self, target,upper,under)
1280
+ #
1281
+ def rearrange_ruby_tag(targets, upper_ruby, under_ruby = "")
1282
+ target, upper, under = rearrange_ruby(targets, upper_ruby, under_ruby)
1283
+ Aozora2Html::Tag::Ruby.new(self, target, upper, under)
2072
1284
  end
2073
-
2074
- # ruby�^�O�̍Ċ��蓖��
2075
- def rearrange_ruby (targets, upper_ruby, under_ruby = "")
1285
+
1286
+ # rubyタグの再割り当て
1287
+ def rearrange_ruby(targets, upper_ruby, under_ruby = "")
2076
1288
  if include_ruby?(targets)
2077
1289
  new_targets = []
2078
1290
  new_upper = if upper_ruby != ""
@@ -2086,34 +1298,34 @@ class Aozora2Html
2086
1298
  []
2087
1299
  end
2088
1300
  if new_upper.length > 1 and new_under.length > 1
2089
- raise Aozora_Error.new("1�‚̒P���3�‚̃��r�͂‚����܂���")
1301
+ raise Aozora2Html::Error, I18n.t(:dont_allow_triple_ruby)
2090
1302
  end
2091
-
1303
+
2092
1304
  targets.each{|x|
2093
- if x.is_a?(Ruby_tag)
1305
+ if x.is_a?(Aozora2Html::Tag::Ruby)
2094
1306
  if x.target.is_a?(Array)
2095
- # inner Ruby_tag is already complex ... give up
2096
- raise Aozora_Error.new("�����ӏ���2�‚̃��r�͂‚����܂���")
1307
+ # inner Aozora2Html::Tag::Ruby is already complex ... give up
1308
+ raise Aozora2Html::Error, I18n.t(:dont_use_double_ruby)
2097
1309
  else
2098
1310
  if x.ruby != ""
2099
1311
  if new_upper.is_a?(Array)
2100
1312
  new_upper.push(x.ruby)
2101
1313
  else
2102
- raise Aozora_Error.new("�����ӏ���2�‚̃��r�͂‚����܂���")
1314
+ raise Aozora2Html::Error, I18n.t(:dont_use_double_ruby)
2103
1315
  end
2104
1316
  else
2105
1317
  if new_under.is_a?(Array)
2106
- new_under.push(x.under_ruby)
1318
+ new_under.push(x.under_ruby)
2107
1319
  else
2108
- raise Aozora_Error.new("�����ӏ���2�‚̃��r�͂‚����܂���")
1320
+ raise Aozora2Html::Error, I18n.t(:dont_use_double_ruby)
2109
1321
  end
2110
1322
  end
2111
1323
  new_targets.push(x.target)
2112
1324
  end
2113
- elsif x.is_a?(Reference_mentioned_tag)
1325
+ elsif x.is_a?(Aozora2Html::Tag::ReferenceMentioned)
2114
1326
  if x.target.is_a?(Array)
2115
1327
  # recursive
2116
- tar,up,un = rearrange_ruby(x.target,"","")
1328
+ tar,up,un = rearrange_ruby(x.target, "", "")
2117
1329
  # rotation!!
2118
1330
  tar.each{|y|
2119
1331
  tmp = x.dup
@@ -2122,12 +1334,12 @@ class Aozora2Html
2122
1334
  if new_under.is_a?(Array)
2123
1335
  new_under.concat(un)
2124
1336
  elsif un.to_s.length > 0
2125
- raise Aozora_Error.new("�����ӏ���2�‚̃��r�͂‚����܂���")
1337
+ raise Aozora2Html::Error, I18n.t(:dont_use_double_ruby)
2126
1338
  end
2127
1339
  if new_upper.is_a?(Array)
2128
1340
  new_upper.concat(up)
2129
1341
  elsif up.to_s.length > 0
2130
- raise Aozora_Error.new("�����ӏ���2�‚̃��r�͂‚����܂���")
1342
+ raise Aozora2Html::Error, I18n.t(:dont_use_double_ruby)
2131
1343
  end
2132
1344
  else
2133
1345
  new_targets.push(x)
@@ -2153,383 +1365,243 @@ class Aozora2Html
2153
1365
  [targets, upper_ruby, under_ruby]
2154
1366
  end
2155
1367
  end
2156
-
2157
- def exec_style (targets, command)
1368
+
1369
+ def exec_style(targets, command)
2158
1370
  try_kuten = kuten2png(command)
2159
1371
  if try_kuten != command
2160
1372
  try_kuten
2161
- elsif command.match(/�c����/)
2162
- Dir_tag.new(self, targets)
2163
- elsif command.match(/���g��/)
2164
- Inline_yokogumi_tag.new(self, targets)
2165
- elsif command.match(/�r�͂�/)
2166
- Inline_keigakomi_tag.new(self, targets)
2167
- elsif command.match(/�L���v�V����/)
2168
- Inline_caption_tag.new(self, targets)
2169
- elsif command.match(/�Ԃ�_/)
2170
- Kaeriten_tag.new(self, targets)
2171
- elsif command.match(/�P�_���艼��/)
2172
- Okurigana_tag.new(self, targets)
2173
- elsif command.match(/���o��/)
1373
+ elsif command.match(TCY_COMMAND)
1374
+ Aozora2Html::Tag::Dir.new(self, targets)
1375
+ elsif command.match(YOKOGUMI_COMMAND)
1376
+ Aozora2Html::Tag::InlineYokogumi.new(self, targets)
1377
+ elsif command.match(KEIGAKOMI_COMMAND)
1378
+ Aozora2Html::Tag::InlineKeigakomi.new(self, targets)
1379
+ elsif command.match(CAPTION_COMMAND)
1380
+ Aozora2Html::Tag::InlineCaption.new(self, targets)
1381
+ elsif command.match(KAERITEN_COMMAND)
1382
+ Aozora2Html::Tag::Kaeriten.new(self, targets)
1383
+ elsif command.match(KUNTEN_OKURIGANA_COMMAND)
1384
+ Aozora2Html::Tag::Okurigana.new(self, targets)
1385
+ elsif command.match(MIDASHI_COMMAND)
2174
1386
  midashi_type = :normal
2175
- if command.match(/���s/)
1387
+ if command.match(DOGYO_MARK)
2176
1388
  midashi_type = :dogyo
2177
- elsif command.match (/��/)
1389
+ elsif command.match(MADO_MARK)
2178
1390
  midashi_type = :mado
2179
1391
  else
2180
1392
  @terprip = false
2181
1393
  end
2182
- Midashi_tag.new(self, targets, command, midashi_type)
2183
- elsif command.match(/(.*)�i�K(..)�ȕ���/)
2184
- whole, nest, style = command.match(/(.*)�i�K(..)�ȕ���/).to_a
2185
- Inline_font_size_tag.new(self,targets,
2186
- convert_japanese_number(nest).to_i,
2187
- if style.match("��")
2188
- :sho
2189
- else
2190
- :dai
2191
- end)
2192
- elsif command.match(/(��|��)�Ɂu([^�v]*)�v��(���r|���L)/)
2193
- whole, dir, under = command.match(/(��|��)�Ɂu([^�v]*)�v��(���r|���L)/).to_a
2194
- if targets.length == 1 and targets[0].is_a?(Ruby_tag)
1394
+ Aozora2Html::Tag::Midashi.new(self, targets, command, midashi_type)
1395
+ elsif command.match(PAT_CHARSIZE)
1396
+ _whole, nest, style = command.match(PAT_CHARSIZE).to_a
1397
+ Aozora2Html::Tag::InlineFontSize.new(self,targets,
1398
+ Utils.convert_japanese_number(nest).to_i,
1399
+ detect_style_size(style))
1400
+ elsif command.match(PAT_RUBY_DIR)
1401
+ _whole, _dir, under = command.match(PAT_RUBY_DIR).to_a
1402
+ if targets.length == 1 and targets[0].is_a?(Aozora2Html::Tag::Ruby)
2195
1403
  tag = targets[0]
2196
1404
  if tag.under_ruby == ""
2197
1405
  tag.under_ruby = under
2198
1406
  tag
2199
1407
  else
2200
- raise Aozora_Error.new("1�‚̒P���3�‚̃��r�͂‚����܂���")
1408
+ raise Aozora2Html::Error, I18n.t(:dont_allow_triple_ruby)
2201
1409
  end
2202
1410
  else
2203
- rearrange_ruby_tag(targets,"",under)
1411
+ rearrange_ruby_tag(targets, "", under)
2204
1412
  end
2205
- elsif command.match(/�u(.+?)�v�̒��L/)
2206
- rearrange_ruby_tag(targets,/�u(.+?)�v�̒��L/.match(command).to_a[1])
2207
- elsif command.match(/�u(.)�v�̖T�L/)
2208
- rearrange_ruby_tag(targets,multiply( /�u(.)�v�̖T�L/.match(command).to_a[1], target.length))
1413
+ elsif command.match(PAT_CHUUKI)
1414
+ rearrange_ruby_tag(targets, PAT_CHUUKI.match(command).to_a[1])
1415
+ elsif command.match(PAT_BOUKI)
1416
+ rearrange_ruby_tag(targets, multiply(PAT_BOUKI.match(command).to_a[1], targets.to_s.length))
2209
1417
  else
2210
1418
  ## direction fix! ##
2211
1419
  filter = lambda{|x| x}
2212
- if command.match(/(�E|��|��|��)��(.*)/)
2213
- whole, dir, com = command.match(/(�E|��|��|��)��(.*)/).to_a
1420
+ if command.match(PAT_DIRECTION)
1421
+ _whole, dir, com = command.match(PAT_DIRECTION).to_a
2214
1422
  # renew command
2215
1423
  command = com
2216
- if command.match(/�_/)
1424
+ if command.match(TEN_MARK)
2217
1425
  case dir
2218
- when "��", "��"
1426
+ when LEFT_MARK, UNDER_MARK
2219
1427
  filter = lambda{|x| x + "_after"}
2220
1428
  end
2221
- elsif command.match(/��/)
1429
+ elsif command.match(SEN_MARK)
2222
1430
  case dir
2223
- when "��", "��"
1431
+ when LEFT_MARK, OVER_MARK
2224
1432
  filter = lambda{|x| x.sub("under","over")}
2225
1433
  end
2226
1434
  end
2227
1435
  end
2228
-
2229
- found = @@command_table[command]
1436
+
1437
+ found = COMMAND_TABLE[command]
2230
1438
  # found = [class, tag]
2231
1439
  if found
2232
- if found[1] == "em" # or found[1] == "strong"
2233
- @chuuki_table[:em] = true
2234
- end
2235
- Decorate_tag.new(self, targets, filter.call(found[0]), found[1])
1440
+ Aozora2Html::Tag::Decorate.new(self, targets, filter.call(found[0]), found[1])
2236
1441
  else
2237
1442
  nil
2238
1443
  end
2239
1444
  end
2240
1445
  end
2241
1446
 
2242
- def apply_dakuten_katakana (command)
1447
+ def apply_dakuten_katakana(command)
2243
1448
  n = command.match(/1-7-8([2345])/).to_a[1]
2244
- frontref =
2245
- case n
2246
- when "2"
2247
- "���J"
2248
- when "3"
2249
- "���J"
2250
- when "4"
2251
- "���J"
2252
- when "5"
2253
- "���J"
2254
- end
1449
+ frontref = DAKUTEN_KATAKANA_TABLE[n]
2255
1450
  if found = search_front_reference(frontref)
2256
- Dakuten_katakana_tag.new(self, n,found.join)
1451
+ Aozora2Html::Tag::DakutenKatakana.new(self, n,found.join)
2257
1452
  else
2258
1453
  apply_rest_notes(command)
2259
1454
  end
2260
1455
  end
2261
1456
 
1457
+ # くの字点の処理
1458
+ #
1459
+ # くの字点は現状そのまま出力するのでフッタの「表記について」で出力するかどうかのフラグ処理だけ行う
2262
1460
  def assign_kunoji
2263
1461
  second = @stream.peek_char(0)
2264
1462
  case second
2265
- when @@noji
1463
+ when NOJI
2266
1464
  @chuuki_table[:kunoji] = true
2267
- when @@dakuten
2268
- if @stream.peek_char(1) == @@noji
1465
+ when DAKUTEN
1466
+ if @stream.peek_char(1) == NOJI
2269
1467
  @chuuki_table[:dakutenkunoji] = true
2270
1468
  end
2271
1469
  end
2272
1470
  end
2273
1471
 
2274
- def apply_rest_notes (command)
1472
+ def apply_rest_notes(command)
2275
1473
  @chuuki_table[:chuki] = true
2276
- Editor_note_tag.new(self, command)
1474
+ Aozora2Html::Tag::EditorNote.new(self, command)
2277
1475
  end
2278
1476
 
2279
- # �b�������Ƃ��͕�����𖳎�����ruby_buf�����Ȃ��Ⴂ���Ȃ�
1477
+ # |が来たときは文字種を無視してruby_bufを守らなきゃいけない
2280
1478
  def apply_ruby
2281
- @ruby_buf_protected = nil
2282
- ruby,raw = read_to_nest("�t")
1479
+ @ruby_buf.protected = nil
1480
+ ruby, _raw = read_to_nest(RUBY_END_MARK)
2283
1481
  if ruby.length == 0
2284
1482
  # escaped ruby character
2285
- return "�s�t"
1483
+ return RUBY_BEGIN_MARK+RUBY_END_MARK
2286
1484
  end
2287
1485
  ans = ""
2288
1486
  notes = []
2289
- @ruby_buf.each{|token|
2290
- if token.is_a?(UnEmbed_Gaiji_tag)
2291
- ans.concat("��")
1487
+ @ruby_buf.each do |token|
1488
+ if token.is_a?(Aozora2Html::Tag::UnEmbedGaiji)
1489
+ ans.concat(GAIJI_MARK)
2292
1490
  token.escape!
2293
1491
  notes.push(token)
2294
1492
  else
2295
1493
  ans.concat(token.to_s)
2296
- end}
2297
- @buffer.push(Ruby_tag.new(self, ans, ruby))
2298
- @buffer = @buffer + notes
2299
- @ruby_buf = [""]
1494
+ end
1495
+ end
1496
+ @buffer.push(Aozora2Html::Tag::Ruby.new(self, ans, ruby))
1497
+ @buffer += notes
1498
+ @ruby_buf.clear
2300
1499
  nil
2301
1500
  end
2302
1501
 
1502
+ # parse_bodyのフッタ版
2303
1503
  def parse_tail
2304
1504
  char = read_char
2305
1505
  check = true
2306
1506
  case char
2307
- when "�k"
1507
+ when ACCENT_BEGIN
2308
1508
  check = false
2309
1509
  char = read_accent
2310
1510
  when @endchar
2311
- throw :terminate
2312
- when "��"
1511
+ throw :terminate
1512
+ when GAIJI_MARK
2313
1513
  char = dispatch_gaiji
2314
- when "�m"
1514
+ when COMMAND_BEGIN
2315
1515
  char = dispatch_aozora_command
2316
- when @@ku
2317
- assign_kunoji
2318
- when "�s"
1516
+ when KU
1517
+ assign_kunoji
1518
+ when RUBY_BEGIN_MARK
2319
1519
  char = apply_ruby
2320
1520
  end
2321
- if char == "\r\n"
1521
+
1522
+ case char
1523
+ when "\r\n"
2322
1524
  tail_output
2323
- elsif char == "�b"
2324
- ruby_buf_dump
2325
- @ruby_buf_protected = true
2326
- elsif char != nil
1525
+ when RUBY_PREFIX
1526
+ @ruby_buf.dump_into(@buffer)
1527
+ @ruby_buf.protected = true
1528
+ when nil
1529
+ # noop
1530
+ else
2327
1531
  if check
2328
- illegal_char_check(char)
1532
+ illegal_char_check(char, line_number)
2329
1533
  end
2330
1534
  push_chars(char)
2331
1535
  end
2332
1536
  end
2333
1537
 
1538
+ # general_outputのフッタ版
2334
1539
  def tail_output
2335
- ruby_buf_dump
1540
+ @ruby_buf.dump_into(@buffer)
2336
1541
  string = @buffer.join
2337
- @ruby_buf = [""]; @ruby_buf_mode = nil; @buffer = []
1542
+ @ruby_buf.clear
1543
+ @buffer = []
2338
1544
  string.gsub!("info@aozora.gr.jp",'<a href="mailto: info@aozora.gr.jp">info@aozora.gr.jp</a>')
2339
- string.gsub!("�‹󕶌Ɂihttp://www.aozora.gr.jp/�j"){"<a href=\"http://www.aozora.gr.jp/\">#{$&}</a>"}
1545
+ string.gsub!("青空文庫(http://www.aozora.gr.jp/)".to_sjis){"<a href=\"http://www.aozora.gr.jp/\">#{$&}</a>"}
2340
1546
  if string.match(/(<br \/>$|<\/p>$|<\/h\d>$|<div.*>$|<\/div>$|^<[^>]*>$)/)
2341
1547
  @out.print string, "\r\n"
2342
1548
  else
2343
1549
  @out.print string, "<br />\r\n"
2344
1550
  end
2345
1551
  end
2346
-
2347
- def hyoki ()
1552
+
1553
+ # `●表記について`で使用した注記等を出力する
1554
+ def hyoki
2348
1555
  # <br /> times fix
2349
- @out.print "<br />\r\n</div>\r\n<div class=\"notation_notes\">\r\n<hr />\r\n<br />\r\n���\�L�ɂ‚���<br />\r\n<ul>\r\n"
2350
- @out.print "\t<li>���̃t�@�C���� W3C ���� XHTML1.1 �ɂ������`���ō쐬����Ă��܂��B</li>\r\n"
1556
+ @out.print "<br />\r\n</div>\r\n<div class=\"notation_notes\">\r\n<hr />\r\n<br />\r\n●表記について<br />\r\n<ul>\r\n".to_sjis
1557
+ @out.print "\t<li>このファイルは W3C 勧告 XHTML1.1 にそった形式で作成されています。</li>\r\n".to_sjis
2351
1558
  if @chuuki_table[:chuki]
2352
- @out.print "\t<li>�m���c�n�́A���͎҂ɂ�钍��\���L���ł��B</li>\r\n"
1559
+ @out.print "\t<li>[#…]は、入力者による注を表す記号です。</li>\r\n".to_sjis
2353
1560
  end
2354
1561
  if @chuuki_table[:kunoji]
2355
1562
  if @chuuki_table[:dakutenkunoji]
2356
- @out.print "\t<li>�u���̎��_�v�́u#{@@ku}#{@@noji}�v�ŁA�u���_�t�����̎��_�v�́u#{@@ku}#{@@dakuten}#{@@noji}�v�ŕ\���܂����B</li>\r\n"
1563
+ @out.printf("\t<li>「くの字点」は「%s」で、「濁点付きくの字点」は「%s」で表しました。</li>\r\n".to_sjis, KU+NOJI, KU+DAKUTEN+NOJI)
2357
1564
  else
2358
- @out.print "\t<li>�u���̎��_�v�́u#{@@ku}#{@@noji}�v�ŕ\���܂����B</li>\r\n"
1565
+ @out.printf("\t<li>「くの字点」は「%s」で表しました。</li>\r\n".to_sjis, KU+NOJI)
2359
1566
  end
2360
1567
  elsif @chuuki_table[:dakutenkunoji]
2361
- @out.print "\t<li>�u���_�t�����̎��_�v�́u#{@@ku}#{@@dakuten}#{@@noji}�v�ŕ\���܂����B</li>\r\n"
1568
+ @out.printf("\t<li>「濁点付きくの字点」は「%s」で表しました。</li>\r\n".to_sjis, KU+DAKUTEN+NOJI)
2362
1569
  end
2363
- if @chuuki_table[:newjis]
2364
- @out.print "\t<li>�u���̎��_�v���̂���JIS X 0213�ɂ��镶���́A�摜�����Ė��ߍ��݂܂����B</li>\r\n"
1570
+ if @chuuki_table[:newjis] && !Aozora2Html::Tag::EmbedGaiji.use_jisx0213
1571
+ @out.print "\t<li>「くの字点」をのぞくJIS X 0213にある文字は、画像化して埋め込みました。</li>\r\n".to_sjis
2365
1572
  end
2366
- if @chuuki_table[:accent]
2367
- @out.print "\t<li>�A�N�Z���g�����t�����e�������́A�摜�����Ė��ߍ��݂܂����B</li>\r\n"
1573
+ if @chuuki_table[:accent] && !Aozora2Html::Tag::Accent.use_jisx0213
1574
+ @out.print "\t<li>アクセント符号付きラテン文字は、画像化して埋め込みました。</li>\r\n".to_sjis
2368
1575
  end
2369
- # if @chuuki_table[:em]
2370
- # @out.print "\t<li>�T�_�⌗�_�A�T���̕t���������́A�����\���ɂ��܂����B</li>\r\n"
2371
- # end
2372
1576
  if @images[0]
2373
- @out.print "\t<li>���̍�i�ɂ́AJIS X 0213�ɂȂ��A�ȉ��̕������p�����Ă��܂��B�i�����́A��{���̏o���u�y�[�W-�s�v���B�j�����̕����͖{�����ł́u���m���c�n�v�̌`�Ŏ����܂����B</li>\r\n</ul>\r\n<br />\r\n\t\t<table class=\"gaiji_list\">\r\n"
1577
+ @out.print "\t<li>この作品には、JIS X 0213にない、以下の文字が用いられています。(数字は、底本中の出現「ページ-行」数。)これらの文字は本文内では「※[#…]」の形で示しました。</li>\r\n</ul>\r\n<br />\r\n\t\t<table class=\"gaiji_list\">\r\n".to_sjis
2374
1578
  @images.each{|cell|
2375
1579
  k,*v = cell
1580
+ vs = v.join("、".to_sjis)
2376
1581
  @out.print " <tr>
2377
1582
  <td>
2378
1583
  #{k}
2379
1584
  </td>
2380
1585
  <td>&nbsp;&nbsp;</td>
2381
1586
  <td>
2382
- #{v.join("�A")} </td>
1587
+ #{vs} </td>
2383
1588
  <!--
2384
1589
  <td>
2385
- �@�@<img src=\"../../../gaiji/others/xxxx.png\" alt=\"#{k}\" width=32 height=32 />
1590
+ <img src=\"../../../gaiji/others/xxxx.png\" alt=\"#{k}\" width=32 height=32 />
2386
1591
  </td>
2387
1592
  -->
2388
1593
  </tr>
2389
- "
1594
+ ".to_sjis
2390
1595
  }
2391
- @out.print "\t\t</table>\r\n"
1596
+ @out.print "\t\t</table>\r\n".to_sjis
2392
1597
  else
2393
- @out.print "</ul>\r\n" # <ul>����<li>�ȊO�̃G�������g������͕̂s���Ȃ̂ŏC��
1598
+ @out.print "</ul>\r\n" # <ul>内に<li>以外のエレメントが来るのは不正なので修正
2394
1599
  end
2395
1600
  @out.print "</div>\r\n"
2396
1601
  end
2397
1602
  end
2398
1603
 
2399
- # �‹�L�@�̓���q�ɑΉ��i�H�j
2400
- class Aozora_tag_parser < Aozora2Html
2401
- def initialize (input, endchar, chuuki, image)
2402
- if not(input.is_a?(Jstream))
2403
- raise ArgumentError, "tag_parser must supply Jstream as input"
2404
- end
2405
- @stream = input;
2406
- @buffer = []; @ruby_buf = [""]; @ruby_char_type = nil
2407
- @chuuki_table = chuuki; @images = image; # global�Ȋ‹����L�^����A�C�e���͋��L����K�v����
2408
- @endchar = endchar # ���s���z����ׂ����ۂ��c
2409
- @section = :tail # ���������ƋL�@���̓C���f���g�����Ȃ��̂œ���
2410
- @raw = "" # �O���ϊ��O�̐��e�L�X�g���c���������Ƃ�����炵��
2411
- end
2412
-
2413
- def read_char # method override!
2414
- c = @stream.read_char
2415
- @raw.concat(c)
2416
- c
2417
- end
2418
-
2419
- def read_to_nest(endchar)
2420
- ans = super(endchar)
2421
- @raw.concat(ans[1])
2422
- ans
2423
- end
2424
-
2425
- def general_output # �o�͂�[String,String]�Ԃ��ŁI
2426
- ruby_buf_dump
2427
- ans=""
2428
- @buffer.each{|s|
2429
- if s.is_a?(UnEmbed_Gaiji_tag) and not(s.escaped?)
2430
- # �����Ă��������𕜊�������
2431
- ans.concat("��")
2432
- end
2433
- ans.concat(s.to_s)
2434
- }
2435
- [ans,@raw]
2436
- end
2437
-
2438
- def process ()
2439
- catch(:terminate){
2440
- loop{
2441
- parse
2442
- }
2443
- }
2444
- general_output
2445
- end
2446
- end
2447
-
2448
- # accent���ꕶ���𐶂������߂̍ċA�Ăяo��
2449
- class Aozora_accent_parser < Aozora2Html
2450
- def initialize (input, endchar, chuuki, image)
2451
- if not(input.is_a?(Jstream))
2452
- raise ArgumentError, "tag_parser must supply Jstream as input"
2453
- end
2454
- @stream = input
2455
- @buffer = []; @ruby_buf = [""]; @ruby_char_type = nil
2456
- @chuuki_table = chuuki; @images = image; # global�Ȋ‹����L�^����A�C�e���͋��L����K�v����
2457
- @endchar = endchar # ���s�͉z�����Ȃ� <br />���o�͂��Ă����Ȃ�
2458
- @closed = nil # ���s�ł̋����P�ރ`�F�b�N�t���O
2459
- @encount_accent = nil
2460
- end
2461
-
2462
- def general_output # �o�͔͂z��ŕԂ�
2463
- ruby_buf_dump
2464
- if not(@encount_accent)
2465
- @buffer.unshift("�k")
2466
- end
2467
- if @closed and not(@encount_accent)
2468
- @buffer.push("�l")
2469
- elsif not(@closed)
2470
- @buffer.push("<br />\r\n")
2471
- end
2472
- @buffer
2473
- end
2474
-
2475
- def parse
2476
- first = read_char
2477
- if found = @@accent_table[first]
2478
- if found2 = found[@stream.peek_char(0)]
2479
- if found2.is_a?(Hash)
2480
- if found3 = found2[@stream.peek_char(1)]
2481
- first = Accent_tag.new(self, *found3)
2482
- @encount_accent = true
2483
- @chuuki_table[:accent] = true
2484
- read_char
2485
- read_char
2486
- end
2487
- elsif found2
2488
- first = Accent_tag.new(self, *found2)
2489
- @encount_accent = true
2490
- read_char
2491
- @chuuki_table[:accent] = true
2492
- end
2493
- end
2494
- end
2495
- case first
2496
- when "��"
2497
- first = dispatch_gaiji
2498
- when "�m"
2499
- first = dispatch_aozora_command
2500
- when @@ku
2501
- assign_kunoji
2502
- when "�s"
2503
- first = apply_ruby
2504
- end
2505
- if first == "\r\n"
2506
- if @encount_accent
2507
- puts "�x��(#{scount}�s��):�A�N�Z���g�����̋T�b���ʂ̎n�߂ƏI��肪�A�s���ő����Ă��܂���"
2508
- end
2509
- throw :terminate
2510
- elsif first == "�l"
2511
- @closed = true
2512
- throw :terminate
2513
- elsif first == "�b"
2514
- ruby_buf_dump
2515
- @ruby_buf_protected = true
2516
- elsif first != "" and first != nil
2517
- illegal_char_check(first)
2518
- push_chars(first)
2519
- end
2520
- end
2521
-
2522
- def process ()
2523
- catch(:terminate){
2524
- loop{
2525
- parse
2526
- }
2527
- }
2528
- general_output
2529
- end
2530
- end
2531
-
2532
1604
  if $0 == __FILE__
2533
- # todo: �����`�F�b�N�Ƃ�
1605
+ # todo: 引数チェックとか
2534
1606
  Aozora2Html.new($*[0],$*[1]).process
2535
1607
  end