aozora2html 0.7.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/rubocop.yml +19 -0
- data/.github/workflows/ruby.yml +37 -0
- data/.gitignore +8 -3
- data/.rubocop.yml +111 -0
- data/.rubocop_todo.yml +7 -0
- data/CHANGELOG.md +59 -0
- data/Gemfile +2 -0
- data/Guardfile +3 -1
- data/HACKING.md +45 -0
- data/LICENSE +116 -0
- data/README.md +29 -16
- data/Rakefile +12 -5
- data/aozora2html.gemspec +24 -24
- data/bin/aozora2html +25 -71
- data/lib/aozora2html/accent_parser.rb +99 -0
- data/lib/aozora2html/error.rb +17 -0
- data/lib/aozora2html/header.rb +141 -0
- data/lib/aozora2html/i18n.rb +48 -0
- data/lib/aozora2html/ruby_buffer.rb +116 -0
- data/lib/aozora2html/string_refinements.rb +36 -0
- data/lib/aozora2html/style_stack.rb +33 -0
- data/lib/aozora2html/tag/accent.rb +37 -0
- data/lib/aozora2html/tag/block.rb +21 -0
- data/lib/aozora2html/tag/chitsuki.rb +19 -0
- data/lib/aozora2html/tag/dakuten_katakana.rb +25 -0
- data/lib/aozora2html/tag/decorate.rb +19 -0
- data/lib/aozora2html/tag/dir.rb +17 -0
- data/lib/aozora2html/tag/editor_note.rb +19 -0
- data/lib/aozora2html/tag/embed_gaiji.rb +52 -0
- data/lib/aozora2html/tag/font_size.rb +20 -0
- data/lib/aozora2html/tag/gaiji.rb +12 -0
- data/lib/aozora2html/tag/img.rb +21 -0
- data/lib/aozora2html/tag/indent.rb +8 -0
- data/lib/aozora2html/tag/inline.rb +16 -0
- data/lib/aozora2html/tag/inline_caption.rb +17 -0
- data/lib/aozora2html/tag/inline_font_size.rb +19 -0
- data/lib/aozora2html/tag/inline_keigakomi.rb +17 -0
- data/lib/aozora2html/tag/inline_yokogumi.rb +17 -0
- data/lib/aozora2html/tag/jisage.rb +17 -0
- data/lib/aozora2html/tag/jizume.rb +19 -0
- data/lib/aozora2html/tag/kaeriten.rb +17 -0
- data/lib/aozora2html/tag/keigakomi.rb +19 -0
- data/lib/aozora2html/tag/kunten.rb +12 -0
- data/lib/aozora2html/tag/midashi.rb +20 -0
- data/lib/aozora2html/tag/multiline.rb +9 -0
- data/lib/aozora2html/tag/multiline_caption.rb +13 -0
- data/lib/aozora2html/tag/multiline_chitsuki.rb +10 -0
- data/lib/aozora2html/tag/multiline_jisage.rb +10 -0
- data/lib/aozora2html/tag/multiline_midashi.rb +25 -0
- data/lib/aozora2html/tag/multiline_style.rb +19 -0
- data/lib/aozora2html/tag/multiline_yokogumi.rb +14 -0
- data/lib/aozora2html/tag/okurigana.rb +17 -0
- data/lib/aozora2html/tag/oneline_chitsuki.rb +10 -0
- data/lib/aozora2html/tag/oneline_indent.rb +9 -0
- data/lib/aozora2html/tag/oneline_jisage.rb +10 -0
- data/lib/aozora2html/tag/reference_mentioned.rb +47 -0
- data/lib/aozora2html/tag/ruby.rb +202 -0
- data/lib/aozora2html/tag/un_embed_gaiji.rb +30 -0
- data/lib/aozora2html/tag.rb +57 -0
- data/lib/aozora2html/tag_parser.rb +60 -0
- data/lib/aozora2html/text_buffer.rb +50 -0
- data/lib/aozora2html/utils.rb +156 -0
- data/lib/aozora2html/version.rb +3 -1
- data/lib/aozora2html/yaml_loader.rb +37 -0
- data/lib/aozora2html/zip.rb +4 -0
- data/lib/aozora2html.rb +1359 -8
- data/lib/extensions.rb +12 -0
- data/lib/jstream.rb +139 -0
- data/sample/chukiichiran_kinyurei.html +15 -2
- data/sample/chukiichiran_kinyurei.txt +15 -2
- data/test/test_aozora2html.rb +323 -73
- data/test/test_aozora_accent_parser.rb +34 -6
- data/test/test_command_parse.rb +216 -0
- data/test/test_compat.rb +3 -4
- data/test/test_dakuten_katakana_tag.rb +12 -13
- data/test/test_decorate_tag.rb +11 -7
- data/test/test_dir_tag.rb +11 -7
- data/test/test_editor_note_tag.rb +9 -6
- data/test/test_exception.rb +11 -9
- data/test/test_font_size_tag.rb +22 -11
- data/test/test_gaiji_tag.rb +22 -14
- data/test/test_header.rb +45 -0
- data/test/test_helper.rb +3 -1
- data/test/test_i18n.rb +39 -0
- data/test/test_img_tag.rb +11 -6
- data/test/test_inline_caption_tag.rb +11 -7
- data/test/test_inline_font_size_tag.rb +15 -11
- data/test/test_inline_keigakomi_tag.rb +11 -7
- data/test/test_inline_yokogumi_tag.rb +11 -7
- data/test/test_jizume_tag.rb +11 -8
- data/test/test_jstream.rb +33 -30
- data/test/test_kaeriten_tag.rb +11 -7
- data/test/test_keigakomi_tag.rb +14 -11
- data/test/test_midashi_tag.rb +39 -0
- data/test/test_multiline_caption_tag.rb +11 -8
- data/test/test_multiline_midashi_tag.rb +26 -26
- data/test/test_multiline_style_tag.rb +11 -8
- data/test/test_multiline_yokogumi_tag.rb +11 -8
- data/test/test_okurigana_tag.rb +11 -7
- data/test/test_ruby_parse.rb +130 -0
- data/test/test_ruby_tag.rb +11 -7
- data/test/test_tag_parser.rb +31 -29
- data/vendor/jis2ucs/README.md +3 -6
- data/yml/accent_table.yml +240 -0
- data/yml/command_table.yml +61 -0
- data/yml/jis2ucs.yml +11234 -0
- metadata +99 -21
- data/.travis.yml +0 -12
- data/appveyor.yml +0 -23
- data/lib/accent_tag.rb +0 -23
- data/lib/aozora2html/jis2ucs.rb +0 -11237
- data/lib/embed_gaiji_tag.rb +0 -34
- data/lib/t2hs.rb +0 -2535
data/lib/t2hs.rb
DELETED
@@ -1,2535 +0,0 @@
|
|
1
|
-
# -*- coding:shift_jis -*-
|
2
|
-
# �Ɍ`���̃e�L�X�g�t�@�C���� html �ɐ��`���� ruby �X�N���v�g
|
3
|
-
require "cgi"
|
4
|
-
|
5
|
-
$gaiji_dir = "../../../gaiji/"
|
6
|
-
|
7
|
-
$css_files = Array["../../aozora.css"]
|
8
|
-
|
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
|
358
|
-
|
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
|
398
|
-
|
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
|
451
|
-
|
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
|
469
|
-
|
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
|
473
|
-
|
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
|
-
}
|
496
|
-
else
|
497
|
-
ans.concat("<rb>#{@target.to_s}</rb>")
|
498
|
-
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
|
513
|
-
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*").force_encoding("shift_jis")
|
673
|
-
@@noji = ["18f5"].pack("h*").force_encoding("shift_jis")
|
674
|
-
@@dakuten = ["18d8"].pack("h*").force_encoding("shift_jis")
|
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
|
824
|
-
@stream.line
|
825
|
-
end
|
826
|
-
|
827
|
-
def block_allowed_context?
|
828
|
-
# inline_tag���J���Ă��Ȃ����`�F�b�N����Ώ\��
|
829
|
-
not(@style_stack.last)
|
830
|
-
end
|
831
|
-
|
832
|
-
def read_char
|
833
|
-
@stream.read_char
|
834
|
-
end
|
835
|
-
|
836
|
-
def read_to (endchar)
|
837
|
-
buf=""
|
838
|
-
loop{
|
839
|
-
char=@stream.read_char
|
840
|
-
if char==endchar
|
841
|
-
break
|
842
|
-
else
|
843
|
-
if char.kind_of?(Symbol)
|
844
|
-
print endchar
|
845
|
-
end
|
846
|
-
buf.concat(char)
|
847
|
-
end}
|
848
|
-
buf
|
849
|
-
end
|
850
|
-
|
851
|
-
def read_accent
|
852
|
-
Aozora_accent_parser.new(@stream,"�l",@chuuki_table,@images).process
|
853
|
-
end
|
854
|
-
|
855
|
-
def read_to_nest (endchar)
|
856
|
-
Aozora_tag_parser.new(@stream,endchar,@chuuki_table,@images).process
|
857
|
-
end
|
858
|
-
|
859
|
-
def read_line
|
860
|
-
tmp=read_to("\r\n")
|
861
|
-
@buffer=[]
|
862
|
-
tmp
|
863
|
-
end
|
864
|
-
|
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)
|
874
|
-
end
|
875
|
-
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
|
907
|
-
:else
|
908
|
-
end
|
909
|
-
end
|
910
|
-
|
911
|
-
def finalize ()
|
912
|
-
hyoki
|
913
|
-
dynamic_contents
|
914
|
-
@out.print("</body>\r\n</html>\r\n")
|
915
|
-
end
|
916
|
-
|
917
|
-
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>")
|
923
|
-
end
|
924
|
-
|
925
|
-
def close ()
|
926
|
-
@stream.close
|
927
|
-
@out.close
|
928
|
-
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
|
953
|
-
end
|
954
|
-
|
955
|
-
def check_close_match (type)
|
956
|
-
ind = if @indent_stack.last.is_a?(String)
|
957
|
-
@noprint = true
|
958
|
-
:jisage
|
959
|
-
else
|
960
|
-
@indent_stack.last
|
961
|
-
end
|
962
|
-
if ind == type
|
963
|
-
nil
|
964
|
-
else
|
965
|
-
convert_indent_type(type)
|
966
|
-
end
|
967
|
-
end
|
968
|
-
|
969
|
-
def implicit_close (type)
|
970
|
-
if @indent_stack.last
|
971
|
-
if n = check_close_match(type)
|
972
|
-
# ok, nested multiline tags, go ahead
|
973
|
-
else
|
974
|
-
# not nested, please close
|
975
|
-
@indent_stack.pop
|
976
|
-
if tag = @tag_stack.pop
|
977
|
-
push_chars(tag)
|
978
|
-
end
|
979
|
-
end
|
980
|
-
end
|
981
|
-
end
|
982
|
-
|
983
|
-
def ensure_close
|
984
|
-
if n = @indent_stack.last
|
985
|
-
raise Aozora_Error.new("#{convert_indent_type(n)}���ɖ{�����I�����܂���")
|
986
|
-
end
|
987
|
-
end
|
988
|
-
|
989
|
-
def explicit_close (type)
|
990
|
-
if n = check_close_match(type)
|
991
|
-
raise Aozora_Error.new("#{n}����悤�Ƃ��܂������A#{n}���ł͂���܂���")
|
992
|
-
end
|
993
|
-
if tag = @tag_stack.pop
|
994
|
-
push_chars(tag)
|
995
|
-
end
|
996
|
-
end
|
997
|
-
|
998
|
-
# main loop
|
999
|
-
def parse
|
1000
|
-
case @section
|
1001
|
-
when :head
|
1002
|
-
parse_header
|
1003
|
-
when :head_end
|
1004
|
-
judge_chuuki
|
1005
|
-
when :chuuki, :chuuki_in
|
1006
|
-
parse_chuuki
|
1007
|
-
when :body
|
1008
|
-
parse_body
|
1009
|
-
when :tail
|
1010
|
-
parse_tail
|
1011
|
-
else
|
1012
|
-
Aozora_Error.new("encount undefined condition")
|
1013
|
-
end
|
1014
|
-
end
|
1015
|
-
|
1016
|
-
def judge_chuuki
|
1017
|
-
# ���L�����邩�ǂ����`�F�b�N
|
1018
|
-
i=0
|
1019
|
-
loop{
|
1020
|
-
case @stream.peek_char(i)
|
1021
|
-
when "-"
|
1022
|
-
i=i+1
|
1023
|
-
when "\r\n"
|
1024
|
-
@section = :chuuki
|
1025
|
-
return
|
1026
|
-
else
|
1027
|
-
@section = :body
|
1028
|
-
@out.print("<br />\r\n")
|
1029
|
-
return
|
1030
|
-
end
|
1031
|
-
}
|
1032
|
-
end
|
1033
|
-
|
1034
|
-
# header�͈�s���ǂ�
|
1035
|
-
def parse_header
|
1036
|
-
string = read_line
|
1037
|
-
# refine from Tomita 09/06/14
|
1038
|
-
if (string == "") # ��s������A�����Ńw�b�_�[�I���Ƃ݂Ȃ�
|
1039
|
-
@section = :head_end
|
1040
|
-
process_header
|
1041
|
-
else
|
1042
|
-
string.gsub!(/�b/,"")
|
1043
|
-
string.gsub!(/�s.*?�t/,"")
|
1044
|
-
@header.push(string)
|
1045
|
-
end
|
1046
|
-
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
|
-
|
1178
|
-
def parse_chuuki
|
1179
|
-
string = read_line
|
1180
|
-
if (string.match(/^\-+$/))
|
1181
|
-
case @section
|
1182
|
-
when :chuuki
|
1183
|
-
@section = :chuuki_in
|
1184
|
-
when :chuuki_in
|
1185
|
-
@section = :body
|
1186
|
-
end
|
1187
|
-
end
|
1188
|
-
end
|
1189
|
-
|
1190
|
-
def illegal_char_check (char)
|
1191
|
-
if char.is_a?(String)
|
1192
|
-
code = char.unpack("H*")[0]
|
1193
|
-
if code == "21" or
|
1194
|
-
code == "23" or
|
1195
|
-
("a1" <= code and code <= "a5") or
|
1196
|
-
("28" <= code and code<= "29") or
|
1197
|
-
code == "5b" or
|
1198
|
-
code == "5d" or
|
1199
|
-
code == "3d" or
|
1200
|
-
code == "3f" or
|
1201
|
-
code == "2b" or
|
1202
|
-
("7b" <= code and code <= "7d")
|
1203
|
-
puts "�x��(#{scount}�s��):1�o�C�g�́u#{char}�v���g���Ă��܂�"
|
1204
|
-
end
|
1205
|
-
|
1206
|
-
if code == "81f2"
|
1207
|
-
puts "�x��(#{scount}�s��):���L�L���̌�p�̉\��������A�u#{char}�v���g���Ă��܂�"
|
1208
|
-
end
|
1209
|
-
|
1210
|
-
if ("81ad" <= code and code <= "81b7") or
|
1211
|
-
("81c0" <= code and code <= "81c7") or
|
1212
|
-
("81cf" <= code and code <= "81d9") or
|
1213
|
-
("81e9" <= code and code <= "81ef") or
|
1214
|
-
("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
|
1218
|
-
("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
|
1223
|
-
("8461" <= code and code <= "846f") or
|
1224
|
-
("8492" <= code and code <= "849e") or
|
1225
|
-
("84bf" <= code and code <= "84fc") or
|
1226
|
-
("8540" <= code and code <= "85fc") or
|
1227
|
-
("8640" <= code and code <= "86fc") or
|
1228
|
-
("8740" <= code and code <= "87fc") or
|
1229
|
-
("8840" <= code and code <= "889e") or
|
1230
|
-
("9873" <= code and code <= "989e") or
|
1231
|
-
("eaa5" <= code and code <= "eafc") or
|
1232
|
-
("eb40" <= code and code <= "ebfc") or
|
1233
|
-
("ec40" <= code and code <= "ecfc") or
|
1234
|
-
("ed40" <= code and code <= "edfc") or
|
1235
|
-
("ee40" <= code and code <= "eefc") or
|
1236
|
-
("ef40" <= code and code <= "effc")
|
1237
|
-
puts "�x��(#{scount}�s��):JIS�O���u#{char}�v���g���Ă��܂�"
|
1238
|
-
end
|
1239
|
-
end
|
1240
|
-
end
|
1241
|
-
|
1242
|
-
# �{�̉�͕�
|
1243
|
-
# 1�������ǂݍ��݁Adispatch����@buffer,@ruby_buf�ւ��܂�
|
1244
|
-
# ���s�R�[�h�ɓ��������痭�ߍ����̂�general_output����
|
1245
|
-
|
1246
|
-
def parse_body
|
1247
|
-
char = read_char
|
1248
|
-
check = true
|
1249
|
-
case char
|
1250
|
-
when "�k"
|
1251
|
-
check = false
|
1252
|
-
char = read_accent
|
1253
|
-
when "��"
|
1254
|
-
if @buffer.length == 0
|
1255
|
-
ending_check
|
1256
|
-
end
|
1257
|
-
when "��"
|
1258
|
-
char = dispatch_gaiji
|
1259
|
-
when "�m"
|
1260
|
-
char = dispatch_aozora_command
|
1261
|
-
when @@ku
|
1262
|
-
assign_kunoji
|
1263
|
-
when "�s"
|
1264
|
-
char = apply_ruby
|
1265
|
-
end
|
1266
|
-
if char == "\r\n"
|
1267
|
-
general_output
|
1268
|
-
elsif char == "�b"
|
1269
|
-
ruby_buf_dump
|
1270
|
-
@ruby_buf_protected = true
|
1271
|
-
elsif char == @endchar
|
1272
|
-
# suddenly finished the file
|
1273
|
-
puts "�x��(#{scount}�s��):�\�����ʃt�@�C���I�["
|
1274
|
-
throw :terminate
|
1275
|
-
elsif char != nil
|
1276
|
-
if check
|
1277
|
-
illegal_char_check(char)
|
1278
|
-
end
|
1279
|
-
push_chars(char)
|
1280
|
-
end
|
1281
|
-
end
|
1282
|
-
|
1283
|
-
def ending_check
|
1284
|
-
if @stream.peek_char(0) == "�{" and @stream.peek_char(1) == "�F"
|
1285
|
-
@section = :tail
|
1286
|
-
ensure_close
|
1287
|
-
@out.print "</div>\r\n<div class=\"bibliographical_information\">\r\n<hr />\r\n<br />\r\n"
|
1288
|
-
end
|
1289
|
-
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
|
-
|
1307
|
-
def push_chars (obj)
|
1308
|
-
if obj.is_a?(Array)
|
1309
|
-
obj.each{|x|
|
1310
|
-
push_chars(x)
|
1311
|
-
}
|
1312
|
-
elsif obj.is_a?(String)
|
1313
|
-
if obj.length == 1
|
1314
|
-
obj = CGI.escapeHTML(obj)
|
1315
|
-
end
|
1316
|
-
obj.each_char{|x|
|
1317
|
-
push_char(x)
|
1318
|
-
}
|
1319
|
-
else
|
1320
|
-
push_char(obj)
|
1321
|
-
end
|
1322
|
-
end
|
1323
|
-
|
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)
|
1329
|
-
else
|
1330
|
-
@ruby_buf.push(char)
|
1331
|
-
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)
|
1336
|
-
else
|
1337
|
-
@ruby_buf.push(char)
|
1338
|
-
@ruby_buf.push("")
|
1339
|
-
end
|
1340
|
-
else
|
1341
|
-
ruby_buf_dump
|
1342
|
-
@ruby_buf_type = ctype
|
1343
|
-
@ruby_buf = [char]
|
1344
|
-
end
|
1345
|
-
end
|
1346
|
-
|
1347
|
-
def buf_is_blank? (buf)
|
1348
|
-
buf.each{|token|
|
1349
|
-
if token.is_a?(String) and not(token=="")
|
1350
|
-
return false
|
1351
|
-
elsif token.is_a?(Oneline_Indent_tag)
|
1352
|
-
return :inline
|
1353
|
-
end
|
1354
|
-
}
|
1355
|
-
true
|
1356
|
-
end
|
1357
|
-
|
1358
|
-
def terpri? (buf)
|
1359
|
-
flag = true
|
1360
|
-
buf.each{|x|
|
1361
|
-
if x.is_a?(Multiline_tag)
|
1362
|
-
flag = false
|
1363
|
-
elsif (x.is_a?(String) and x == "")
|
1364
|
-
nil
|
1365
|
-
else
|
1366
|
-
return true
|
1367
|
-
end
|
1368
|
-
}
|
1369
|
-
flag
|
1370
|
-
end
|
1371
|
-
|
1372
|
-
def general_output
|
1373
|
-
if @style_stack.last
|
1374
|
-
raise Aozora_Error.new("#{@style_stack.last[0]}���ɉ��s����܂����B���s���܂����v�f�ɂ̓u���b�N�\�L��p���Ă�������")
|
1375
|
-
end
|
1376
|
-
# buffer�ɃC���f���g�^�O����������������s���Ȃ��I
|
1377
|
-
if @noprint
|
1378
|
-
@noprint = false
|
1379
|
-
return
|
1380
|
-
end
|
1381
|
-
ruby_buf_dump
|
1382
|
-
buf = @buffer
|
1383
|
-
@ruby_buf = [""]; @ruby_buf_mode = nil; @buffer = []
|
1384
|
-
tail = []
|
1385
|
-
|
1386
|
-
indent_type = buf_is_blank?(buf)
|
1387
|
-
terprip = (terpri?(buf) and @terprip)
|
1388
|
-
@terprip = true
|
1389
|
-
|
1390
|
-
if @indent_stack.last.is_a?(String) and not(indent_type)
|
1391
|
-
@out.print @indent_stack.last
|
1392
|
-
end
|
1393
|
-
|
1394
|
-
buf.each{|s|
|
1395
|
-
if s.is_a?(Oneline_Indent_tag)
|
1396
|
-
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")
|
1402
|
-
end
|
1403
|
-
@out.print s.to_s
|
1404
|
-
}
|
1405
|
-
if @indent_stack.last.is_a?(String)
|
1406
|
-
# �Ԃ牺��indent
|
1407
|
-
# tail always active
|
1408
|
-
if tail.last
|
1409
|
-
tail.each{|s|
|
1410
|
-
@out.print s.to_s
|
1411
|
-
}
|
1412
|
-
end
|
1413
|
-
if indent_type == :inline
|
1414
|
-
@out.print "\r\n"
|
1415
|
-
elsif indent_type and terprip
|
1416
|
-
@out.print "<br />\r\n"
|
1417
|
-
else
|
1418
|
-
@out.print "</div>\r\n"
|
1419
|
-
end
|
1420
|
-
elsif tail.last
|
1421
|
-
tail.each{|s|
|
1422
|
-
@out.print s.to_s
|
1423
|
-
}
|
1424
|
-
@out.print "\r\n"
|
1425
|
-
elsif terprip
|
1426
|
-
@out.print "<br />\r\n"
|
1427
|
-
else
|
1428
|
-
@out.print "\r\n"
|
1429
|
-
end
|
1430
|
-
end
|
1431
|
-
|
1432
|
-
# �O���Q�Ƃ̔��� Ruby,style�d�˂������X�̂��߁A�v�f�̔z��ŕԂ�
|
1433
|
-
def search_front_reference (string)
|
1434
|
-
if string.length == 0
|
1435
|
-
return false
|
1436
|
-
end
|
1437
|
-
searching_buf = if @ruby_buf.length != 0
|
1438
|
-
@ruby_buf
|
1439
|
-
else
|
1440
|
-
@buffer
|
1441
|
-
end
|
1442
|
-
last_string = searching_buf.last
|
1443
|
-
if last_string.is_a?(String)
|
1444
|
-
if last_string == ""
|
1445
|
-
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
|
1449
|
-
# start = match.begin(0)
|
1450
|
-
# tail = match.end(0)
|
1451
|
-
# last_string[start,tail-start] = ""
|
1452
|
-
searching_buf.pop
|
1453
|
-
searching_buf.push(last_string.sub(Regexp.new(Regexp.quote(string)+"$"),""))
|
1454
|
-
[string]
|
1455
|
-
elsif string.match(Regexp.new(Regexp.quote(last_string)+"$"))
|
1456
|
-
# ������v
|
1457
|
-
tmp = searching_buf.pop
|
1458
|
-
found = search_front_reference(string.sub(Regexp.new(Regexp.quote(last_string)+"$"),""))
|
1459
|
-
if found
|
1460
|
-
found+[tmp]
|
1461
|
-
else
|
1462
|
-
searching_buf.push(tmp)
|
1463
|
-
false
|
1464
|
-
end
|
1465
|
-
end
|
1466
|
-
elsif last_string.is_a?(Reference_mentioned_tag)
|
1467
|
-
inner = last_string.target_string
|
1468
|
-
if inner == string
|
1469
|
-
# ���S��v
|
1470
|
-
searching_buf.pop
|
1471
|
-
[last_string]
|
1472
|
-
elsif string.match(Regexp.new(Regexp.quote(inner)+"$"))
|
1473
|
-
# ������v
|
1474
|
-
tmp = searching_buf.pop
|
1475
|
-
found = search_front_reference(string.sub(Regexp.new(Regexp.quote(inner)+"$"),""))
|
1476
|
-
if found
|
1477
|
-
found+[tmp]
|
1478
|
-
else
|
1479
|
-
searching_buf.push(tmp)
|
1480
|
-
false
|
1481
|
-
end
|
1482
|
-
end
|
1483
|
-
else
|
1484
|
-
false
|
1485
|
-
end
|
1486
|
-
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
|
1499
|
-
else
|
1500
|
-
@ruby_buf.push(elt)
|
1501
|
-
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
|
1509
|
-
else
|
1510
|
-
@ruby_buf.push(elt)
|
1511
|
-
end
|
1512
|
-
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
|
1524
|
-
end
|
1525
|
-
|
1526
|
-
def kuten2png (substring)
|
1527
|
-
desc = substring.gsub(/�u���v[��|��]/,"")
|
1528
|
-
match = desc.match(/[12]\-\d{1,2}\-\d{1,2}/)
|
1529
|
-
if (match and not(desc.match(/��0213�O��/)) and not(desc.match(/��.*��/)))
|
1530
|
-
@chuuki_table[:newjis] = true
|
1531
|
-
codes = match[0].split("-")
|
1532
|
-
folder = sprintf("%1d-%02d",*codes)
|
1533
|
-
code = sprintf("%1d-%02d-%02d",*codes)
|
1534
|
-
Embed_Gaiji_tag.new(self, folder,code,desc.gsub!("��",""))
|
1535
|
-
else
|
1536
|
-
substring
|
1537
|
-
end
|
1538
|
-
end
|
1539
|
-
|
1540
|
-
def escape_gaiji (command)
|
1541
|
-
whole, kanji, line = command.match(/(?:��)(.*)(?:�A)(.*)/).to_a
|
1542
|
-
tmp = @images.assoc(kanji)
|
1543
|
-
if tmp
|
1544
|
-
tmp.push(line)
|
1545
|
-
else
|
1546
|
-
@images.push([kanji,line])
|
1547
|
-
end
|
1548
|
-
UnEmbed_Gaiji_tag.new(self, command)
|
1549
|
-
end
|
1550
|
-
|
1551
|
-
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
|
1564
|
-
else
|
1565
|
-
"��"
|
1566
|
-
end
|
1567
|
-
end
|
1568
|
-
|
1569
|
-
def dispatch_aozora_command
|
1570
|
-
if @stream.peek_char(0) != "��"
|
1571
|
-
"�m"
|
1572
|
-
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
|
1611
|
-
end
|
1612
|
-
end
|
1613
|
-
|
1614
|
-
def apply_burasage (command)
|
1615
|
-
tag = nil
|
1616
|
-
if implicit_close(:jisage)
|
1617
|
-
@terprip = false
|
1618
|
-
general_output
|
1619
|
-
end
|
1620
|
-
@noprint = true # always no print
|
1621
|
-
command = convert_japanese_number(command)
|
1622
|
-
if command.match(/�V�t��/)
|
1623
|
-
width = command.match(/�܂�Ԃ���(\d*)������/)[1]
|
1624
|
-
tag = '<div class="burasage" style="margin-left: ' + width + 'em; text-indent: -' + width + 'em;">'
|
1625
|
-
else
|
1626
|
-
match = command.match(/(\d*)�������A�܂�Ԃ���(\d*)������/)
|
1627
|
-
left, indent = match.to_a[1,2]
|
1628
|
-
left = left.to_i - indent.to_i
|
1629
|
-
tag = "<div class=\"burasage\" style=\"margin-left: #{indent}em; text-indent: #{left}em;\">"
|
1630
|
-
end
|
1631
|
-
@indent_stack.push(tag)
|
1632
|
-
@tag_stack.push("") # dummy
|
1633
|
-
nil
|
1634
|
-
end
|
1635
|
-
|
1636
|
-
def jisage_width (command)
|
1637
|
-
convert_japanese_number(command).match(/(\d*)(?:������)/)[1]
|
1638
|
-
end
|
1639
|
-
|
1640
|
-
def apply_jisage (command)
|
1641
|
-
if command.match(/�܂�/) or command.match(/�I���/)
|
1642
|
-
# �������I���
|
1643
|
-
explicit_close(:jisage)
|
1644
|
-
@indent_stack.pop
|
1645
|
-
nil
|
1646
|
-
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
|
1665
|
-
end
|
1666
|
-
end
|
1667
|
-
|
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>')
|
1676
|
-
end
|
1677
|
-
else
|
1678
|
-
check = @ruby_buf.last
|
1679
|
-
if check.is_a?(String) and check.match(/�i$/)
|
1680
|
-
push_chars('<span class="warichu">')
|
1681
|
-
else
|
1682
|
-
push_chars('<span class="warichu">')
|
1683
|
-
push_chars('�i')
|
1684
|
-
end
|
1685
|
-
end
|
1686
|
-
nil
|
1687
|
-
end
|
1688
|
-
|
1689
|
-
def chitsuki_length (command)
|
1690
|
-
command = convert_japanese_number(command)
|
1691
|
-
if match = command.match(/([0-9]+)��/)
|
1692
|
-
match[1]
|
1693
|
-
else
|
1694
|
-
"0"
|
1695
|
-
end
|
1696
|
-
end
|
1697
|
-
|
1698
|
-
def apply_chitsuki (string, multiline = false)
|
1699
|
-
if string.match(/�����Œn�t���I���/) or
|
1700
|
-
string.match(/�����Ŏ��グ�I���/)
|
1701
|
-
explicit_close(:chitsuki)
|
1702
|
-
@indent_stack.pop
|
1703
|
-
nil
|
1704
|
-
else
|
1705
|
-
l = chitsuki_length(string)
|
1706
|
-
if multiline
|
1707
|
-
# �����s�w��
|
1708
|
-
implicit_close(:chitsuki)
|
1709
|
-
@indent_stack.push(:chitsuki)
|
1710
|
-
Multiline_Chitsuki_tag.new(self, l)
|
1711
|
-
else
|
1712
|
-
# 1�s�̂�
|
1713
|
-
Oneline_Chitsuki_tag.new(self, l)
|
1714
|
-
end
|
1715
|
-
end
|
1716
|
-
end
|
1717
|
-
|
1718
|
-
def new_midashi_id(inc)
|
1719
|
-
@midashi_id += inc
|
1720
|
-
end
|
1721
|
-
|
1722
|
-
def apply_midashi(command)
|
1723
|
-
@indent_stack.push(:midashi)
|
1724
|
-
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)
|
1733
|
-
end
|
1734
|
-
|
1735
|
-
def apply_yokogumi(command)
|
1736
|
-
@indent_stack.push(:yokogumi)
|
1737
|
-
Multiline_yokogumi_tag.new(self)
|
1738
|
-
end
|
1739
|
-
|
1740
|
-
def apply_keigakomi(command)
|
1741
|
-
@indent_stack.push(:keigakomi)
|
1742
|
-
Keigakomi_tag.new(self)
|
1743
|
-
end
|
1744
|
-
|
1745
|
-
def apply_caption(command)
|
1746
|
-
@indent_stack.push(:caption)
|
1747
|
-
Multiline_caption_tag.new(self)
|
1748
|
-
end
|
1749
|
-
|
1750
|
-
def apply_jizume(command)
|
1751
|
-
w = convert_japanese_number(command).match(/(\d*)(?:���l��)/)[1]
|
1752
|
-
@indent_stack.push(:jizume)
|
1753
|
-
Jizume_tag.new(self, w)
|
1754
|
-
end
|
1755
|
-
|
1756
|
-
def push_block_tag (tag,closing)
|
1757
|
-
push_chars(tag)
|
1758
|
-
closing.concat(tag.close_tag)
|
1759
|
-
end
|
1760
|
-
|
1761
|
-
def exec_inline_start_command (command)
|
1762
|
-
case command
|
1763
|
-
when "���L�t��"
|
1764
|
-
@style_stack.push([command,'</ruby>'])
|
1765
|
-
push_char('<ruby><rb>')
|
1766
|
-
when "�c����"
|
1767
|
-
@style_stack.push([command,'</span>'])
|
1768
|
-
push_char('<span dir="ltr">')
|
1769
|
-
when "�r�͂�"
|
1770
|
-
@style_stack.push([command,'</span>'])
|
1771
|
-
push_chars('<span class="keigakomi">')
|
1772
|
-
when "���g��"
|
1773
|
-
@style_stack.push([command,'</span>'])
|
1774
|
-
push_chars('<span class="yokogumi">')
|
1775
|
-
when "�L���v�V����"
|
1776
|
-
@style_stack.push([command,'</span>'])
|
1777
|
-
push_chars('<span class="caption">')
|
1778
|
-
when "�匩�o��"
|
1779
|
-
@style_stack.push([command,'</a></h3>'])
|
1780
|
-
@terprip = false
|
1781
|
-
push_chars("<h3 class=\"o-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(100)}\">")
|
1782
|
-
when "�����o��"
|
1783
|
-
@style_stack.push([command,'</a></h4>'])
|
1784
|
-
@terprip = false
|
1785
|
-
push_chars("<h4 class=\"naka-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(10)}\">")
|
1786
|
-
when "�����o��"
|
1787
|
-
@style_stack.push([command,'</a></h5>'])
|
1788
|
-
@terprip = false
|
1789
|
-
push_chars("<h5 class=\"ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(1)}\">")
|
1790
|
-
when "���s�匩�o��"
|
1791
|
-
@style_stack.push([command,'</a></h3>'])
|
1792
|
-
push_chars("<h3 class=\"dogyo-o-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(100)}\">")
|
1793
|
-
when "���s�����o��"
|
1794
|
-
@style_stack.push([command,'</a></h4>'])
|
1795
|
-
push_chars("<h4 class=\"dogyo-naka-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(10)}\">")
|
1796
|
-
when "���s�����o��"
|
1797
|
-
@style_stack.push([command,'</a></h5>'])
|
1798
|
-
push_chars("<h5 class=\"dogyo-ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(1)}\">")
|
1799
|
-
when "���匩�o��"
|
1800
|
-
@style_stack.push([command,'</a></h3>'])
|
1801
|
-
push_chars("<h3 class=\"mado-o-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(100)}\">")
|
1802
|
-
when "�������o��"
|
1803
|
-
@style_stack.push([command,'</a></h4>'])
|
1804
|
-
push_chars("<h4 class=\"mado-naka-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(10)}\">")
|
1805
|
-
when "�������o��"
|
1806
|
-
@style_stack.push([command,'</a></h5>'])
|
1807
|
-
push_chars("<h5 class=\"mado-ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi#{new_midashi_id(1)}\">")
|
1808
|
-
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
|
1855
|
-
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
|
1864
|
-
end
|
1865
|
-
push_chars("<#{found[1]} class=\"#{filter.call(found[0])}\">")
|
1866
|
-
else
|
1867
|
-
nil
|
1868
|
-
end
|
1869
|
-
end
|
1870
|
-
end
|
1871
|
-
end
|
1872
|
-
|
1873
|
-
def exec_inline_end_command (command)
|
1874
|
-
encount = command.sub("�I���","")
|
1875
|
-
if encount == "�{��"
|
1876
|
-
# force to finish main_text
|
1877
|
-
@section = :tail
|
1878
|
-
ensure_close
|
1879
|
-
@noprint = true
|
1880
|
-
@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��"
|
1882
|
-
# special inline ruby
|
1883
|
-
@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)
|
1887
|
-
push_chars(@style_stack.pop[1])
|
1888
|
-
else
|
1889
|
-
raise Aozora_Error.new("#{encount}���I�����悤�Ƃ��܂������A#{@style_stack.last[0]}���ł�")
|
1890
|
-
end
|
1891
|
-
end
|
1892
|
-
|
1893
|
-
def exec_block_start_command (command)
|
1894
|
-
match = ""
|
1895
|
-
if command.match(/������/)
|
1896
|
-
push_block_tag(apply_jisage(command),match)
|
1897
|
-
elsif command.match(/(�n�t��|���グ)$/)
|
1898
|
-
push_block_tag(apply_chitsuki(command,true),match)
|
1899
|
-
end
|
1900
|
-
|
1901
|
-
if command.match(/���o��/)
|
1902
|
-
push_block_tag(apply_midashi(command),match)
|
1903
|
-
end
|
1904
|
-
|
1905
|
-
if command.match(/���l��/)
|
1906
|
-
if match != ""
|
1907
|
-
@indent_stack.pop
|
1908
|
-
end
|
1909
|
-
push_block_tag(apply_jizume(command),match)
|
1910
|
-
end
|
1911
|
-
|
1912
|
-
if command.match(/���g��/)
|
1913
|
-
if match != ""
|
1914
|
-
@indent_stack.pop
|
1915
|
-
end
|
1916
|
-
push_block_tag(apply_yokogumi(command),match)
|
1917
|
-
end
|
1918
|
-
|
1919
|
-
if command.match(/�r�͂�/)
|
1920
|
-
if match != ""
|
1921
|
-
@indent_stack.pop
|
1922
|
-
end
|
1923
|
-
push_block_tag(apply_keigakomi(command),match)
|
1924
|
-
end
|
1925
|
-
|
1926
|
-
if command.match(/�L���v�V����/)
|
1927
|
-
if match != ""
|
1928
|
-
@indent_stack.pop
|
1929
|
-
end
|
1930
|
-
push_block_tag(apply_caption(command),match)
|
1931
|
-
end
|
1932
|
-
|
1933
|
-
if command.match(/����/)
|
1934
|
-
if match != ""
|
1935
|
-
@indent_stack.pop
|
1936
|
-
end
|
1937
|
-
push_block_tag(Multiline_style_tag.new(self, "futoji"),match)
|
1938
|
-
@indent_stack.push(:futoji)
|
1939
|
-
end
|
1940
|
-
if command.match(/�Α�/)
|
1941
|
-
if match != ""
|
1942
|
-
@indent_stack.pop
|
1943
|
-
end
|
1944
|
-
push_block_tag(Multiline_style_tag.new(self, "shatai"),match)
|
1945
|
-
@indent_stack.push(:shatai)
|
1946
|
-
end
|
1947
|
-
|
1948
|
-
if command.match(/(.*)�i�K(..)�ȕ���/)
|
1949
|
-
whole, nest, style = command.match(/(.*)�i�K(..)�ȕ���/).to_a
|
1950
|
-
if match != ""
|
1951
|
-
@indent_stack.pop
|
1952
|
-
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)
|
1961
|
-
@indent_stack.push(daisho)
|
1962
|
-
end
|
1963
|
-
|
1964
|
-
if match == ""
|
1965
|
-
apply_rest_notes("��������" + command)
|
1966
|
-
else
|
1967
|
-
@tag_stack.push(match)
|
1968
|
-
nil
|
1969
|
-
end
|
1970
|
-
end
|
1971
|
-
|
1972
|
-
def exec_block_end_command (command)
|
1973
|
-
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
|
1997
|
-
explicit_close(mode)
|
1998
|
-
match = @indent_stack.pop
|
1999
|
-
end
|
2000
|
-
|
2001
|
-
if match
|
2002
|
-
if not(match.is_a?(String))
|
2003
|
-
@terprip = false
|
2004
|
-
end
|
2005
|
-
nil
|
2006
|
-
else
|
2007
|
-
apply_rest_notes("������" + command)
|
2008
|
-
end
|
2009
|
-
end
|
2010
|
-
|
2011
|
-
def exec_img_command (command,raw)
|
2012
|
-
match = raw.match(/(.*)�i(fig.+\.png)(�A��([0-9]+)�~�c([0-9]+))*�j����/)
|
2013
|
-
if match
|
2014
|
-
whole, alt, src, wh, width, height = match.to_a
|
2015
|
-
css_class = if alt.match(/�ʐ^/)
|
2016
|
-
"photo"
|
2017
|
-
else
|
2018
|
-
"illustration"
|
2019
|
-
end
|
2020
|
-
Img_tag.new(self, src, css_class, alt, width, height)
|
2021
|
-
else
|
2022
|
-
apply_rest_notes(command)
|
2023
|
-
end
|
2024
|
-
end
|
2025
|
-
|
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
|
2033
|
-
if reference and found = search_front_reference(reference)
|
2034
|
-
tmp = exec_style(found, spec)
|
2035
|
-
if tmp
|
2036
|
-
return tmp
|
2037
|
-
else
|
2038
|
-
recovery_front_reference(found)
|
2039
|
-
end
|
2040
|
-
end
|
2041
|
-
# comment out?
|
2042
|
-
apply_rest_notes(command)
|
2043
|
-
end
|
2044
|
-
|
2045
|
-
def multiply (bouki, times)
|
2046
|
-
s = ""
|
2047
|
-
(times-1).times{
|
2048
|
-
s += bouki
|
2049
|
-
s += "<!>"
|
2050
|
-
}
|
2051
|
-
s + bouki
|
2052
|
-
end
|
2053
|
-
|
2054
|
-
def include_ruby? (array)
|
2055
|
-
array.index{|elt|
|
2056
|
-
if elt.is_a?(Ruby_tag)
|
2057
|
-
true
|
2058
|
-
elsif elt.is_a?(Reference_mentioned_tag)
|
2059
|
-
if elt.target.is_a?(Array)
|
2060
|
-
include_ruby?(elt.target)
|
2061
|
-
else
|
2062
|
-
elt.target.is_a?(Ruby_tag)
|
2063
|
-
end
|
2064
|
-
end
|
2065
|
-
}
|
2066
|
-
end
|
2067
|
-
|
2068
|
-
# 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)
|
2072
|
-
end
|
2073
|
-
|
2074
|
-
# ruby�^�O�̍Ċ��蓖��
|
2075
|
-
def rearrange_ruby (targets, upper_ruby, under_ruby = "")
|
2076
|
-
if include_ruby?(targets)
|
2077
|
-
new_targets = []
|
2078
|
-
new_upper = if upper_ruby != ""
|
2079
|
-
upper_ruby
|
2080
|
-
else
|
2081
|
-
[]
|
2082
|
-
end
|
2083
|
-
new_under = if under_ruby != ""
|
2084
|
-
under_ruby
|
2085
|
-
else
|
2086
|
-
[]
|
2087
|
-
end
|
2088
|
-
if new_upper.length > 1 and new_under.length > 1
|
2089
|
-
raise Aozora_Error.new("1�̒P���3�̃��r�͂����܂���")
|
2090
|
-
end
|
2091
|
-
|
2092
|
-
targets.each{|x|
|
2093
|
-
if x.is_a?(Ruby_tag)
|
2094
|
-
if x.target.is_a?(Array)
|
2095
|
-
# inner Ruby_tag is already complex ... give up
|
2096
|
-
raise Aozora_Error.new("�����ӏ���2�̃��r�͂����܂���")
|
2097
|
-
else
|
2098
|
-
if x.ruby != ""
|
2099
|
-
if new_upper.is_a?(Array)
|
2100
|
-
new_upper.push(x.ruby)
|
2101
|
-
else
|
2102
|
-
raise Aozora_Error.new("�����ӏ���2�̃��r�͂����܂���")
|
2103
|
-
end
|
2104
|
-
else
|
2105
|
-
if new_under.is_a?(Array)
|
2106
|
-
new_under.push(x.under_ruby)
|
2107
|
-
else
|
2108
|
-
raise Aozora_Error.new("�����ӏ���2�̃��r�͂����܂���")
|
2109
|
-
end
|
2110
|
-
end
|
2111
|
-
new_targets.push(x.target)
|
2112
|
-
end
|
2113
|
-
elsif x.is_a?(Reference_mentioned_tag)
|
2114
|
-
if x.target.is_a?(Array)
|
2115
|
-
# recursive
|
2116
|
-
tar,up,un = rearrange_ruby(x.target,"","")
|
2117
|
-
# rotation!!
|
2118
|
-
tar.each{|y|
|
2119
|
-
tmp = x.dup
|
2120
|
-
tmp.target = y
|
2121
|
-
new_targets.push(tmp)}
|
2122
|
-
if new_under.is_a?(Array)
|
2123
|
-
new_under.concat(un)
|
2124
|
-
elsif un.to_s.length > 0
|
2125
|
-
raise Aozora_Error.new("�����ӏ���2�̃��r�͂����܂���")
|
2126
|
-
end
|
2127
|
-
if new_upper.is_a?(Array)
|
2128
|
-
new_upper.concat(up)
|
2129
|
-
elsif up.to_s.length > 0
|
2130
|
-
raise Aozora_Error.new("�����ӏ���2�̃��r�͂����܂���")
|
2131
|
-
end
|
2132
|
-
else
|
2133
|
-
new_targets.push(x)
|
2134
|
-
if new_under.is_a?(Array)
|
2135
|
-
new_under.push("")
|
2136
|
-
end
|
2137
|
-
if new_upper.is_a?(Array)
|
2138
|
-
new_upper.push("")
|
2139
|
-
end
|
2140
|
-
end
|
2141
|
-
else
|
2142
|
-
new_targets.push(x)
|
2143
|
-
if new_under.is_a?(Array)
|
2144
|
-
new_under.push("")
|
2145
|
-
end
|
2146
|
-
if new_upper.is_a?(Array)
|
2147
|
-
new_upper.push("")
|
2148
|
-
end
|
2149
|
-
end
|
2150
|
-
}
|
2151
|
-
[new_targets, new_upper, new_under]
|
2152
|
-
else
|
2153
|
-
[targets, upper_ruby, under_ruby]
|
2154
|
-
end
|
2155
|
-
end
|
2156
|
-
|
2157
|
-
def exec_style (targets, command)
|
2158
|
-
try_kuten = kuten2png(command)
|
2159
|
-
if try_kuten != command
|
2160
|
-
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��/)
|
2174
|
-
midashi_type = :normal
|
2175
|
-
if command.match(/���s/)
|
2176
|
-
midashi_type = :dogyo
|
2177
|
-
elsif command.match (/��/)
|
2178
|
-
midashi_type = :mado
|
2179
|
-
else
|
2180
|
-
@terprip = false
|
2181
|
-
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)
|
2195
|
-
tag = targets[0]
|
2196
|
-
if tag.under_ruby == ""
|
2197
|
-
tag.under_ruby = under
|
2198
|
-
tag
|
2199
|
-
else
|
2200
|
-
raise Aozora_Error.new("1�̒P���3�̃��r�͂����܂���")
|
2201
|
-
end
|
2202
|
-
else
|
2203
|
-
rearrange_ruby_tag(targets,"",under)
|
2204
|
-
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))
|
2209
|
-
else
|
2210
|
-
## direction fix! ##
|
2211
|
-
filter = lambda{|x| x}
|
2212
|
-
if command.match(/(�E|��|��|��)��(.*)/)
|
2213
|
-
whole, dir, com = command.match(/(�E|��|��|��)��(.*)/).to_a
|
2214
|
-
# renew command
|
2215
|
-
command = com
|
2216
|
-
if command.match(/�_/)
|
2217
|
-
case dir
|
2218
|
-
when "��", "��"
|
2219
|
-
filter = lambda{|x| x + "_after"}
|
2220
|
-
end
|
2221
|
-
elsif command.match(/��/)
|
2222
|
-
case dir
|
2223
|
-
when "��", "��"
|
2224
|
-
filter = lambda{|x| x.sub("under","over")}
|
2225
|
-
end
|
2226
|
-
end
|
2227
|
-
end
|
2228
|
-
|
2229
|
-
found = @@command_table[command]
|
2230
|
-
# found = [class, tag]
|
2231
|
-
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])
|
2236
|
-
else
|
2237
|
-
nil
|
2238
|
-
end
|
2239
|
-
end
|
2240
|
-
end
|
2241
|
-
|
2242
|
-
def apply_dakuten_katakana (command)
|
2243
|
-
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
|
2255
|
-
if found = search_front_reference(frontref)
|
2256
|
-
Dakuten_katakana_tag.new(self, n,found.join)
|
2257
|
-
else
|
2258
|
-
apply_rest_notes(command)
|
2259
|
-
end
|
2260
|
-
end
|
2261
|
-
|
2262
|
-
def assign_kunoji
|
2263
|
-
second = @stream.peek_char(0)
|
2264
|
-
case second
|
2265
|
-
when @@noji
|
2266
|
-
@chuuki_table[:kunoji] = true
|
2267
|
-
when @@dakuten
|
2268
|
-
if @stream.peek_char(1) == @@noji
|
2269
|
-
@chuuki_table[:dakutenkunoji] = true
|
2270
|
-
end
|
2271
|
-
end
|
2272
|
-
end
|
2273
|
-
|
2274
|
-
def apply_rest_notes (command)
|
2275
|
-
@chuuki_table[:chuki] = true
|
2276
|
-
Editor_note_tag.new(self, command)
|
2277
|
-
end
|
2278
|
-
|
2279
|
-
# �b�������Ƃ��͕����������ruby_buf�����Ȃ��Ⴂ���Ȃ�
|
2280
|
-
def apply_ruby
|
2281
|
-
@ruby_buf_protected = nil
|
2282
|
-
ruby,raw = read_to_nest("�t")
|
2283
|
-
if ruby.length == 0
|
2284
|
-
# escaped ruby character
|
2285
|
-
return "�s�t"
|
2286
|
-
end
|
2287
|
-
ans = ""
|
2288
|
-
notes = []
|
2289
|
-
@ruby_buf.each{|token|
|
2290
|
-
if token.is_a?(UnEmbed_Gaiji_tag)
|
2291
|
-
ans.concat("��")
|
2292
|
-
token.escape!
|
2293
|
-
notes.push(token)
|
2294
|
-
else
|
2295
|
-
ans.concat(token.to_s)
|
2296
|
-
end}
|
2297
|
-
@buffer.push(Ruby_tag.new(self, ans, ruby))
|
2298
|
-
@buffer = @buffer + notes
|
2299
|
-
@ruby_buf = [""]
|
2300
|
-
nil
|
2301
|
-
end
|
2302
|
-
|
2303
|
-
def parse_tail
|
2304
|
-
char = read_char
|
2305
|
-
check = true
|
2306
|
-
case char
|
2307
|
-
when "�k"
|
2308
|
-
check = false
|
2309
|
-
char = read_accent
|
2310
|
-
when @endchar
|
2311
|
-
throw :terminate
|
2312
|
-
when "��"
|
2313
|
-
char = dispatch_gaiji
|
2314
|
-
when "�m"
|
2315
|
-
char = dispatch_aozora_command
|
2316
|
-
when @@ku
|
2317
|
-
assign_kunoji
|
2318
|
-
when "�s"
|
2319
|
-
char = apply_ruby
|
2320
|
-
end
|
2321
|
-
if char == "\r\n"
|
2322
|
-
tail_output
|
2323
|
-
elsif char == "�b"
|
2324
|
-
ruby_buf_dump
|
2325
|
-
@ruby_buf_protected = true
|
2326
|
-
elsif char != nil
|
2327
|
-
if check
|
2328
|
-
illegal_char_check(char)
|
2329
|
-
end
|
2330
|
-
push_chars(char)
|
2331
|
-
end
|
2332
|
-
end
|
2333
|
-
|
2334
|
-
def tail_output
|
2335
|
-
ruby_buf_dump
|
2336
|
-
string = @buffer.join
|
2337
|
-
@ruby_buf = [""]; @ruby_buf_mode = nil; @buffer = []
|
2338
|
-
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>"}
|
2340
|
-
if string.match(/(<br \/>$|<\/p>$|<\/h\d>$|<div.*>$|<\/div>$|^<[^>]*>$)/)
|
2341
|
-
@out.print string, "\r\n"
|
2342
|
-
else
|
2343
|
-
@out.print string, "<br />\r\n"
|
2344
|
-
end
|
2345
|
-
end
|
2346
|
-
|
2347
|
-
def hyoki ()
|
2348
|
-
# <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"
|
2351
|
-
if @chuuki_table[:chuki]
|
2352
|
-
@out.print "\t<li>�m���c�n�́A���͎҂ɂ�钍��\���L���ł��B</li>\r\n"
|
2353
|
-
end
|
2354
|
-
if @chuuki_table[:kunoji]
|
2355
|
-
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"
|
2357
|
-
else
|
2358
|
-
@out.print "\t<li>�u���̎��_�v�́u#{@@ku}#{@@noji}�v�ŕ\���܂����B</li>\r\n"
|
2359
|
-
end
|
2360
|
-
elsif @chuuki_table[:dakutenkunoji]
|
2361
|
-
@out.print "\t<li>�u���_�t�����̎��_�v�́u#{@@ku}#{@@dakuten}#{@@noji}�v�ŕ\���܂����B</li>\r\n"
|
2362
|
-
end
|
2363
|
-
if @chuuki_table[:newjis]
|
2364
|
-
@out.print "\t<li>�u���̎��_�v���̂���JIS X 0213�ɂ��镶���́A�摜�����Ė��ߍ��݂܂����B</li>\r\n"
|
2365
|
-
end
|
2366
|
-
if @chuuki_table[:accent]
|
2367
|
-
@out.print "\t<li>�A�N�Z���g�����t�����e�������́A�摜�����Ė��ߍ��݂܂����B</li>\r\n"
|
2368
|
-
end
|
2369
|
-
# if @chuuki_table[:em]
|
2370
|
-
# @out.print "\t<li>�T�_�⌗�_�A�T���̕t���������́A�����\���ɂ��܂����B</li>\r\n"
|
2371
|
-
# end
|
2372
|
-
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"
|
2374
|
-
@images.each{|cell|
|
2375
|
-
k,*v = cell
|
2376
|
-
@out.print " <tr>
|
2377
|
-
<td>
|
2378
|
-
#{k}
|
2379
|
-
</td>
|
2380
|
-
<td> </td>
|
2381
|
-
<td>
|
2382
|
-
#{v.join("�A")} </td>
|
2383
|
-
<!--
|
2384
|
-
<td>
|
2385
|
-
�@�@<img src=\"../../../gaiji/others/xxxx.png\" alt=\"#{k}\" width=32 height=32 />
|
2386
|
-
</td>
|
2387
|
-
-->
|
2388
|
-
</tr>
|
2389
|
-
"
|
2390
|
-
}
|
2391
|
-
@out.print "\t\t</table>\r\n"
|
2392
|
-
else
|
2393
|
-
@out.print "</ul>\r\n" # <ul>����<li>�ȊO�̃G�������g������͕̂s���Ȃ̂ŏC��
|
2394
|
-
end
|
2395
|
-
@out.print "</div>\r\n"
|
2396
|
-
end
|
2397
|
-
end
|
2398
|
-
|
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
|
-
if $0 == __FILE__
|
2533
|
-
# todo: �����`�F�b�N�Ƃ�
|
2534
|
-
Aozora2Html.new($*[0],$*[1]).process
|
2535
|
-
end
|