aozora2html 0.7.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/aozora2html +3 -50
- data/lib/aozora2html.rb +0 -4
- data/lib/aozora2html/accent_parser.rb +91 -0
- data/lib/aozora2html/error.rb +16 -0
- data/lib/aozora2html/header.rb +139 -0
- data/lib/aozora2html/i18n.rb +17 -0
- data/lib/aozora2html/ruby_buffer.rb +81 -0
- data/lib/aozora2html/style_stack.rb +27 -0
- data/lib/aozora2html/tag.rb +55 -0
- data/lib/aozora2html/tag/accent.rb +39 -0
- data/lib/aozora2html/tag/block.rb +19 -0
- data/lib/aozora2html/tag/chitsuki.rb +15 -0
- data/lib/aozora2html/tag/dakuten_katakana.rb +23 -0
- data/lib/aozora2html/tag/decorate.rb +18 -0
- data/lib/aozora2html/tag/dir.rb +15 -0
- data/lib/aozora2html/tag/editor_note.rb +16 -0
- data/lib/aozora2html/tag/embed_gaiji.rb +48 -0
- data/lib/aozora2html/tag/font_size.rb +17 -0
- data/lib/aozora2html/tag/gaiji.rb +11 -0
- data/lib/aozora2html/tag/img.rb +21 -0
- data/lib/aozora2html/tag/indent.rb +8 -0
- data/lib/aozora2html/tag/inline.rb +13 -0
- data/lib/aozora2html/tag/inline_caption.rb +15 -0
- data/lib/aozora2html/tag/inline_font_size.rb +18 -0
- data/lib/aozora2html/tag/inline_keigakomi.rb +15 -0
- data/lib/aozora2html/tag/inline_yokogumi.rb +16 -0
- data/lib/aozora2html/tag/jisage.rb +15 -0
- data/lib/aozora2html/tag/jizume.rb +16 -0
- data/lib/aozora2html/tag/kaeriten.rb +15 -0
- data/lib/aozora2html/tag/keigakomi.rb +13 -0
- data/lib/aozora2html/tag/kunten.rb +12 -0
- data/lib/aozora2html/tag/midashi.rb +18 -0
- data/lib/aozora2html/tag/multiline.rb +6 -0
- data/lib/aozora2html/tag/multiline_caption.rb +15 -0
- data/lib/aozora2html/tag/multiline_chitsuki.rb +8 -0
- data/lib/aozora2html/tag/multiline_jisage.rb +8 -0
- data/lib/aozora2html/tag/multiline_midashi.rb +22 -0
- data/lib/aozora2html/tag/multiline_style.rb +17 -0
- data/lib/aozora2html/tag/multiline_yokogumi.rb +17 -0
- data/lib/aozora2html/tag/okurigana.rb +15 -0
- data/lib/aozora2html/tag/oneline_chitsuki.rb +9 -0
- data/lib/aozora2html/tag/oneline_indent.rb +2 -0
- data/lib/aozora2html/tag/oneline_jisage.rb +7 -0
- data/lib/aozora2html/tag/reference_mentioned.rb +46 -0
- data/lib/aozora2html/tag/ruby.rb +98 -0
- data/lib/aozora2html/tag/un_embed_gaiji.rb +24 -0
- data/lib/aozora2html/tag_parser.rb +53 -0
- data/lib/aozora2html/utils.rb +82 -0
- data/lib/aozora2html/version.rb +1 -1
- data/lib/aozora2html/yaml_loader.rb +31 -0
- data/lib/extensions.rb +31 -0
- data/lib/jstream.rb +68 -0
- data/lib/t2hs.rb +485 -1490
- data/test/test_aozora2html.rb +161 -57
- data/test/test_aozora_accent_parser.rb +13 -2
- data/test/test_command_parse.rb +213 -0
- data/test/test_dakuten_katakana_tag.rb +5 -4
- data/test/test_decorate_tag.rb +5 -4
- data/test/test_dir_tag.rb +5 -4
- data/test/test_editor_note_tag.rb +4 -4
- data/test/test_exception.rb +4 -4
- data/test/test_font_size_tag.rb +8 -7
- data/test/test_gaiji_tag.rb +14 -7
- data/test/test_header.rb +60 -0
- data/test/test_img_tag.rb +5 -4
- data/test/test_inline_caption_tag.rb +5 -4
- data/test/test_inline_font_size_tag.rb +7 -6
- data/test/test_inline_keigakomi_tag.rb +5 -4
- data/test/test_inline_yokogumi_tag.rb +5 -4
- data/test/test_jizume_tag.rb +7 -6
- data/test/test_jstream.rb +5 -5
- data/test/test_kaeriten_tag.rb +5 -4
- data/test/test_keigakomi_tag.rb +8 -7
- data/test/test_midashi_tag.rb +38 -0
- data/test/test_multiline_caption_tag.rb +7 -6
- data/test/test_multiline_midashi_tag.rb +12 -11
- data/test/test_multiline_style_tag.rb +7 -6
- data/test/test_multiline_yokogumi_tag.rb +7 -6
- data/test/test_okurigana_tag.rb +5 -4
- data/test/test_ruby_parse.rb +116 -0
- data/test/test_ruby_tag.rb +5 -4
- data/test/test_tag_parser.rb +10 -10
- data/yml/accent_table.yml +240 -0
- data/yml/command_table.yml +61 -0
- data/yml/jis2ucs.yml +11234 -0
- metadata +63 -6
- data/lib/accent_tag.rb +0 -23
- data/lib/aozora2html/jis2ucs.rb +0 -11237
- data/lib/embed_gaiji_tag.rb +0 -34
data/lib/aozora2html/version.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
class Aozora2Html
|
3
|
+
class YamlLoader
|
4
|
+
def initialize(base_dir)
|
5
|
+
@base_dir = base_dir
|
6
|
+
end
|
7
|
+
|
8
|
+
def load(path)
|
9
|
+
tmp_data = YAML.load_file(File.join(@base_dir, path))
|
10
|
+
normalize_data(tmp_data)
|
11
|
+
end
|
12
|
+
|
13
|
+
def normalize_data(data)
|
14
|
+
case data
|
15
|
+
when String
|
16
|
+
data.encode("shift_jis")
|
17
|
+
when Hash
|
18
|
+
new_data = {}
|
19
|
+
data.each do |k, v|
|
20
|
+
new_data[normalize_data(k)] = normalize_data(v)
|
21
|
+
end
|
22
|
+
new_data
|
23
|
+
when Array
|
24
|
+
data.map{|item| normalize_data(item)}
|
25
|
+
else
|
26
|
+
# noop
|
27
|
+
data
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/extensions.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# 1.8 like to_s method to Array
|
3
|
+
class Array
|
4
|
+
def to_s
|
5
|
+
self.join
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class String
|
10
|
+
|
11
|
+
# used in Aozora2Html#char_type
|
12
|
+
def char_type
|
13
|
+
ch = self
|
14
|
+
if ch.match(Regexp.new("[ぁ-んゝゞ]".encode("shift_jis")))
|
15
|
+
:hiragana
|
16
|
+
elsif ch.match(Regexp.new("[ァ-ンーヽヾヴ]".encode("shift_jis")))
|
17
|
+
:katakana
|
18
|
+
elsif ch.match(Regexp.new("[0-9A-Za-zΑ-Ωα-ωА-Яа-я−&’,.]".encode("shift_jis")))
|
19
|
+
:zenkaku
|
20
|
+
elsif ch.match(Regexp.new("[A-Za-z0-9#\\-\\&'\\,]".encode("shift_jis")))
|
21
|
+
:hankaku
|
22
|
+
elsif ch.match(Regexp.new("[亜-熙々※仝〆〇ヶ]".encode("shift_jis")))
|
23
|
+
:kanji
|
24
|
+
elsif ch.match(/[\.\;\"\?\!\)]/)
|
25
|
+
:hankaku_terminate
|
26
|
+
else
|
27
|
+
:else
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
data/lib/jstream.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "aozora2html/error"
|
2
|
+
require "aozora2html/i18n"
|
3
|
+
|
4
|
+
##
|
5
|
+
# Stream class for reading a file.
|
6
|
+
#
|
7
|
+
# It's just a wrapper class of IO to read characters.
|
8
|
+
# when finished to read IO, return a symbol :eof.
|
9
|
+
# when found line terminator except CR+LF, exit.
|
10
|
+
#
|
11
|
+
class Jstream
|
12
|
+
|
13
|
+
attr_accessor :line
|
14
|
+
|
15
|
+
def initialize(file_io)
|
16
|
+
@line = 0
|
17
|
+
@entry = false
|
18
|
+
@file = file_io
|
19
|
+
begin
|
20
|
+
store_to_buffer
|
21
|
+
rescue Aozora2Html::Error => e
|
22
|
+
puts e.message(1)
|
23
|
+
if e.is_a?(Aozora2Html::Error)
|
24
|
+
exit(2)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def inspect
|
30
|
+
"#<jcode-stream input " + @file.inspect + ">"
|
31
|
+
end
|
32
|
+
|
33
|
+
def read_char
|
34
|
+
found = @buffer.shift
|
35
|
+
if @entry
|
36
|
+
@line += 1
|
37
|
+
@entry = false
|
38
|
+
end
|
39
|
+
if found
|
40
|
+
return found
|
41
|
+
end
|
42
|
+
|
43
|
+
begin
|
44
|
+
store_to_buffer
|
45
|
+
rescue EOFError
|
46
|
+
@buffer = [:eof]
|
47
|
+
end
|
48
|
+
"\r\n"
|
49
|
+
end
|
50
|
+
|
51
|
+
def peek_char(pos)
|
52
|
+
@buffer[pos] || "\r\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
def close
|
56
|
+
@file.close
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def store_to_buffer
|
61
|
+
if tmp = @file.readline.chomp!("\r\n")
|
62
|
+
@buffer = tmp.each_char.to_a
|
63
|
+
else
|
64
|
+
raise Aozora2Html::Error, Aozora2Html::I18n.t(:use_crlf)
|
65
|
+
end
|
66
|
+
@entry = true
|
67
|
+
end
|
68
|
+
end
|
data/lib/t2hs.rb
CHANGED
@@ -1,958 +1,206 @@
|
|
1
1
|
# -*- coding:shift_jis -*-
|
2
2
|
# �Ɍ`���̃e�L�X�g�t�@�C���� html �ɐ��`���� ruby �X�N���v�g
|
3
3
|
require "cgi"
|
4
|
+
require "extensions"
|
5
|
+
require "aozora2html/error"
|
6
|
+
require "jstream"
|
7
|
+
require "aozora2html/tag"
|
8
|
+
require "aozora2html/tag_parser"
|
9
|
+
require "aozora2html/accent_parser"
|
10
|
+
require "aozora2html/style_stack"
|
11
|
+
require "aozora2html/header"
|
12
|
+
require "aozora2html/ruby_buffer"
|
13
|
+
require "aozora2html/yaml_loader"
|
14
|
+
require "aozora2html/zip"
|
15
|
+
require "aozora2html/utils"
|
4
16
|
|
5
17
|
$gaiji_dir = "../../../gaiji/"
|
6
18
|
|
7
19
|
$css_files = Array["../../aozora.css"]
|
8
20
|
|
9
|
-
#
|
10
|
-
class
|
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
|
21
|
+
# �ϊ���{��
|
22
|
+
class Aozora2Html
|
358
23
|
|
359
|
-
# �
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
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
|
24
|
+
# �S�p�o�b�N�X���b�V�����o���Ȃ����璼�ł�
|
25
|
+
KU = ["18e5"].pack("h*").force_encoding("shift_jis")
|
26
|
+
NOJI = ["18f5"].pack("h*").force_encoding("shift_jis")
|
27
|
+
DAKUTEN = ["18d8"].pack("h*").force_encoding("shift_jis")
|
28
|
+
GAIJI_MARK = "��"
|
29
|
+
SIZE_SMALL = "��"
|
30
|
+
SIZE_MIDDLE = "��"
|
31
|
+
SIZE_LARGE = "��"
|
32
|
+
AOZORABUNKO = "��"
|
33
|
+
#PAT_EDITOR = /[�Z��|��|�ҏW|�ҏW�Z��|�Z���ҏW]$/
|
34
|
+
PAT_EDITOR = /(�Z��|��|�ҏW|�ҏW�Z��|�Z���ҏW)$/
|
35
|
+
PAT_HENYAKU = /�Җ�$/
|
36
|
+
PAT_TRANSLATOR = /��$/
|
37
|
+
RUBY_PREFIX = "�b"
|
38
|
+
|
39
|
+
# KUNOJI = ["18e518f5"].pack("h*")
|
40
|
+
# utf8 ["fecbf8fecbcb"].pack("h*")
|
41
|
+
# DAKUTENKUNOJI = ["18e518d818f5"].pack("h*")
|
42
|
+
# utf8 ["fecbf82e083bfecbcb"].pack("h*")
|
398
43
|
|
399
|
-
|
400
|
-
|
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
|
44
|
+
loader = Aozora2Html::YamlLoader.new(File.dirname(__FILE__))
|
45
|
+
ACCENT_TABLE = loader.load("../yml/accent_table.yml")
|
451
46
|
|
452
|
-
#
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
47
|
+
# [class, tag]
|
48
|
+
COMMAND_TABLE = loader.load("../yml/command_table.yml")
|
49
|
+
JIS2UCS = loader.load("../yml/jis2ucs.yml")
|
50
|
+
|
51
|
+
INDENT_TYPE = {
|
52
|
+
:jisage => "������",
|
53
|
+
:chitsuki => "�n�t��",
|
54
|
+
:midashi => "���o��",
|
55
|
+
:jizume => "���l��",
|
56
|
+
:yokogumi => "���g��",
|
57
|
+
:keigakomi => "�r�͂�",
|
58
|
+
:caption => "�L���v�V����",
|
59
|
+
:futoji => "����",
|
60
|
+
:shatai => "�Α�",
|
61
|
+
:dai => "�傫�ȕ���",
|
62
|
+
:sho => "�����ȕ���",
|
63
|
+
}
|
469
64
|
|
470
|
-
|
471
|
-
"
|
472
|
-
|
65
|
+
DAKUTEN_KATAKANA_TABLE = {
|
66
|
+
"2" => "���J",
|
67
|
+
"3" => "���J",
|
68
|
+
"4" => "���J",
|
69
|
+
"5" => "���J",
|
70
|
+
}
|
473
71
|
|
474
|
-
|
475
|
-
|
476
|
-
|
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
|
-
}
|
72
|
+
def initialize(input, output)
|
73
|
+
if input.respond_to?(:read) ## readable IO?
|
74
|
+
@stream = Jstream.new(input)
|
496
75
|
else
|
497
|
-
|
76
|
+
@stream = Jstream.new(File.open(input,"rb:Shift_JIS"))
|
498
77
|
end
|
499
|
-
|
500
|
-
|
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
|
78
|
+
if output.respond_to?(:print) ## writable IO?
|
79
|
+
@out = output
|
513
80
|
else
|
514
|
-
|
515
|
-
end
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
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
|
81
|
+
@out = File.open(output,"w")
|
82
|
+
end
|
83
|
+
@buffer = []
|
84
|
+
@ruby_buf = RubyBuffer.new
|
85
|
+
@section = :head ## ���ݏ������̃Z�N�V����(:head,:head_end,:chuuki,:chuuki_in,:body,:tail)
|
86
|
+
@header = Aozora2Html::Header.new() ## �w�b�_�s�̔z��
|
87
|
+
@style_stack = StyleStack.new ##�X�^�C���̃X�^�b�N
|
88
|
+
@chuuki_table = {} ## �Ō�ɂǂ̒��L���o������ێ����Ă���
|
89
|
+
@images = [] ## �g�p�����O���̉摜�ێ��p
|
90
|
+
@indent_stack = []
|
91
|
+
@tag_stack = []
|
92
|
+
@midashi_id = 0 ## ���o���̃J�E���^�A���o���̎�ނɂ���đ������قȂ�
|
93
|
+
@terprip = true ## ���s����p (terpri��Lisp�R��?)
|
94
|
+
@endchar = :eof ## ��͏I�������AAccentParser��TagParser�ł͈قȂ�
|
95
|
+
@noprint = nil
|
96
|
+
end
|
97
|
+
|
98
|
+
def line_number
|
824
99
|
@stream.line
|
825
100
|
end
|
826
101
|
|
827
102
|
def block_allowed_context?
|
828
103
|
# inline_tag���J���Ă��Ȃ����`�F�b�N����Ώ\��
|
829
|
-
|
104
|
+
@style_stack.empty?
|
830
105
|
end
|
831
106
|
|
107
|
+
# �ꕶ���ǂݍ���
|
832
108
|
def read_char
|
833
109
|
@stream.read_char
|
834
110
|
end
|
835
111
|
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
112
|
+
# �w�肳�ꂽ�I�[����(1������String��CRLF)�܂œǂݍ���
|
113
|
+
#
|
114
|
+
# @param [String] endchar �I�[����
|
115
|
+
def read_to(endchar)
|
116
|
+
buf = ""
|
117
|
+
loop do
|
118
|
+
char = @stream.read_char
|
119
|
+
if char == endchar
|
841
120
|
break
|
842
121
|
else
|
843
122
|
if char.kind_of?(Symbol)
|
844
123
|
print endchar
|
845
124
|
end
|
846
125
|
buf.concat(char)
|
847
|
-
end
|
126
|
+
end
|
127
|
+
end
|
848
128
|
buf
|
849
129
|
end
|
850
130
|
|
851
131
|
def read_accent
|
852
|
-
|
132
|
+
Aozora2Html::AccentParser.new(@stream, "�l", @chuuki_table, @images).process
|
853
133
|
end
|
854
134
|
|
855
|
-
def read_to_nest
|
856
|
-
|
135
|
+
def read_to_nest(endchar)
|
136
|
+
Aozora2Html::TagParser.new(@stream, endchar, @chuuki_table, @images).process
|
857
137
|
end
|
858
138
|
|
859
139
|
def read_line
|
860
|
-
tmp=read_to("\r\n")
|
861
|
-
@buffer=[]
|
140
|
+
tmp = read_to("\r\n")
|
141
|
+
@buffer = []
|
862
142
|
tmp
|
863
143
|
end
|
864
144
|
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
145
|
+
# parse����
|
146
|
+
#
|
147
|
+
# �I�����i�I�[�܂ŗ����ꍇ�j�ɂ�throw :terminate�ŒE�o����
|
148
|
+
#
|
149
|
+
def process
|
150
|
+
begin
|
151
|
+
catch(:terminate) do
|
152
|
+
loop do
|
153
|
+
begin
|
154
|
+
parse
|
155
|
+
rescue Aozora2Html::Error => e
|
156
|
+
puts e.message(line_number)
|
157
|
+
if e.is_a?(Aozora2Html::Error)
|
158
|
+
exit(2)
|
159
|
+
end
|
874
160
|
end
|
875
161
|
end
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
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
|
162
|
+
end
|
163
|
+
tail_output # final call
|
164
|
+
finalize
|
165
|
+
close
|
166
|
+
rescue => e
|
167
|
+
puts "ERROR: line: #{line_number}"
|
168
|
+
raise e
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def char_type(char)
|
173
|
+
begin
|
174
|
+
char.char_type
|
175
|
+
rescue
|
907
176
|
:else
|
908
177
|
end
|
909
178
|
end
|
910
|
-
|
911
|
-
def finalize
|
179
|
+
|
180
|
+
def finalize
|
912
181
|
hyoki
|
913
182
|
dynamic_contents
|
914
183
|
@out.print("</body>\r\n</html>\r\n")
|
915
184
|
end
|
916
|
-
|
185
|
+
|
917
186
|
def dynamic_contents
|
918
|
-
@out.print
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
187
|
+
@out.print "<div id=\"card\">\r\n<hr />\r\n<br />\r\n" +
|
188
|
+
"<a href=\"JavaScript:goLibCard();\" id=\"goAZLibCard\">���}���J�[�h</a>" +
|
189
|
+
"<script type=\"text/javascript\" src=\"../../contents.js\"></script>\r\n" +
|
190
|
+
"<script type=\"text/javascript\" src=\"../../golibcard.js\"></script>\r\n" +
|
191
|
+
"</div>"
|
923
192
|
end
|
924
193
|
|
925
|
-
def close
|
194
|
+
def close
|
926
195
|
@stream.close
|
927
196
|
@out.close
|
928
197
|
end
|
929
|
-
|
930
|
-
def convert_indent_type
|
931
|
-
|
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
|
198
|
+
|
199
|
+
def convert_indent_type(type)
|
200
|
+
INDENT_TYPE[type] || type
|
953
201
|
end
|
954
202
|
|
955
|
-
def check_close_match
|
203
|
+
def check_close_match(type)
|
956
204
|
ind = if @indent_stack.last.is_a?(String)
|
957
205
|
@noprint = true
|
958
206
|
:jisage
|
@@ -966,9 +214,9 @@ class Aozora2Html
|
|
966
214
|
end
|
967
215
|
end
|
968
216
|
|
969
|
-
def implicit_close
|
217
|
+
def implicit_close(type)
|
970
218
|
if @indent_stack.last
|
971
|
-
if
|
219
|
+
if check_close_match(type)
|
972
220
|
# ok, nested multiline tags, go ahead
|
973
221
|
else
|
974
222
|
# not nested, please close
|
@@ -982,19 +230,20 @@ class Aozora2Html
|
|
982
230
|
|
983
231
|
def ensure_close
|
984
232
|
if n = @indent_stack.last
|
985
|
-
raise
|
233
|
+
raise Aozora2Html::Error, "#{convert_indent_type(n)}���ɖ{�����I�����܂���"
|
986
234
|
end
|
987
|
-
end
|
988
|
-
|
989
|
-
def explicit_close
|
990
|
-
|
991
|
-
|
235
|
+
end
|
236
|
+
|
237
|
+
def explicit_close(type)
|
238
|
+
n = check_close_match(type)
|
239
|
+
if n
|
240
|
+
raise Aozora2Html::Error, "#{n}����悤�Ƃ��܂������A#{n}���ł͂���܂���"
|
992
241
|
end
|
993
242
|
if tag = @tag_stack.pop
|
994
243
|
push_chars(tag)
|
995
244
|
end
|
996
245
|
end
|
997
|
-
|
246
|
+
|
998
247
|
# main loop
|
999
248
|
def parse
|
1000
249
|
case @section
|
@@ -1009,175 +258,50 @@ class Aozora2Html
|
|
1009
258
|
when :tail
|
1010
259
|
parse_tail
|
1011
260
|
else
|
1012
|
-
|
261
|
+
raise Aozora2Html::Error, "encount undefined condition"
|
1013
262
|
end
|
1014
263
|
end
|
1015
264
|
|
1016
265
|
def judge_chuuki
|
1017
266
|
# ���L�����邩�ǂ����`�F�b�N
|
1018
|
-
i=0
|
1019
|
-
loop
|
267
|
+
i = 0
|
268
|
+
loop do
|
1020
269
|
case @stream.peek_char(i)
|
1021
270
|
when "-"
|
1022
|
-
i
|
271
|
+
i += 1
|
1023
272
|
when "\r\n"
|
1024
|
-
@
|
1025
|
-
|
273
|
+
if i == 0 && @stream.peek_char(1) == "\r\n"
|
274
|
+
@section = :body
|
275
|
+
return
|
276
|
+
else
|
277
|
+
@section = :chuuki
|
278
|
+
return
|
279
|
+
end
|
1026
280
|
else
|
1027
281
|
@section = :body
|
1028
282
|
@out.print("<br />\r\n")
|
1029
283
|
return
|
1030
284
|
end
|
1031
|
-
|
285
|
+
end
|
1032
286
|
end
|
1033
287
|
|
1034
288
|
# header�͈�s���ǂ�
|
1035
289
|
def parse_header
|
1036
290
|
string = read_line
|
1037
291
|
# refine from Tomita 09/06/14
|
1038
|
-
if
|
292
|
+
if string == "" # ��s������A�����Ńw�b�_�[�I���Ƃ݂Ȃ�
|
1039
293
|
@section = :head_end
|
1040
|
-
|
294
|
+
@out.print @header.to_html
|
1041
295
|
else
|
1042
|
-
string.gsub!(
|
296
|
+
string.gsub!(RUBY_PREFIX,"")
|
1043
297
|
string.gsub!(/�s.*?�t/,"")
|
1044
298
|
@header.push(string)
|
1045
299
|
end
|
1046
300
|
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
301
|
|
1178
302
|
def parse_chuuki
|
1179
303
|
string = read_line
|
1180
|
-
if
|
304
|
+
if string.match(/^\-+$/)
|
1181
305
|
case @section
|
1182
306
|
when :chuuki
|
1183
307
|
@section = :chuuki_in
|
@@ -1187,39 +311,39 @@ class Aozora2Html
|
|
1187
311
|
end
|
1188
312
|
end
|
1189
313
|
|
1190
|
-
def illegal_char_check
|
314
|
+
def illegal_char_check(char, line)
|
1191
315
|
if char.is_a?(String)
|
1192
316
|
code = char.unpack("H*")[0]
|
1193
|
-
if code == "21" or
|
317
|
+
if (code == "21" or
|
1194
318
|
code == "23" or
|
1195
|
-
("a1" <= code and code <= "a5") or
|
1196
|
-
("28" <= code and code<= "29") or
|
319
|
+
("a1" <= code and code <= "a5") or
|
320
|
+
("28" <= code and code <= "29") or
|
1197
321
|
code == "5b" or
|
1198
322
|
code == "5d" or
|
1199
323
|
code == "3d" or
|
1200
324
|
code == "3f" or
|
1201
325
|
code == "2b" or
|
1202
|
-
("7b" <= code and code <= "7d")
|
1203
|
-
puts "�x��(#{
|
326
|
+
("7b" <= code and code <= "7d"))
|
327
|
+
puts "�x��(#{line}�s��):1�o�C�g�́u#{char}�v���g���Ă��܂�"
|
1204
328
|
end
|
1205
329
|
|
1206
330
|
if code == "81f2"
|
1207
|
-
puts "�x��(#{
|
331
|
+
puts "�x��(#{line}�s��):���L�L���̌�p�̉\��������A�u#{char}�v���g���Ă��܂�"
|
1208
332
|
end
|
1209
|
-
|
1210
|
-
if ("81ad" <= code and code <= "81b7") or
|
333
|
+
|
334
|
+
if (("81ad" <= code and code <= "81b7") or
|
1211
335
|
("81c0" <= code and code <= "81c7") or
|
1212
336
|
("81cf" <= code and code <= "81d9") or
|
1213
337
|
("81e9" <= code and code <= "81ef") or
|
1214
338
|
("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
|
339
|
+
("8240" <= code and code <= "824e") or
|
340
|
+
("8259" <= code and code <= "825f") or
|
341
|
+
("827a" <= code and code <= "8280") or
|
1218
342
|
("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
|
343
|
+
("82f2" <= code and code <= "82fc") or
|
344
|
+
("8397" <= code and code <= "839e") or
|
345
|
+
("83b7" <= code and code <= "83be") or
|
346
|
+
("83d7" <= code and code <= "83fc") or
|
1223
347
|
("8461" <= code and code <= "846f") or
|
1224
348
|
("8492" <= code and code <= "849e") or
|
1225
349
|
("84bf" <= code and code <= "84fc") or
|
@@ -1233,16 +357,17 @@ class Aozora2Html
|
|
1233
357
|
("ec40" <= code and code <= "ecfc") or
|
1234
358
|
("ed40" <= code and code <= "edfc") or
|
1235
359
|
("ee40" <= code and code <= "eefc") or
|
1236
|
-
("ef40" <= code and code <= "effc")
|
1237
|
-
puts "�x��(#{
|
360
|
+
("ef40" <= code and code <= "effc"))
|
361
|
+
puts "�x��(#{line}�s��):JIS�O���u#{char}�v���g���Ă��܂�"
|
1238
362
|
end
|
1239
363
|
end
|
1240
364
|
end
|
1241
365
|
|
1242
366
|
# �{�̉�͕�
|
367
|
+
#
|
1243
368
|
# 1�������ǂݍ��݁Adispatch����@buffer,@ruby_buf�ւ��܂�
|
1244
369
|
# ���s�R�[�h�ɓ��������痭�ߍ����̂�general_output����
|
1245
|
-
|
370
|
+
|
1246
371
|
def parse_body
|
1247
372
|
char = read_char
|
1248
373
|
check = true
|
@@ -1258,60 +383,52 @@ class Aozora2Html
|
|
1258
383
|
char = dispatch_gaiji
|
1259
384
|
when "�m"
|
1260
385
|
char = dispatch_aozora_command
|
1261
|
-
when
|
386
|
+
when KU
|
1262
387
|
assign_kunoji
|
1263
388
|
when "�s"
|
1264
389
|
char = apply_ruby
|
1265
390
|
end
|
1266
|
-
|
391
|
+
|
392
|
+
case char
|
393
|
+
when "\r\n"
|
1267
394
|
general_output
|
1268
|
-
|
1269
|
-
|
1270
|
-
@
|
1271
|
-
|
395
|
+
when RUBY_PREFIX
|
396
|
+
@ruby_buf.dump(@buffer)
|
397
|
+
@ruby_buf.protected = true
|
398
|
+
when @endchar
|
1272
399
|
# suddenly finished the file
|
1273
|
-
puts "�x��(#{
|
1274
|
-
|
1275
|
-
|
400
|
+
puts "�x��(#{line_number}�s��):�\�����ʃt�@�C���I�["
|
401
|
+
throw :terminate
|
402
|
+
when nil
|
403
|
+
# noop
|
404
|
+
else
|
1276
405
|
if check
|
1277
|
-
illegal_char_check(char)
|
406
|
+
illegal_char_check(char, line_number)
|
1278
407
|
end
|
1279
408
|
push_chars(char)
|
1280
409
|
end
|
1281
410
|
end
|
1282
|
-
|
411
|
+
|
1283
412
|
def ending_check
|
413
|
+
# `��{�F`�Ńt�b�^(:tail)�ɑJ��
|
1284
414
|
if @stream.peek_char(0) == "�{" and @stream.peek_char(1) == "�F"
|
1285
415
|
@section = :tail
|
1286
416
|
ensure_close
|
1287
417
|
@out.print "</div>\r\n<div class=\"bibliographical_information\">\r\n<hr />\r\n<br />\r\n"
|
1288
418
|
end
|
1289
419
|
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
420
|
|
1307
|
-
|
421
|
+
# Original Aozora2Html#push_chars does not convert "'" into '''; it's old behaivor
|
422
|
+
# of CGI.escapeHTML().
|
423
|
+
#
|
424
|
+
def push_chars(obj)
|
1308
425
|
if obj.is_a?(Array)
|
1309
426
|
obj.each{|x|
|
1310
427
|
push_chars(x)
|
1311
428
|
}
|
1312
429
|
elsif obj.is_a?(String)
|
1313
430
|
if obj.length == 1
|
1314
|
-
obj =
|
431
|
+
obj = obj.gsub(/[&\"<>]/, {'&' => '&', '"' => '"', '<' => '<', '>' => '>'})
|
1315
432
|
end
|
1316
433
|
obj.each_char{|x|
|
1317
434
|
push_char(x)
|
@@ -1321,46 +438,48 @@ class Aozora2Html
|
|
1321
438
|
end
|
1322
439
|
end
|
1323
440
|
|
1324
|
-
def push_char
|
441
|
+
def push_char(char)
|
1325
442
|
ctype = char_type(char)
|
1326
|
-
if ctype == :hankaku_terminate and @
|
1327
|
-
if @ruby_buf.
|
1328
|
-
@ruby_buf.
|
443
|
+
if ctype == :hankaku_terminate and @ruby_buf.char_type == :hankaku
|
444
|
+
if @ruby_buf.last_is_string?
|
445
|
+
@ruby_buf.last_concat(char)
|
1329
446
|
else
|
1330
447
|
@ruby_buf.push(char)
|
1331
448
|
end
|
1332
|
-
@
|
1333
|
-
elsif @
|
1334
|
-
if char.is_a?(String) and @ruby_buf.
|
1335
|
-
@ruby_buf.
|
449
|
+
@ruby_buf.char_type = :else
|
450
|
+
elsif @ruby_buf.protected or (ctype != :else and ctype == @ruby_buf.char_type)
|
451
|
+
if char.is_a?(String) and @ruby_buf.last_is_string?
|
452
|
+
@ruby_buf.last_concat(char)
|
1336
453
|
else
|
1337
454
|
@ruby_buf.push(char)
|
1338
455
|
@ruby_buf.push("")
|
1339
456
|
end
|
1340
457
|
else
|
1341
|
-
|
1342
|
-
@
|
1343
|
-
@ruby_buf =
|
458
|
+
@ruby_buf.dump(@buffer)
|
459
|
+
@ruby_buf.clear(char)
|
460
|
+
@ruby_buf.char_type = ctype
|
1344
461
|
end
|
1345
462
|
end
|
1346
|
-
|
1347
|
-
def buf_is_blank?
|
463
|
+
|
464
|
+
def buf_is_blank?(buf)
|
1348
465
|
buf.each{|token|
|
1349
466
|
if token.is_a?(String) and not(token=="")
|
1350
467
|
return false
|
1351
|
-
elsif token.is_a?(
|
468
|
+
elsif token.is_a?(Aozora2Html::Tag::OnelineIndent)
|
1352
469
|
return :inline
|
1353
470
|
end
|
1354
471
|
}
|
1355
472
|
true
|
1356
473
|
end
|
1357
|
-
|
1358
|
-
|
474
|
+
|
475
|
+
# �s����<br />���o�͂���ׂ����ǂ����̔��ʗp
|
476
|
+
#
|
477
|
+
def terpri?(buf)
|
1359
478
|
flag = true
|
1360
479
|
buf.each{|x|
|
1361
|
-
if x.is_a?(
|
480
|
+
if x.is_a?(Aozora2Html::Tag::Multiline)
|
1362
481
|
flag = false
|
1363
|
-
elsif (x.is_a?(String) and x == "")
|
482
|
+
elsif (x.is_a?(String) and x == "")
|
1364
483
|
nil
|
1365
484
|
else
|
1366
485
|
return true
|
@@ -1369,18 +488,24 @@ class Aozora2Html
|
|
1369
488
|
flag
|
1370
489
|
end
|
1371
490
|
|
491
|
+
# �ǂݍ��s�̏o�͂��s��
|
492
|
+
#
|
493
|
+
# parser�����s������ǂݍ���Ă��
|
494
|
+
# @ruby_buf��@buffer�͏���������
|
495
|
+
#
|
1372
496
|
def general_output
|
1373
497
|
if @style_stack.last
|
1374
|
-
raise
|
498
|
+
raise Aozora2Html::Error, "#{@style_stack.last_command}���ɉ��s����܂����B���s���܂����v�f�ɂ̓u���b�N�\�L��p���Ă�������"
|
1375
499
|
end
|
1376
500
|
# buffer�ɃC���f���g�^�O����������������s���Ȃ��I
|
1377
501
|
if @noprint
|
1378
502
|
@noprint = false
|
1379
503
|
return
|
1380
504
|
end
|
1381
|
-
|
505
|
+
@ruby_buf.dump(@buffer)
|
1382
506
|
buf = @buffer
|
1383
|
-
@ruby_buf
|
507
|
+
@ruby_buf.clear
|
508
|
+
@buffer = []
|
1384
509
|
tail = []
|
1385
510
|
|
1386
511
|
indent_type = buf_is_blank?(buf)
|
@@ -1390,26 +515,22 @@ class Aozora2Html
|
|
1390
515
|
if @indent_stack.last.is_a?(String) and not(indent_type)
|
1391
516
|
@out.print @indent_stack.last
|
1392
517
|
end
|
1393
|
-
|
518
|
+
|
1394
519
|
buf.each{|s|
|
1395
|
-
if s.is_a?(
|
520
|
+
if s.is_a?(Aozora2Html::Tag::OnelineIndent)
|
1396
521
|
tail.unshift(s.close_tag)
|
1397
|
-
elsif s.is_a?(
|
522
|
+
elsif s.is_a?(Aozora2Html::Tag::UnEmbedGaiji) and !s.escaped?
|
1398
523
|
# ��������������������
|
1399
524
|
@out.print "��"
|
1400
|
-
elsif s.is_a?(Multiline_Chitsuki_tag)
|
1401
|
-
elsif s.is_a?(String) and s.match("</em")
|
1402
525
|
end
|
1403
526
|
@out.print s.to_s
|
1404
527
|
}
|
528
|
+
|
529
|
+
# �Ō��CRLF���o�͂���
|
1405
530
|
if @indent_stack.last.is_a?(String)
|
1406
531
|
# �Ԃ牺��indent
|
1407
532
|
# tail always active
|
1408
|
-
|
1409
|
-
tail.each{|s|
|
1410
|
-
@out.print s.to_s
|
1411
|
-
}
|
1412
|
-
end
|
533
|
+
@out.print tail.map{|s| s.to_s}.join("")
|
1413
534
|
if indent_type == :inline
|
1414
535
|
@out.print "\r\n"
|
1415
536
|
elsif indent_type and terprip
|
@@ -1417,25 +538,23 @@ class Aozora2Html
|
|
1417
538
|
else
|
1418
539
|
@out.print "</div>\r\n"
|
1419
540
|
end
|
1420
|
-
elsif tail.
|
1421
|
-
tail.each{|s|
|
1422
|
-
@out.print s.to_s
|
1423
|
-
}
|
1424
|
-
@out.print "\r\n"
|
1425
|
-
elsif terprip
|
541
|
+
elsif tail.empty? and terprip
|
1426
542
|
@out.print "<br />\r\n"
|
1427
543
|
else
|
544
|
+
@out.print tail.map{|s| s.to_s}.join("")
|
1428
545
|
@out.print "\r\n"
|
1429
546
|
end
|
1430
547
|
end
|
1431
|
-
|
548
|
+
|
1432
549
|
# �O���Q�Ƃ̔��� Ruby,style�d�˂������X�̂��߁A�v�f�̔z��ŕԂ�
|
1433
|
-
|
550
|
+
#
|
551
|
+
# �O���Q�Ƃ�`�����m���u�����v�ɖT�_�n`�A`�����m���u���v�Ɂu�}�}�v�̒��L�n`�Ƃ������\�L
|
552
|
+
def search_front_reference(string)
|
1434
553
|
if string.length == 0
|
1435
554
|
return false
|
1436
555
|
end
|
1437
|
-
searching_buf = if @ruby_buf.
|
1438
|
-
@ruby_buf
|
556
|
+
searching_buf = if @ruby_buf.present?
|
557
|
+
@ruby_buf.to_a
|
1439
558
|
else
|
1440
559
|
@buffer
|
1441
560
|
end
|
@@ -1444,7 +563,7 @@ class Aozora2Html
|
|
1444
563
|
if last_string == ""
|
1445
564
|
searching_buf.pop
|
1446
565
|
search_front_reference(string.sub(Regexp.new(Regexp.quote(last_string)+"$"),""))
|
1447
|
-
elsif
|
566
|
+
elsif last_string.match(Regexp.new(Regexp.quote(string)+"$"))
|
1448
567
|
# ���S��v
|
1449
568
|
# start = match.begin(0)
|
1450
569
|
# tail = match.end(0)
|
@@ -1463,7 +582,7 @@ class Aozora2Html
|
|
1463
582
|
false
|
1464
583
|
end
|
1465
584
|
end
|
1466
|
-
elsif last_string.is_a?(
|
585
|
+
elsif last_string.is_a?(Aozora2Html::Tag::ReferenceMentioned)
|
1467
586
|
inner = last_string.target_string
|
1468
587
|
if inner == string
|
1469
588
|
# ���S��v
|
@@ -1484,15 +603,15 @@ class Aozora2Html
|
|
1484
603
|
false
|
1485
604
|
end
|
1486
605
|
end
|
1487
|
-
|
606
|
+
|
1488
607
|
# ���������O���Q�Ƃ����ɖ߂�
|
1489
|
-
def recovery_front_reference
|
608
|
+
def recovery_front_reference(reference)
|
1490
609
|
reference.each{|elt|
|
1491
|
-
# if @
|
1492
|
-
if @ruby_buf.
|
1493
|
-
if @ruby_buf.
|
610
|
+
# if @ruby_buf.protected
|
611
|
+
if @ruby_buf.present?
|
612
|
+
if @ruby_buf.last_is_string?
|
1494
613
|
if elt.is_a?(String)
|
1495
|
-
@ruby_buf.
|
614
|
+
@ruby_buf.last_concat(elt)
|
1496
615
|
else
|
1497
616
|
@ruby_buf.push(elt)
|
1498
617
|
end
|
@@ -1512,8 +631,8 @@ class Aozora2Html
|
|
1512
631
|
end
|
1513
632
|
}
|
1514
633
|
end
|
1515
|
-
|
1516
|
-
def convert_japanese_number
|
634
|
+
|
635
|
+
def convert_japanese_number(command)
|
1517
636
|
tmp = command.tr("�O-�X", "0-9")
|
1518
637
|
tmp.tr!("���O�l�ܘZ������Z","1234567890")
|
1519
638
|
tmp.gsub!(/(\d)�\(\d)/){"#{$1}#{$2}"}
|
@@ -1523,29 +642,29 @@ class Aozora2Html
|
|
1523
642
|
tmp
|
1524
643
|
end
|
1525
644
|
|
1526
|
-
def kuten2png
|
645
|
+
def kuten2png(substring)
|
1527
646
|
desc = substring.gsub(/�u���v[��|��]/,"")
|
1528
647
|
match = desc.match(/[12]\-\d{1,2}\-\d{1,2}/)
|
1529
648
|
if (match and not(desc.match(/��0213�O��/)) and not(desc.match(/��.*��/)))
|
1530
649
|
@chuuki_table[:newjis] = true
|
1531
650
|
codes = match[0].split("-")
|
1532
|
-
folder = sprintf("%1d-%02d"
|
651
|
+
folder = sprintf("%1d-%02d", codes[0], codes[1])
|
1533
652
|
code = sprintf("%1d-%02d-%02d",*codes)
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
653
|
+
Aozora2Html::Tag::EmbedGaiji.new(self, folder, code, desc.gsub!("��",""))
|
654
|
+
else
|
655
|
+
substring
|
656
|
+
end
|
1538
657
|
end
|
1539
658
|
|
1540
|
-
def escape_gaiji
|
1541
|
-
|
659
|
+
def escape_gaiji(command)
|
660
|
+
_whole, kanji, line = command.match(/(?:��)(.*)(?:�A)(.*)/).to_a
|
1542
661
|
tmp = @images.assoc(kanji)
|
1543
662
|
if tmp
|
1544
663
|
tmp.push(line)
|
1545
664
|
else
|
1546
|
-
@images.push([kanji,line])
|
665
|
+
@images.push([kanji, line])
|
1547
666
|
end
|
1548
|
-
|
667
|
+
Aozora2Html::Tag::UnEmbedGaiji.new(self, command)
|
1549
668
|
end
|
1550
669
|
|
1551
670
|
def dispatch_gaiji
|
@@ -1553,19 +672,22 @@ class Aozora2Html
|
|
1553
672
|
if hook == "�m"
|
1554
673
|
read_char
|
1555
674
|
# embed?
|
1556
|
-
command,
|
675
|
+
command, _raw = read_to_nest("�n")
|
1557
676
|
try_emb = kuten2png(command)
|
1558
|
-
if try_emb
|
677
|
+
if try_emb != command
|
678
|
+
try_emb
|
679
|
+
elsif command.match(/U\+([0-9A-F]{4,5})/) && Aozora2Html::Tag::EmbedGaiji.use_unicode
|
680
|
+
unicode_num = $1
|
681
|
+
Aozora2Html::Tag::EmbedGaiji.new(self, nil, nil, command, unicode_num)
|
682
|
+
else
|
1559
683
|
# Unemb
|
1560
684
|
escape_gaiji(command)
|
1561
|
-
else
|
1562
|
-
try_emb
|
1563
685
|
end
|
1564
686
|
else
|
1565
687
|
"��"
|
1566
688
|
end
|
1567
689
|
end
|
1568
|
-
|
690
|
+
|
1569
691
|
def dispatch_aozora_command
|
1570
692
|
if @stream.peek_char(0) != "��"
|
1571
693
|
"�m"
|
@@ -1577,13 +699,13 @@ class Aozora2Html
|
|
1577
699
|
apply_burasage(command)
|
1578
700
|
|
1579
701
|
elsif command.match(/^��������/)
|
1580
|
-
exec_block_start_command(command
|
702
|
+
exec_block_start_command(command)
|
1581
703
|
elsif command.match(/^������/)
|
1582
|
-
exec_block_end_command(command
|
704
|
+
exec_block_end_command(command)
|
1583
705
|
|
1584
706
|
elsif command.match(/���蒍/)
|
1585
707
|
apply_warichu(command)
|
1586
|
-
elsif command.match(/������/)
|
708
|
+
elsif command.match(/������/)
|
1587
709
|
apply_jisage(command)
|
1588
710
|
elsif command.match(/fig(\d)+_(\d)+\.png/)
|
1589
711
|
exec_img_command(command,raw)
|
@@ -1598,9 +720,9 @@ class Aozora2Html
|
|
1598
720
|
elsif command.match(/1-7-8[2345]/)
|
1599
721
|
apply_dakuten_katakana(command)
|
1600
722
|
elsif command.match(/^([���O�l�ܘZ������\���㒆���b�������V�n�l]+)$/)
|
1601
|
-
|
723
|
+
Aozora2Html::Tag::Kaeriten.new(self, command)
|
1602
724
|
elsif command.match(/^�i(.+)�j$/)
|
1603
|
-
|
725
|
+
Aozora2Html::Tag::Okurigana.new(self, command.gsub!(/[�i�j]/,""))
|
1604
726
|
elsif command.match(/(�n�t��|���グ)(�I���)*$/)
|
1605
727
|
apply_chitsuki(command)
|
1606
728
|
elsif exec_inline_start_command(command)
|
@@ -1611,7 +733,7 @@ class Aozora2Html
|
|
1611
733
|
end
|
1612
734
|
end
|
1613
735
|
|
1614
|
-
def apply_burasage
|
736
|
+
def apply_burasage(command)
|
1615
737
|
tag = nil
|
1616
738
|
if implicit_close(:jisage)
|
1617
739
|
@terprip = false
|
@@ -1632,21 +754,21 @@ class Aozora2Html
|
|
1632
754
|
@tag_stack.push("") # dummy
|
1633
755
|
nil
|
1634
756
|
end
|
1635
|
-
|
1636
|
-
def jisage_width
|
757
|
+
|
758
|
+
def jisage_width(command)
|
1637
759
|
convert_japanese_number(command).match(/(\d*)(?:������)/)[1]
|
1638
760
|
end
|
1639
|
-
|
1640
|
-
def apply_jisage
|
761
|
+
|
762
|
+
def apply_jisage(command)
|
1641
763
|
if command.match(/�܂�/) or command.match(/�I���/)
|
1642
764
|
# �������I���
|
1643
|
-
explicit_close(:jisage)
|
765
|
+
explicit_close(:jisage)
|
1644
766
|
@indent_stack.pop
|
1645
767
|
nil
|
1646
768
|
else
|
1647
769
|
if command.match(/���̍s/)
|
1648
770
|
# 1�s����
|
1649
|
-
@buffer.unshift(
|
771
|
+
@buffer.unshift(Aozora2Html::Tag::OnelineJisage.new(self, jisage_width(command)))
|
1650
772
|
nil
|
1651
773
|
else
|
1652
774
|
if @buffer.length == 0 and @stream.peek_char(0) == "\r\n"
|
@@ -1656,28 +778,25 @@ class Aozora2Html
|
|
1656
778
|
# adhook hack
|
1657
779
|
@noprint = false
|
1658
780
|
@indent_stack.push(:jisage)
|
1659
|
-
|
781
|
+
Aozora2Html::Tag::MultilineJisage.new(self, jisage_width(command))
|
1660
782
|
else
|
1661
|
-
@buffer.unshift(
|
783
|
+
@buffer.unshift(Aozora2Html::Tag::OnelineJisage.new(self, jisage_width(command)))
|
1662
784
|
nil
|
1663
785
|
end
|
1664
786
|
end
|
1665
787
|
end
|
1666
788
|
end
|
1667
789
|
|
1668
|
-
def apply_warichu
|
790
|
+
def apply_warichu(command)
|
1669
791
|
if command.match(/�I���/)
|
1670
|
-
|
1671
|
-
if check == "�j"
|
1672
|
-
push_chars('</span>')
|
1673
|
-
else
|
792
|
+
if @stream.peek_char(0) != "�j"
|
1674
793
|
push_chars('�j')
|
1675
|
-
push_chars('</span>')
|
1676
794
|
end
|
795
|
+
push_chars('</span>')
|
1677
796
|
else
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
797
|
+
check = @ruby_buf.last
|
798
|
+
if check.is_a?(String) and check.match(/�i$/)
|
799
|
+
push_chars('<span class="warichu">')
|
1681
800
|
else
|
1682
801
|
push_chars('<span class="warichu">')
|
1683
802
|
push_chars('�i')
|
@@ -1686,7 +805,7 @@ class Aozora2Html
|
|
1686
805
|
nil
|
1687
806
|
end
|
1688
807
|
|
1689
|
-
def chitsuki_length
|
808
|
+
def chitsuki_length(command)
|
1690
809
|
command = convert_japanese_number(command)
|
1691
810
|
if match = command.match(/([0-9]+)��/)
|
1692
811
|
match[1]
|
@@ -1694,8 +813,8 @@ class Aozora2Html
|
|
1694
813
|
"0"
|
1695
814
|
end
|
1696
815
|
end
|
1697
|
-
|
1698
|
-
def apply_chitsuki
|
816
|
+
|
817
|
+
def apply_chitsuki(string, multiline = false)
|
1699
818
|
if string.match(/�����Œn�t���I���/) or
|
1700
819
|
string.match(/�����Ŏ��グ�I���/)
|
1701
820
|
explicit_close(:chitsuki)
|
@@ -1707,15 +826,29 @@ class Aozora2Html
|
|
1707
826
|
# �����s�w��
|
1708
827
|
implicit_close(:chitsuki)
|
1709
828
|
@indent_stack.push(:chitsuki)
|
1710
|
-
|
829
|
+
Aozora2Html::Tag::MultilineChitsuki.new(self, l)
|
1711
830
|
else
|
1712
831
|
# 1�s�̂�
|
1713
|
-
|
832
|
+
Aozora2Html::Tag::OnelineChitsuki.new(self, l)
|
1714
833
|
end
|
1715
834
|
end
|
1716
835
|
end
|
1717
836
|
|
1718
|
-
def new_midashi_id(
|
837
|
+
def new_midashi_id(size)
|
838
|
+
inc = 1
|
839
|
+
if size.kind_of?(String)
|
840
|
+
if size.match(SIZE_SMALL)
|
841
|
+
inc = 1
|
842
|
+
elsif size.match(SIZE_MIDDLE)
|
843
|
+
inc = 10
|
844
|
+
elsif size.match(SIZE_LARGE)
|
845
|
+
inc = 100
|
846
|
+
else
|
847
|
+
raise Aozora2Html::Error, I18n.t(:undefined_header)
|
848
|
+
end
|
849
|
+
else
|
850
|
+
inc = size
|
851
|
+
end
|
1719
852
|
@midashi_id += inc
|
1720
853
|
end
|
1721
854
|
|
@@ -1724,41 +857,41 @@ class Aozora2Html
|
|
1724
857
|
midashi_type = :normal
|
1725
858
|
if command.match(/���s/)
|
1726
859
|
midashi_type = :dogyo
|
1727
|
-
elsif command.match
|
860
|
+
elsif command.match(/��/)
|
1728
861
|
midashi_type = :mado
|
1729
862
|
else
|
1730
863
|
@terprip = false
|
1731
864
|
end
|
1732
|
-
|
865
|
+
Aozora2Html::Tag::MultilineMidashi.new(self,command,midashi_type)
|
1733
866
|
end
|
1734
867
|
|
1735
868
|
def apply_yokogumi(command)
|
1736
869
|
@indent_stack.push(:yokogumi)
|
1737
|
-
|
870
|
+
Aozora2Html::Tag::MultilineYokogumi.new(self)
|
1738
871
|
end
|
1739
872
|
|
1740
873
|
def apply_keigakomi(command)
|
1741
874
|
@indent_stack.push(:keigakomi)
|
1742
|
-
|
875
|
+
Aozora2Html::Tag::Keigakomi.new(self)
|
1743
876
|
end
|
1744
877
|
|
1745
878
|
def apply_caption(command)
|
1746
879
|
@indent_stack.push(:caption)
|
1747
|
-
|
880
|
+
Aozora2Html::Tag::MultilineCaption.new(self)
|
1748
881
|
end
|
1749
882
|
|
1750
883
|
def apply_jizume(command)
|
1751
884
|
w = convert_japanese_number(command).match(/(\d*)(?:���l��)/)[1]
|
1752
885
|
@indent_stack.push(:jizume)
|
1753
|
-
|
886
|
+
Aozora2Html::Tag::Jizume.new(self, w)
|
1754
887
|
end
|
1755
|
-
|
1756
|
-
def push_block_tag
|
888
|
+
|
889
|
+
def push_block_tag(tag,closing)
|
1757
890
|
push_chars(tag)
|
1758
891
|
closing.concat(tag.close_tag)
|
1759
892
|
end
|
1760
893
|
|
1761
|
-
def exec_inline_start_command
|
894
|
+
def exec_inline_start_command(command)
|
1762
895
|
case command
|
1763
896
|
when "���L�t��"
|
1764
897
|
@style_stack.push([command,'</ruby>'])
|
@@ -1775,6 +908,9 @@ class Aozora2Html
|
|
1775
908
|
when "�L���v�V����"
|
1776
909
|
@style_stack.push([command,'</span>'])
|
1777
910
|
push_chars('<span class="caption">')
|
911
|
+
when "����"
|
912
|
+
@style_stack.push([command,'</span>'])
|
913
|
+
push_chars('<span class="warigaki">')
|
1778
914
|
when "�匩�o��"
|
1779
915
|
@style_stack.push([command,'</a></h3>'])
|
1780
916
|
@terprip = false
|
@@ -1808,7 +944,7 @@ class Aozora2Html
|
|
1808
944
|
else
|
1809
945
|
if command.match(/(.*)�i�K(..)�ȕ���/)
|
1810
946
|
@style_stack.push([command,'</span>'])
|
1811
|
-
|
947
|
+
_whole, nest, style = command.match(/(.*)�i�K(..)�ȕ���/).to_a
|
1812
948
|
times = convert_japanese_number(nest).to_i
|
1813
949
|
daisho = if style.match("��")
|
1814
950
|
:sho
|
@@ -1816,30 +952,14 @@ class Aozora2Html
|
|
1816
952
|
:dai
|
1817
953
|
end
|
1818
954
|
html_class = daisho.to_s + times.to_s
|
1819
|
-
size =
|
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
|
955
|
+
size = Utils.create_font_size(times, daisho)
|
1836
956
|
push_chars("<span class=\"#{html_class}\" style=\"font-size: #{size};\">")
|
1837
957
|
else
|
1838
958
|
## Decoration ##
|
1839
959
|
key = command
|
1840
960
|
filter = lambda{|x| x}
|
1841
961
|
if command.match(/(�E|��|��|��)��(.*)/)
|
1842
|
-
|
962
|
+
_whole, dir, com = command.match(/(�E|��|��|��)��(.*)/).to_a
|
1843
963
|
# renew command
|
1844
964
|
key = com
|
1845
965
|
if command.match(/�_/)
|
@@ -1854,23 +974,23 @@ class Aozora2Html
|
|
1854
974
|
end
|
1855
975
|
end
|
1856
976
|
end
|
1857
|
-
|
1858
|
-
found =
|
977
|
+
|
978
|
+
found = COMMAND_TABLE[key]
|
1859
979
|
# found = [class, tag]
|
1860
980
|
if found
|
1861
981
|
@style_stack.push([command,"</#{found[1]}>"])
|
1862
|
-
if found[1] == "em" # or found[1] == "strong"
|
1863
|
-
@chuuki_table[:em] = true
|
1864
|
-
end
|
1865
982
|
push_chars("<#{found[1]} class=\"#{filter.call(found[0])}\">")
|
1866
983
|
else
|
984
|
+
if $DEBUG
|
985
|
+
puts "�x��(#{line_number}�s��):�u#{key}�v�͖��Ή��̃R�}���h�̂��ߖ������܂�"
|
986
|
+
end
|
1867
987
|
nil
|
1868
988
|
end
|
1869
989
|
end
|
1870
990
|
end
|
1871
991
|
end
|
1872
992
|
|
1873
|
-
def exec_inline_end_command
|
993
|
+
def exec_inline_end_command(command)
|
1874
994
|
encount = command.sub("�I���","")
|
1875
995
|
if encount == "�{��"
|
1876
996
|
# force to finish main_text
|
@@ -1878,19 +998,21 @@ class Aozora2Html
|
|
1878
998
|
ensure_close
|
1879
999
|
@noprint = true
|
1880
1000
|
@out.print "</div>\r\n<div class=\"after_text\">\r\n<hr />\r\n"
|
1881
|
-
elsif encount.match("���L�t��") and @style_stack.
|
1001
|
+
elsif encount.match("���L�t��") and @style_stack.last_command == "���L�t��"
|
1882
1002
|
# special inline ruby
|
1883
1003
|
@style_stack.pop
|
1884
|
-
|
1004
|
+
_whole, ruby = encount.match("�u(.*)�v�̒��L�t��").to_a
|
1885
1005
|
push_char("</rb><rp>�i</rp><rt>#{ruby}</rt><rp>�j</rp></ruby>")
|
1886
|
-
elsif @style_stack.
|
1006
|
+
elsif @style_stack.last_command.match(encount)
|
1887
1007
|
push_chars(@style_stack.pop[1])
|
1888
1008
|
else
|
1889
|
-
raise
|
1009
|
+
raise Aozora2Html::Error, "#{encount}���I�����悤�Ƃ��܂������A#{@style_stack.last_command}���ł�"
|
1890
1010
|
end
|
1891
1011
|
end
|
1892
1012
|
|
1893
|
-
def exec_block_start_command
|
1013
|
+
def exec_block_start_command(command)
|
1014
|
+
original_command = command.dup
|
1015
|
+
command.sub!(/^��������/, "")
|
1894
1016
|
match = ""
|
1895
1017
|
if command.match(/������/)
|
1896
1018
|
push_block_tag(apply_jisage(command),match)
|
@@ -1929,24 +1051,24 @@ class Aozora2Html
|
|
1929
1051
|
end
|
1930
1052
|
push_block_tag(apply_caption(command),match)
|
1931
1053
|
end
|
1932
|
-
|
1054
|
+
|
1933
1055
|
if command.match(/����/)
|
1934
1056
|
if match != ""
|
1935
1057
|
@indent_stack.pop
|
1936
1058
|
end
|
1937
|
-
push_block_tag(
|
1059
|
+
push_block_tag(Aozora2Html::Tag::MultilineStyle.new(self, "futoji"),match)
|
1938
1060
|
@indent_stack.push(:futoji)
|
1939
1061
|
end
|
1940
1062
|
if command.match(/�Α�/)
|
1941
1063
|
if match != ""
|
1942
1064
|
@indent_stack.pop
|
1943
1065
|
end
|
1944
|
-
push_block_tag(
|
1066
|
+
push_block_tag(Aozora2Html::Tag::MultilineStyle.new(self, "shatai"),match)
|
1945
1067
|
@indent_stack.push(:shatai)
|
1946
|
-
end
|
1068
|
+
end
|
1947
1069
|
|
1948
1070
|
if command.match(/(.*)�i�K(..)�ȕ���/)
|
1949
|
-
|
1071
|
+
_whole, nest, style = command.match(/(.*)�i�K(..)�ȕ���/).to_a
|
1950
1072
|
if match != ""
|
1951
1073
|
@indent_stack.pop
|
1952
1074
|
end
|
@@ -1955,76 +1077,86 @@ class Aozora2Html
|
|
1955
1077
|
else
|
1956
1078
|
:dai
|
1957
1079
|
end
|
1958
|
-
push_block_tag(
|
1959
|
-
|
1960
|
-
|
1080
|
+
push_block_tag(Aozora2Html::Tag::FontSize.new(self,
|
1081
|
+
convert_japanese_number(nest).to_i,
|
1082
|
+
daisho),
|
1083
|
+
match)
|
1961
1084
|
@indent_stack.push(daisho)
|
1962
1085
|
end
|
1963
1086
|
|
1964
1087
|
if match == ""
|
1965
|
-
apply_rest_notes(
|
1088
|
+
apply_rest_notes(original_command)
|
1966
1089
|
else
|
1967
1090
|
@tag_stack.push(match)
|
1968
1091
|
nil
|
1969
1092
|
end
|
1970
1093
|
end
|
1971
1094
|
|
1972
|
-
def
|
1095
|
+
def detect_command_mode(command)
|
1096
|
+
if command.match(/������/)
|
1097
|
+
:jisage
|
1098
|
+
elsif command.match(/(�n�t��|���グ)�I���$/)
|
1099
|
+
:chitsuki
|
1100
|
+
elsif command.match(/���o��/)
|
1101
|
+
:midashi
|
1102
|
+
elsif command.match(/���l��/)
|
1103
|
+
:jizume
|
1104
|
+
elsif command.match(/���g��/)
|
1105
|
+
:yokogumi
|
1106
|
+
elsif command.match(/�r�͂�/)
|
1107
|
+
:keigakomi
|
1108
|
+
elsif command.match(/�L���v�V����/)
|
1109
|
+
:caption
|
1110
|
+
elsif command.match(/����/)
|
1111
|
+
:futoji
|
1112
|
+
elsif command.match(/�Α�/)
|
1113
|
+
:shatai
|
1114
|
+
elsif command.match(/�傫�ȕ���/)
|
1115
|
+
:dai
|
1116
|
+
elsif command.match(/�����ȕ���/)
|
1117
|
+
:sho
|
1118
|
+
else
|
1119
|
+
nil
|
1120
|
+
end
|
1121
|
+
end
|
1122
|
+
|
1123
|
+
def exec_block_end_command(command)
|
1124
|
+
original_command = command.dup
|
1125
|
+
command.sub!(/^������/, "")
|
1973
1126
|
match = false
|
1974
|
-
|
1975
|
-
|
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
|
1127
|
+
mode = detect_command_mode(command)
|
1128
|
+
if mode
|
1997
1129
|
explicit_close(mode)
|
1998
1130
|
match = @indent_stack.pop
|
1999
1131
|
end
|
2000
|
-
|
1132
|
+
|
2001
1133
|
if match
|
2002
|
-
if
|
1134
|
+
if !match.is_a?(String)
|
2003
1135
|
@terprip = false
|
2004
1136
|
end
|
2005
1137
|
nil
|
2006
1138
|
else
|
2007
|
-
apply_rest_notes(
|
1139
|
+
apply_rest_notes(original_command)
|
2008
1140
|
end
|
2009
1141
|
end
|
2010
|
-
|
2011
|
-
def exec_img_command
|
1142
|
+
|
1143
|
+
def exec_img_command(command,raw)
|
2012
1144
|
match = raw.match(/(.*)�i(fig.+\.png)(�A��([0-9]+)�~�c([0-9]+))*�j����/)
|
2013
1145
|
if match
|
2014
|
-
|
1146
|
+
_whole, alt, src, _wh, width, height = match.to_a
|
2015
1147
|
css_class = if alt.match(/�ʐ^/)
|
2016
1148
|
"photo"
|
2017
1149
|
else
|
2018
1150
|
"illustration"
|
2019
1151
|
end
|
2020
|
-
|
1152
|
+
Aozora2Html::Tag::Img.new(self, src, css_class, alt, width, height)
|
2021
1153
|
else
|
2022
1154
|
apply_rest_notes(command)
|
2023
1155
|
end
|
2024
1156
|
end
|
2025
1157
|
|
2026
|
-
def exec_frontref_command
|
2027
|
-
|
1158
|
+
def exec_frontref_command(command)
|
1159
|
+
_whole, reference, spec1, spec2 = command.match(/�u([^�u�v]*(?:�u.+�v)*[^�u�v]*)�v[�ɂ͂�](�u.+�v��)*(.+)/).to_a
|
2028
1160
|
spec = if spec1
|
2029
1161
|
spec1 + spec2
|
2030
1162
|
else
|
@@ -2042,37 +1174,37 @@ class Aozora2Html
|
|
2042
1174
|
apply_rest_notes(command)
|
2043
1175
|
end
|
2044
1176
|
|
2045
|
-
def multiply
|
1177
|
+
def multiply(bouki, times)
|
2046
1178
|
s = ""
|
2047
1179
|
(times-1).times{
|
2048
1180
|
s += bouki
|
2049
|
-
s += "
|
1181
|
+
s += " "
|
2050
1182
|
}
|
2051
1183
|
s + bouki
|
2052
1184
|
end
|
2053
1185
|
|
2054
|
-
def include_ruby?
|
1186
|
+
def include_ruby?(array)
|
2055
1187
|
array.index{|elt|
|
2056
|
-
if elt.is_a?(
|
1188
|
+
if elt.is_a?(Aozora2Html::Tag::Ruby)
|
2057
1189
|
true
|
2058
|
-
elsif elt.is_a?(
|
1190
|
+
elsif elt.is_a?(Aozora2Html::Tag::ReferenceMentioned)
|
2059
1191
|
if elt.target.is_a?(Array)
|
2060
1192
|
include_ruby?(elt.target)
|
2061
1193
|
else
|
2062
|
-
elt.target.is_a?(
|
1194
|
+
elt.target.is_a?(Aozora2Html::Tag::Ruby)
|
2063
1195
|
end
|
2064
1196
|
end
|
2065
1197
|
}
|
2066
1198
|
end
|
2067
|
-
|
1199
|
+
|
2068
1200
|
# complex ruby wrap up utilities -- don't erase! we will use soon ...
|
2069
|
-
def rearrange_ruby_tag
|
1201
|
+
def rearrange_ruby_tag(targets, upper_ruby, under_ruby = "")
|
2070
1202
|
target,upper,under = rearrange_ruby(targets, upper_ruby, under_ruby)
|
2071
|
-
|
1203
|
+
Aozora2Html::Tag::Ruby.new(self, target,upper,under)
|
2072
1204
|
end
|
2073
|
-
|
1205
|
+
|
2074
1206
|
# ruby�^�O�̍Ċ��蓖��
|
2075
|
-
def rearrange_ruby
|
1207
|
+
def rearrange_ruby(targets, upper_ruby, under_ruby = "")
|
2076
1208
|
if include_ruby?(targets)
|
2077
1209
|
new_targets = []
|
2078
1210
|
new_upper = if upper_ruby != ""
|
@@ -2086,31 +1218,31 @@ class Aozora2Html
|
|
2086
1218
|
[]
|
2087
1219
|
end
|
2088
1220
|
if new_upper.length > 1 and new_under.length > 1
|
2089
|
-
raise
|
1221
|
+
raise Aozora2Html::Error, "1�̒P���3�̃��r�͂����܂���"
|
2090
1222
|
end
|
2091
|
-
|
1223
|
+
|
2092
1224
|
targets.each{|x|
|
2093
|
-
if x.is_a?(
|
1225
|
+
if x.is_a?(Aozora2Html::Tag::Ruby)
|
2094
1226
|
if x.target.is_a?(Array)
|
2095
|
-
# inner
|
2096
|
-
raise
|
1227
|
+
# inner Aozora2Html::Tag::Ruby is already complex ... give up
|
1228
|
+
raise Aozora2Html::Error, "�����ӏ���2�̃��r�͂����܂���"
|
2097
1229
|
else
|
2098
1230
|
if x.ruby != ""
|
2099
1231
|
if new_upper.is_a?(Array)
|
2100
1232
|
new_upper.push(x.ruby)
|
2101
1233
|
else
|
2102
|
-
raise
|
1234
|
+
raise Aozora2Html::Error, "�����ӏ���2�̃��r�͂����܂���"
|
2103
1235
|
end
|
2104
1236
|
else
|
2105
1237
|
if new_under.is_a?(Array)
|
2106
1238
|
new_under.push(x.under_ruby)
|
2107
1239
|
else
|
2108
|
-
raise
|
1240
|
+
raise Aozora2Html::Error, "�����ӏ���2�̃��r�͂����܂���"
|
2109
1241
|
end
|
2110
1242
|
end
|
2111
1243
|
new_targets.push(x.target)
|
2112
1244
|
end
|
2113
|
-
elsif x.is_a?(
|
1245
|
+
elsif x.is_a?(Aozora2Html::Tag::ReferenceMentioned)
|
2114
1246
|
if x.target.is_a?(Array)
|
2115
1247
|
# recursive
|
2116
1248
|
tar,up,un = rearrange_ruby(x.target,"","")
|
@@ -2122,12 +1254,12 @@ class Aozora2Html
|
|
2122
1254
|
if new_under.is_a?(Array)
|
2123
1255
|
new_under.concat(un)
|
2124
1256
|
elsif un.to_s.length > 0
|
2125
|
-
raise
|
1257
|
+
raise Aozora2Html::Error, "�����ӏ���2�̃��r�͂����܂���"
|
2126
1258
|
end
|
2127
1259
|
if new_upper.is_a?(Array)
|
2128
1260
|
new_upper.concat(up)
|
2129
1261
|
elsif up.to_s.length > 0
|
2130
|
-
raise
|
1262
|
+
raise Aozora2Html::Error, "�����ӏ���2�̃��r�͂����܂���"
|
2131
1263
|
end
|
2132
1264
|
else
|
2133
1265
|
new_targets.push(x)
|
@@ -2153,36 +1285,36 @@ class Aozora2Html
|
|
2153
1285
|
[targets, upper_ruby, under_ruby]
|
2154
1286
|
end
|
2155
1287
|
end
|
2156
|
-
|
2157
|
-
def exec_style
|
1288
|
+
|
1289
|
+
def exec_style(targets, command)
|
2158
1290
|
try_kuten = kuten2png(command)
|
2159
1291
|
if try_kuten != command
|
2160
1292
|
try_kuten
|
2161
1293
|
elsif command.match(/�c����/)
|
2162
|
-
|
1294
|
+
Aozora2Html::Tag::Dir.new(self, targets)
|
2163
1295
|
elsif command.match(/���g��/)
|
2164
|
-
|
1296
|
+
Aozora2Html::Tag::InlineYokogumi.new(self, targets)
|
2165
1297
|
elsif command.match(/�r�͂�/)
|
2166
|
-
|
1298
|
+
Aozora2Html::Tag::InlineKeigakomi.new(self, targets)
|
2167
1299
|
elsif command.match(/�L���v�V����/)
|
2168
|
-
|
1300
|
+
Aozora2Html::Tag::InlineCaption.new(self, targets)
|
2169
1301
|
elsif command.match(/�Ԃ�_/)
|
2170
|
-
|
1302
|
+
Aozora2Html::Tag::Kaeriten.new(self, targets)
|
2171
1303
|
elsif command.match(/�P�_���艼��/)
|
2172
|
-
|
1304
|
+
Aozora2Html::Tag::Okurigana.new(self, targets)
|
2173
1305
|
elsif command.match(/���o��/)
|
2174
1306
|
midashi_type = :normal
|
2175
1307
|
if command.match(/���s/)
|
2176
1308
|
midashi_type = :dogyo
|
2177
|
-
elsif command.match
|
1309
|
+
elsif command.match(/��/)
|
2178
1310
|
midashi_type = :mado
|
2179
1311
|
else
|
2180
1312
|
@terprip = false
|
2181
1313
|
end
|
2182
|
-
|
1314
|
+
Aozora2Html::Tag::Midashi.new(self, targets, command, midashi_type)
|
2183
1315
|
elsif command.match(/(.*)�i�K(..)�ȕ���/)
|
2184
|
-
|
2185
|
-
|
1316
|
+
_whole, nest, style = command.match(/(.*)�i�K(..)�ȕ���/).to_a
|
1317
|
+
Aozora2Html::Tag::InlineFontSize.new(self,targets,
|
2186
1318
|
convert_japanese_number(nest).to_i,
|
2187
1319
|
if style.match("��")
|
2188
1320
|
:sho
|
@@ -2190,14 +1322,14 @@ class Aozora2Html
|
|
2190
1322
|
:dai
|
2191
1323
|
end)
|
2192
1324
|
elsif command.match(/(��|��)�Ɂu([^�v]*)�v��(���r|���L)/)
|
2193
|
-
|
2194
|
-
if targets.length == 1 and targets[0].is_a?(
|
1325
|
+
_whole, dir, under = command.match(/(��|��)�Ɂu([^�v]*)�v��(���r|���L)/).to_a
|
1326
|
+
if targets.length == 1 and targets[0].is_a?(Aozora2Html::Tag::Ruby)
|
2195
1327
|
tag = targets[0]
|
2196
1328
|
if tag.under_ruby == ""
|
2197
1329
|
tag.under_ruby = under
|
2198
1330
|
tag
|
2199
1331
|
else
|
2200
|
-
raise
|
1332
|
+
raise Aozora2Html::Error, "1�̒P���3�̃��r�͂����܂���"
|
2201
1333
|
end
|
2202
1334
|
else
|
2203
1335
|
rearrange_ruby_tag(targets,"",under)
|
@@ -2205,12 +1337,12 @@ class Aozora2Html
|
|
2205
1337
|
elsif command.match(/�u(.+?)�v�̒��L/)
|
2206
1338
|
rearrange_ruby_tag(targets,/�u(.+?)�v�̒��L/.match(command).to_a[1])
|
2207
1339
|
elsif command.match(/�u(.)�v�̖T�L/)
|
2208
|
-
rearrange_ruby_tag(targets,multiply( /�u(.)�v�̖T�L/.match(command).to_a[1],
|
1340
|
+
rearrange_ruby_tag(targets,multiply( /�u(.)�v�̖T�L/.match(command).to_a[1], targets.to_s.length))
|
2209
1341
|
else
|
2210
1342
|
## direction fix! ##
|
2211
1343
|
filter = lambda{|x| x}
|
2212
1344
|
if command.match(/(�E|��|��|��)��(.*)/)
|
2213
|
-
|
1345
|
+
_whole, dir, com = command.match(/(�E|��|��|��)��(.*)/).to_a
|
2214
1346
|
# renew command
|
2215
1347
|
command = com
|
2216
1348
|
if command.match(/�_/)
|
@@ -2225,81 +1357,73 @@ class Aozora2Html
|
|
2225
1357
|
end
|
2226
1358
|
end
|
2227
1359
|
end
|
2228
|
-
|
2229
|
-
found =
|
1360
|
+
|
1361
|
+
found = COMMAND_TABLE[command]
|
2230
1362
|
# found = [class, tag]
|
2231
1363
|
if found
|
2232
|
-
|
2233
|
-
@chuuki_table[:em] = true
|
2234
|
-
end
|
2235
|
-
Decorate_tag.new(self, targets, filter.call(found[0]), found[1])
|
1364
|
+
Aozora2Html::Tag::Decorate.new(self, targets, filter.call(found[0]), found[1])
|
2236
1365
|
else
|
2237
1366
|
nil
|
2238
1367
|
end
|
2239
1368
|
end
|
2240
1369
|
end
|
2241
1370
|
|
2242
|
-
def apply_dakuten_katakana
|
1371
|
+
def apply_dakuten_katakana(command)
|
2243
1372
|
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
|
1373
|
+
frontref = DAKUTEN_KATAKANA_TABLE[n]
|
2255
1374
|
if found = search_front_reference(frontref)
|
2256
|
-
|
1375
|
+
Aozora2Html::Tag::DakutenKatakana.new(self, n,found.join)
|
2257
1376
|
else
|
2258
1377
|
apply_rest_notes(command)
|
2259
1378
|
end
|
2260
1379
|
end
|
2261
1380
|
|
1381
|
+
# ���̎��_�̏���
|
1382
|
+
#
|
1383
|
+
# ���̎��_�͌��̂܂o�͂���̂Ńt�b�^�́u�\�L�ɂ��āv�ŏo�͂��邩�ǂ����̃t���O���������s��
|
2262
1384
|
def assign_kunoji
|
2263
1385
|
second = @stream.peek_char(0)
|
2264
1386
|
case second
|
2265
|
-
when
|
1387
|
+
when NOJI
|
2266
1388
|
@chuuki_table[:kunoji] = true
|
2267
|
-
when
|
2268
|
-
if @stream.peek_char(1) ==
|
1389
|
+
when DAKUTEN
|
1390
|
+
if @stream.peek_char(1) == NOJI
|
2269
1391
|
@chuuki_table[:dakutenkunoji] = true
|
2270
1392
|
end
|
2271
1393
|
end
|
2272
1394
|
end
|
2273
1395
|
|
2274
|
-
def apply_rest_notes
|
1396
|
+
def apply_rest_notes(command)
|
2275
1397
|
@chuuki_table[:chuki] = true
|
2276
|
-
|
1398
|
+
Aozora2Html::Tag::EditorNote.new(self, command)
|
2277
1399
|
end
|
2278
1400
|
|
2279
1401
|
# �b�������Ƃ��͕����������ruby_buf�����Ȃ��Ⴂ���Ȃ�
|
2280
1402
|
def apply_ruby
|
2281
|
-
@
|
2282
|
-
ruby,
|
1403
|
+
@ruby_buf.protected = nil
|
1404
|
+
ruby, _raw = read_to_nest("�t")
|
2283
1405
|
if ruby.length == 0
|
2284
1406
|
# escaped ruby character
|
2285
1407
|
return "�s�t"
|
2286
1408
|
end
|
2287
1409
|
ans = ""
|
2288
1410
|
notes = []
|
2289
|
-
@ruby_buf.each
|
2290
|
-
if token.is_a?(
|
1411
|
+
@ruby_buf.each do |token|
|
1412
|
+
if token.is_a?(Aozora2Html::Tag::UnEmbedGaiji)
|
2291
1413
|
ans.concat("��")
|
2292
1414
|
token.escape!
|
2293
1415
|
notes.push(token)
|
2294
1416
|
else
|
2295
1417
|
ans.concat(token.to_s)
|
2296
|
-
end
|
2297
|
-
|
1418
|
+
end
|
1419
|
+
end
|
1420
|
+
@buffer.push(Aozora2Html::Tag::Ruby.new(self, ans, ruby))
|
2298
1421
|
@buffer = @buffer + notes
|
2299
|
-
@ruby_buf
|
1422
|
+
@ruby_buf.clear
|
2300
1423
|
nil
|
2301
1424
|
end
|
2302
1425
|
|
1426
|
+
# parse_body�̃t�b�^��
|
2303
1427
|
def parse_tail
|
2304
1428
|
char = read_char
|
2305
1429
|
check = true
|
@@ -2308,33 +1432,39 @@ class Aozora2Html
|
|
2308
1432
|
check = false
|
2309
1433
|
char = read_accent
|
2310
1434
|
when @endchar
|
2311
|
-
|
1435
|
+
throw :terminate
|
2312
1436
|
when "��"
|
2313
1437
|
char = dispatch_gaiji
|
2314
1438
|
when "�m"
|
2315
1439
|
char = dispatch_aozora_command
|
2316
|
-
when
|
2317
|
-
|
1440
|
+
when KU
|
1441
|
+
assign_kunoji
|
2318
1442
|
when "�s"
|
2319
1443
|
char = apply_ruby
|
2320
1444
|
end
|
2321
|
-
|
1445
|
+
|
1446
|
+
case char
|
1447
|
+
when "\r\n"
|
2322
1448
|
tail_output
|
2323
|
-
|
2324
|
-
|
2325
|
-
@
|
2326
|
-
|
1449
|
+
when RUBY_PREFIX
|
1450
|
+
@ruby_buf.dump(@buffer)
|
1451
|
+
@ruby_buf.protected = true
|
1452
|
+
when nil
|
1453
|
+
# noop
|
1454
|
+
else
|
2327
1455
|
if check
|
2328
|
-
illegal_char_check(char)
|
1456
|
+
illegal_char_check(char, line_number)
|
2329
1457
|
end
|
2330
1458
|
push_chars(char)
|
2331
1459
|
end
|
2332
1460
|
end
|
2333
1461
|
|
1462
|
+
# general_output�̃t�b�^��
|
2334
1463
|
def tail_output
|
2335
|
-
|
1464
|
+
@ruby_buf.dump(@buffer)
|
2336
1465
|
string = @buffer.join
|
2337
|
-
@ruby_buf
|
1466
|
+
@ruby_buf.clear
|
1467
|
+
@buffer = []
|
2338
1468
|
string.gsub!("info@aozora.gr.jp",'<a href="mailto: info@aozora.gr.jp">info@aozora.gr.jp</a>')
|
2339
1469
|
string.gsub!("�Ɂihttp://www.aozora.gr.jp/�j"){"<a href=\"http://www.aozora.gr.jp/\">#{$&}</a>"}
|
2340
1470
|
if string.match(/(<br \/>$|<\/p>$|<\/h\d>$|<div.*>$|<\/div>$|^<[^>]*>$)/)
|
@@ -2343,8 +1473,9 @@ class Aozora2Html
|
|
2343
1473
|
@out.print string, "<br />\r\n"
|
2344
1474
|
end
|
2345
1475
|
end
|
2346
|
-
|
2347
|
-
|
1476
|
+
|
1477
|
+
# `���\�L�ɂ���`�Ŏg�p�������L�����o�͂���
|
1478
|
+
def hyoki
|
2348
1479
|
# <br /> times fix
|
2349
1480
|
@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
1481
|
@out.print "\t<li>���̃t�@�C���� W3C ���� XHTML1.1 �ɂ������`���ō쐬����Ă��܂��B</li>\r\n"
|
@@ -2353,22 +1484,19 @@ class Aozora2Html
|
|
2353
1484
|
end
|
2354
1485
|
if @chuuki_table[:kunoji]
|
2355
1486
|
if @chuuki_table[:dakutenkunoji]
|
2356
|
-
@out.print "\t<li>�u���̎��_�v�́u#{
|
1487
|
+
@out.print "\t<li>�u���̎��_�v�́u#{KU}#{NOJI}�v�ŁA�u���_�t�����̎��_�v�́u#{KU}#{DAKUTEN}#{NOJI}�v�ŕ\���܂����B</li>\r\n"
|
2357
1488
|
else
|
2358
|
-
@out.print "\t<li>�u���̎��_�v�́u#{
|
1489
|
+
@out.print "\t<li>�u���̎��_�v�́u#{KU}#{NOJI}�v�ŕ\���܂����B</li>\r\n"
|
2359
1490
|
end
|
2360
1491
|
elsif @chuuki_table[:dakutenkunoji]
|
2361
|
-
@out.print "\t<li>�u���_�t�����̎��_�v�́u#{
|
1492
|
+
@out.print "\t<li>�u���_�t�����̎��_�v�́u#{KU}#{DAKUTEN}#{NOJI}�v�ŕ\���܂����B</li>\r\n"
|
2362
1493
|
end
|
2363
|
-
if @chuuki_table[:newjis]
|
1494
|
+
if @chuuki_table[:newjis] && !Aozora2Html::Tag::EmbedGaiji.use_jisx0213
|
2364
1495
|
@out.print "\t<li>�u���̎��_�v���̂���JIS X 0213�ɂ��镶���́A�摜�����Ė��ߍ��݂܂����B</li>\r\n"
|
2365
1496
|
end
|
2366
|
-
if @chuuki_table[:accent]
|
1497
|
+
if @chuuki_table[:accent] && !Aozora2Html::Tag::Accent.use_jisx0213
|
2367
1498
|
@out.print "\t<li>�A�N�Z���g�����t�����e�������́A�摜�����Ė��ߍ��݂܂����B</li>\r\n"
|
2368
1499
|
end
|
2369
|
-
# if @chuuki_table[:em]
|
2370
|
-
# @out.print "\t<li>�T�_�⌗�_�A�T���̕t���������́A�����\���ɂ��܂����B</li>\r\n"
|
2371
|
-
# end
|
2372
1500
|
if @images[0]
|
2373
1501
|
@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
1502
|
@images.each{|cell|
|
@@ -2396,139 +1524,6 @@ class Aozora2Html
|
|
2396
1524
|
end
|
2397
1525
|
end
|
2398
1526
|
|
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
1527
|
if $0 == __FILE__
|
2533
1528
|
# todo: �����`�F�b�N�Ƃ�
|
2534
1529
|
Aozora2Html.new($*[0],$*[1]).process
|