aozora2html 2.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubocop.yml +19 -0
- data/.github/workflows/ruby.yml +5 -3
- data/.gitignore +1 -0
- data/.rubocop.yml +38 -151
- data/.rubocop_todo.yml +7 -0
- data/CHANGELOG.md +41 -0
- data/Gemfile +2 -0
- data/Guardfile +3 -1
- data/HACKING.md +45 -0
- data/README.md +14 -6
- data/Rakefile +12 -5
- data/aozora2html.gemspec +25 -23
- data/bin/aozora2html +21 -19
- data/lib/aozora2html/accent_parser.rb +62 -54
- data/lib/aozora2html/error.rb +5 -4
- data/lib/aozora2html/header.rb +20 -18
- data/lib/aozora2html/i18n.rb +40 -20
- data/lib/aozora2html/midashi_counter.rb +32 -0
- data/lib/aozora2html/ruby_buffer.rb +63 -28
- data/lib/aozora2html/string_refinements.rb +36 -0
- data/lib/aozora2html/style_stack.rb +6 -0
- data/lib/aozora2html/tag/accent.rb +10 -12
- data/lib/aozora2html/tag/block.rb +11 -9
- data/lib/aozora2html/tag/chitsuki.rb +6 -2
- data/lib/aozora2html/tag/dakuten_katakana.rb +10 -8
- data/lib/aozora2html/tag/decorate.rb +4 -3
- data/lib/aozora2html/tag/dir.rb +4 -2
- data/lib/aozora2html/tag/editor_note.rb +7 -4
- data/lib/aozora2html/tag/embed_gaiji.rb +15 -11
- data/lib/aozora2html/tag/font_size.rb +5 -2
- data/lib/aozora2html/tag/gaiji.rb +4 -3
- data/lib/aozora2html/tag/img.rb +4 -4
- data/lib/aozora2html/tag/indent.rb +3 -3
- data/lib/aozora2html/tag/inline.rb +10 -7
- data/lib/aozora2html/tag/inline_caption.rb +4 -2
- data/lib/aozora2html/tag/inline_font_size.rb +4 -3
- data/lib/aozora2html/tag/inline_keigakomi.rb +4 -2
- data/lib/aozora2html/tag/inline_yokogumi.rb +4 -3
- data/lib/aozora2html/tag/jisage.rb +3 -1
- data/lib/aozora2html/tag/jizume.rb +3 -0
- data/lib/aozora2html/tag/kaeriten.rb +4 -2
- data/lib/aozora2html/tag/keigakomi.rb +15 -9
- data/lib/aozora2html/tag/kunten.rb +4 -4
- data/lib/aozora2html/tag/midashi.rb +3 -1
- data/lib/aozora2html/tag/multiline.rb +3 -0
- data/lib/aozora2html/tag/multiline_caption.rb +6 -8
- data/lib/aozora2html/tag/multiline_chitsuki.rb +3 -1
- data/lib/aozora2html/tag/multiline_jisage.rb +3 -1
- data/lib/aozora2html/tag/multiline_midashi.rb +6 -3
- data/lib/aozora2html/tag/multiline_style.rb +5 -3
- data/lib/aozora2html/tag/multiline_yokogumi.rb +6 -9
- data/lib/aozora2html/tag/okurigana.rb +4 -2
- data/lib/aozora2html/tag/oneline_chitsuki.rb +3 -2
- data/lib/aozora2html/tag/oneline_indent.rb +8 -1
- data/lib/aozora2html/tag/oneline_jisage.rb +3 -0
- data/lib/aozora2html/tag/reference_mentioned.rb +22 -21
- data/lib/aozora2html/tag/ruby.rb +174 -70
- data/lib/aozora2html/tag/un_embed_gaiji.rb +8 -2
- data/lib/aozora2html/tag.rb +40 -38
- data/lib/aozora2html/tag_parser.rb +23 -16
- data/lib/aozora2html/text_buffer.rb +50 -0
- data/lib/aozora2html/utils.rb +113 -50
- data/lib/aozora2html/version.rb +3 -1
- data/lib/aozora2html/yaml_loader.rb +8 -2
- data/lib/aozora2html/zip.rb +4 -0
- data/lib/aozora2html.rb +1329 -3
- data/lib/extensions.rb +2 -34
- data/lib/jstream.rb +96 -25
- data/sample/chukiichiran_kinyurei.html +42 -29
- data/sample/chukiichiran_kinyurei.txt +16 -3
- metadata +80 -83
- data/.travis.yml +0 -12
- data/lib/t2hs.rb +0 -1607
- data/test/test_aozora2html.rb +0 -379
- data/test/test_aozora_accent_parser.rb +0 -31
- data/test/test_command_parse.rb +0 -213
- data/test/test_compat.rb +0 -11
- data/test/test_dakuten_katakana_tag.rb +0 -27
- data/test/test_decorate_tag.rb +0 -24
- data/test/test_dir_tag.rb +0 -24
- data/test/test_editor_note_tag.rb +0 -22
- data/test/test_exception.rb +0 -23
- data/test/test_font_size_tag.rb +0 -41
- data/test/test_gaiji_tag.rb +0 -49
- data/test/test_header.rb +0 -60
- data/test/test_helper.rb +0 -5
- data/test/test_i18n.rb +0 -23
- data/test/test_img_tag.rb +0 -23
- data/test/test_inline_caption_tag.rb +0 -24
- data/test/test_inline_font_size_tag.rb +0 -34
- data/test/test_inline_keigakomi_tag.rb +0 -24
- data/test/test_inline_yokogumi_tag.rb +0 -24
- data/test/test_jizume_tag.rb +0 -25
- data/test/test_jstream.rb +0 -57
- data/test/test_kaeriten_tag.rb +0 -24
- data/test/test_keigakomi_tag.rb +0 -31
- data/test/test_midashi_tag.rb +0 -38
- data/test/test_multiline_caption_tag.rb +0 -25
- data/test/test_multiline_midashi_tag.rb +0 -55
- data/test/test_multiline_style_tag.rb +0 -25
- data/test/test_multiline_yokogumi_tag.rb +0 -25
- data/test/test_okurigana_tag.rb +0 -24
- data/test/test_ruby_parse.rb +0 -130
- data/test/test_ruby_tag.rb +0 -24
- data/test/test_tag_parser.rb +0 -80
data/lib/aozora2html/tag/ruby.rb
CHANGED
@@ -1,98 +1,202 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
# complex ruby markup
|
3
4
|
# if css3 is major supported, please fix ruby position with property "ruby-position"
|
4
5
|
# see also: http://www.w3.org/TR/2001/WD-css3-ruby-20010216/
|
5
6
|
class Aozora2Html
|
6
7
|
class Tag
|
8
|
+
# ルビ用
|
9
|
+
#
|
10
|
+
# 現状、under_rubyは無視しているのに注意
|
7
11
|
class Ruby < Aozora2Html::Tag::ReferenceMentioned
|
8
12
|
attr_accessor :ruby, :under_ruby
|
13
|
+
attr_reader :target
|
9
14
|
|
10
|
-
def initialize(parser, string, ruby, under_ruby =
|
15
|
+
def initialize(parser, string, ruby, under_ruby = '')
|
11
16
|
@target = string
|
12
17
|
@ruby = ruby
|
13
18
|
@under_ruby = under_ruby
|
14
19
|
super
|
15
20
|
end
|
16
21
|
|
17
|
-
def gen_rt(string)
|
18
|
-
if string != ""
|
19
|
-
"<rt class=\"real_ruby\">#{string}</rt>"
|
20
|
-
else
|
21
|
-
"<rt class=\"dummy_ruby\"></rt>"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
22
|
def to_s
|
26
|
-
"<ruby><rb>#{@target
|
23
|
+
"<ruby><rb>#{@target}</rb><rp>#{PAREN_BEGIN_MARK}</rp><rt>#{@ruby}</rt><rp>#{PAREN_END_MARK}</rp></ruby>"
|
27
24
|
end
|
28
25
|
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
# cell is used
|
35
|
-
@rbspan = @ruby.length
|
36
|
-
end
|
37
|
-
if @under_ruby.is_a?(Array) and @under_ruby.length > 0
|
38
|
-
# cell is used, but two way cell is not supported
|
39
|
-
if @rbspan
|
40
|
-
raise Aozora2Html::Error, I18n.t(:unsupported_ruby)
|
41
|
-
else
|
42
|
-
@rbspan = @under_ruby.length
|
43
|
-
end
|
44
|
-
end
|
26
|
+
# rubyタグの再割り当て
|
27
|
+
def self.rearrange_ruby(parser, targets, upper_ruby, under_ruby)
|
28
|
+
unless include_ruby?(targets)
|
29
|
+
return Aozora2Html::Tag::Ruby.new(parser, targets, upper_ruby, under_ruby)
|
30
|
+
end
|
45
31
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
32
|
+
new_targets = []
|
33
|
+
new_upper = if upper_ruby == ''
|
34
|
+
[]
|
35
|
+
else
|
36
|
+
upper_ruby
|
37
|
+
end
|
38
|
+
new_under = if under_ruby == ''
|
39
|
+
[]
|
40
|
+
else
|
41
|
+
under_ruby
|
42
|
+
end
|
43
|
+
if (new_upper.length >= 1) && (new_under.length >= 1)
|
44
|
+
raise Aozora2Html::Error, I18n.t(:dont_allow_triple_ruby)
|
45
|
+
end
|
54
46
|
|
55
|
-
|
47
|
+
targets.each do |x|
|
48
|
+
case x
|
49
|
+
when Aozora2Html::Tag::Ruby
|
50
|
+
raise Aozora2Html::Error, I18n.t(:dont_use_double_ruby) if x.target.is_a?(Array)
|
56
51
|
|
57
|
-
|
58
|
-
|
59
|
-
@ruby.each{|x|
|
60
|
-
ans.concat(gen_rt(x))
|
61
|
-
}
|
62
|
-
elsif @rbspan
|
63
|
-
if @ruby != ""
|
64
|
-
ans.concat("<rt class=\"real_ruby\" rbspan=\"#{@rbspan}\">#{@ruby}</rt>")
|
65
|
-
else
|
66
|
-
ans.concat("<rt class=\"dummy_ruby\" rbspan=\"#{@rbspan}\"></rt>")
|
67
|
-
end
|
68
|
-
else
|
69
|
-
ans.concat(gen_rt(@ruby))
|
70
|
-
end
|
52
|
+
if x.ruby == ''
|
53
|
+
raise Aozora2Html::Error, I18n.t(:dont_use_double_ruby) unless new_under.is_a?(Array)
|
71
54
|
|
72
|
-
|
55
|
+
new_under.push(x.under_ruby)
|
56
|
+
else
|
57
|
+
raise Aozora2Html::Error, I18n.t(:dont_use_double_ruby) unless new_upper.is_a?(Array)
|
73
58
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
59
|
+
new_upper.push(x.ruby)
|
60
|
+
end
|
61
|
+
new_targets.push(x.target)
|
62
|
+
when Aozora2Html::Tag::ReferenceMentioned
|
63
|
+
if x.target.is_a?(Array)
|
64
|
+
# recursive
|
65
|
+
ruby2 = rearrange_ruby(parser, x.target, '', '')
|
66
|
+
target2, upper_ruby2, under_ruby2 = ruby2.target, ruby2.ruby, ruby2.under_ruby
|
67
|
+
# rotation!!
|
68
|
+
target2.each do |y|
|
69
|
+
tmp = x.dup
|
70
|
+
tmp.target = y
|
71
|
+
new_targets.push(tmp)
|
72
|
+
end
|
73
|
+
if new_under.is_a?(Array)
|
74
|
+
new_under.concat(under_ruby2)
|
75
|
+
elsif under_ruby2.to_s.length > 0
|
76
|
+
raise Aozora2Html::Error, I18n.t(:dont_use_double_ruby)
|
77
|
+
end
|
78
|
+
if new_upper.is_a?(Array)
|
79
|
+
new_upper.concat(upper_ruby2)
|
80
|
+
elsif upper_ruby2.to_s.length > 0
|
81
|
+
raise Aozora2Html::Error, I18n.t(:dont_use_double_ruby)
|
82
|
+
end
|
83
|
+
else
|
84
|
+
new_targets.push(x)
|
85
|
+
if new_under.is_a?(Array)
|
86
|
+
new_under.push('')
|
87
|
+
end
|
88
|
+
if new_upper.is_a?(Array)
|
89
|
+
new_upper.push('')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
else
|
93
|
+
new_targets.push(x)
|
94
|
+
if new_under.is_a?(Array)
|
95
|
+
new_under.push('')
|
96
|
+
end
|
97
|
+
if new_upper.is_a?(Array)
|
98
|
+
new_upper.push('')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
88
102
|
|
89
|
-
|
90
|
-
|
103
|
+
Aozora2Html::Tag::Ruby.new(parser, new_targets, new_upper, new_under)
|
104
|
+
end
|
91
105
|
|
92
|
-
|
93
|
-
|
94
|
-
|
106
|
+
# arrayがルビを含んでいればそのインデックスを返す
|
107
|
+
#
|
108
|
+
# @return [Integer, nil]
|
109
|
+
#
|
110
|
+
def self.include_ruby?(array)
|
111
|
+
array.index do |elt|
|
112
|
+
case elt
|
113
|
+
when Aozora2Html::Tag::Ruby
|
114
|
+
true
|
115
|
+
when Aozora2Html::Tag::ReferenceMentioned
|
116
|
+
if elt.target.is_a?(Array)
|
117
|
+
include_ruby?(elt.target)
|
118
|
+
else
|
119
|
+
elt.target.is_a?(Aozora2Html::Tag::Ruby)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
95
124
|
|
125
|
+
# ----------------------------------------------------
|
126
|
+
#
|
127
|
+
# def gen_rt(string)
|
128
|
+
# if string == ''
|
129
|
+
# '<rt class="dummy_ruby"></rt>'
|
130
|
+
# else
|
131
|
+
# "<rt class=\"real_ruby\">#{string}</rt>"
|
132
|
+
# end
|
133
|
+
# end
|
134
|
+
#
|
135
|
+
#
|
136
|
+
# complex ruby is waiting for IE support and CSS3 candidate
|
137
|
+
# def to_s
|
138
|
+
# ans = "<ruby class=\"complex_ruby\"><rbc>" # indicator of new version of aozora ruby
|
139
|
+
# if @ruby.is_a?(Array) and @ruby.length > 0
|
140
|
+
# # cell is used
|
141
|
+
# @rbspan = @ruby.length
|
142
|
+
# end
|
143
|
+
# if @under_ruby.is_a?(Array) and @under_ruby.length > 0
|
144
|
+
# # cell is used, but two way cell is not supported
|
145
|
+
# if @rbspan
|
146
|
+
# raise Aozora2Html::Error, I18n.t(:unsupported_ruby)
|
147
|
+
# else
|
148
|
+
# @rbspan = @under_ruby.length
|
149
|
+
# end
|
150
|
+
# end
|
151
|
+
#
|
152
|
+
# # target
|
153
|
+
# if @rbspan
|
154
|
+
# @target.each{|x|
|
155
|
+
# ans.concat("<rb>#{x.to_s}</rb>")
|
156
|
+
# }
|
157
|
+
# else
|
158
|
+
# ans.concat("<rb>#{@target.to_s}</rb>")
|
159
|
+
# end
|
160
|
+
#
|
161
|
+
# ans.concat("</rbc><rtc>")
|
162
|
+
#
|
163
|
+
# # upper ruby
|
164
|
+
# if @ruby.is_a?(Array)
|
165
|
+
# @ruby.each{|x|
|
166
|
+
# ans.concat(gen_rt(x))
|
167
|
+
# }
|
168
|
+
# elsif @rbspan
|
169
|
+
# if @ruby != ""
|
170
|
+
# ans.concat("<rt class=\"real_ruby\" rbspan=\"#{@rbspan}\">#{@ruby}</rt>")
|
171
|
+
# else
|
172
|
+
# ans.concat("<rt class=\"dummy_ruby\" rbspan=\"#{@rbspan}\"></rt>")
|
173
|
+
# end
|
174
|
+
# else
|
175
|
+
# ans.concat(gen_rt(@ruby))
|
176
|
+
# end
|
177
|
+
#
|
178
|
+
# ans.concat("</rtc>")
|
179
|
+
#
|
180
|
+
# # under_ruby (if exists)
|
181
|
+
# if @under_ruby.length > 0
|
182
|
+
# ans.concat("<rtc>")
|
183
|
+
# if @under_ruby.is_a?(Array)
|
184
|
+
# @under_ruby.each{|x|
|
185
|
+
# ans.concat(gen_rt(x))
|
186
|
+
# }
|
187
|
+
# elsif @rbspan
|
188
|
+
# ans.concat("<rt class=\"real_ruby\" rbspan=\"#{@rbspan}\">#{@under_ruby}</rt>")
|
189
|
+
# else
|
190
|
+
# ans.concat(gen_rt(@under_ruby))
|
191
|
+
# end
|
192
|
+
# ans.concat("</rtc>")
|
193
|
+
# end
|
194
|
+
#
|
195
|
+
# # finalize
|
196
|
+
# ans.concat("</ruby>")
|
197
|
+
#
|
198
|
+
# ans
|
199
|
+
# end
|
96
200
|
end
|
97
201
|
end
|
98
202
|
end
|
@@ -1,6 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../string_refinements'
|
4
|
+
|
2
5
|
class Aozora2Html
|
3
6
|
class Tag
|
7
|
+
# 非埋め込み外字
|
4
8
|
class UnEmbedGaiji < Aozora2Html::Tag::Gaiji
|
5
9
|
def initialize(parser, desc)
|
6
10
|
@desc = desc
|
@@ -8,8 +12,10 @@ class Aozora2Html
|
|
8
12
|
super
|
9
13
|
end
|
10
14
|
|
15
|
+
using StringRefinements
|
16
|
+
|
11
17
|
def to_s
|
12
|
-
'<span class="notes">['.
|
18
|
+
'<span class="notes">['.to_sjis + @desc + ']</span>'.to_sjis
|
13
19
|
end
|
14
20
|
|
15
21
|
def escaped?
|
data/lib/aozora2html/tag.rb
CHANGED
@@ -1,43 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'tag/inline'
|
4
|
+
require_relative 'tag/block'
|
5
|
+
require_relative 'tag/accent'
|
6
|
+
require_relative 'tag/gaiji'
|
7
|
+
require_relative 'tag/embed_gaiji'
|
8
|
+
require_relative 'tag/un_embed_gaiji'
|
9
|
+
require_relative 'tag/editor_note'
|
10
|
+
require_relative 'tag/indent'
|
11
|
+
require_relative 'tag/oneline_indent'
|
12
|
+
require_relative 'tag/multiline'
|
13
|
+
require_relative 'tag/multiline_style'
|
14
|
+
require_relative 'tag/font_size'
|
15
|
+
require_relative 'tag/jizume'
|
16
|
+
require_relative 'tag/keigakomi'
|
17
|
+
require_relative 'tag/multiline_yokogumi'
|
18
|
+
require_relative 'tag/multiline_caption'
|
19
|
+
require_relative 'tag/multiline_midashi'
|
20
|
+
require_relative 'tag/jisage'
|
21
|
+
require_relative 'tag/oneline_jisage'
|
22
|
+
require_relative 'tag/multiline_jisage'
|
23
|
+
require_relative 'tag/chitsuki'
|
24
|
+
require_relative 'tag/oneline_chitsuki'
|
25
|
+
require_relative 'tag/multiline_chitsuki'
|
26
|
+
require_relative 'tag/reference_mentioned'
|
27
|
+
require_relative 'tag/midashi'
|
28
|
+
require_relative 'tag/ruby'
|
29
|
+
require_relative 'tag/kunten'
|
30
|
+
require_relative 'tag/kaeriten'
|
31
|
+
require_relative 'tag/okurigana'
|
32
|
+
require_relative 'tag/inline_keigakomi'
|
33
|
+
require_relative 'tag/inline_yokogumi'
|
34
|
+
require_relative 'tag/inline_caption'
|
35
|
+
require_relative 'tag/inline_font_size'
|
36
|
+
require_relative 'tag/decorate'
|
37
|
+
require_relative 'tag/dakuten_katakana'
|
38
|
+
require_relative 'tag/dir'
|
39
|
+
require_relative 'tag/img'
|
38
40
|
|
39
|
-
# 変換される青空記法class
|
40
41
|
class Aozora2Html
|
42
|
+
# 変換される青空記法class
|
41
43
|
class Tag
|
42
44
|
# debug用
|
43
45
|
def inspect
|
@@ -1,22 +1,30 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'ruby_buffer'
|
4
|
+
|
3
5
|
class Aozora2Html
|
6
|
+
# 注記記法parser
|
7
|
+
#
|
8
|
+
# 青空記法の入れ子に対応(?)
|
4
9
|
class TagParser < Aozora2Html
|
5
|
-
def initialize(input, endchar, chuuki, image)
|
6
|
-
|
7
|
-
raise ArgumentError,
|
10
|
+
def initialize(input, endchar, chuuki, image, gaiji_dir:) # rubocop:disable Lint/MissingSuper
|
11
|
+
unless input.is_a?(Jstream)
|
12
|
+
raise ArgumentError, 'tag_parser must supply Jstream as input'
|
8
13
|
end
|
14
|
+
|
9
15
|
@stream = input
|
10
|
-
@
|
16
|
+
@gaiji_dir = gaiji_dir
|
17
|
+
@buffer = TextBuffer.new
|
11
18
|
@ruby_buf = RubyBuffer.new
|
12
19
|
@chuuki_table = chuuki
|
13
20
|
@images = image # globalな環境を記録するアイテムは共有する必要あり
|
14
21
|
@endchar = endchar # 改行を越えるべきか否か…
|
15
22
|
@section = :tail # 末尾処理と記法内はインデントをしないので等価
|
16
|
-
@raw =
|
23
|
+
@raw = +'' # 外字変換前の生テキストを残したいことがあるらしい
|
17
24
|
end
|
18
25
|
|
19
|
-
|
26
|
+
# method override!
|
27
|
+
def read_char
|
20
28
|
c = @stream.read_char
|
21
29
|
@raw.concat(c)
|
22
30
|
c
|
@@ -28,24 +36,23 @@ class Aozora2Html
|
|
28
36
|
ans
|
29
37
|
end
|
30
38
|
|
31
|
-
|
39
|
+
# 出力は[String,String]返しで!
|
40
|
+
def general_output
|
32
41
|
@ruby_buf.dump_into(@buffer)
|
33
|
-
ans=
|
42
|
+
ans = +''
|
34
43
|
@buffer.each do |s|
|
35
|
-
if s.is_a?(Aozora2Html::Tag::UnEmbedGaiji)
|
44
|
+
if s.is_a?(Aozora2Html::Tag::UnEmbedGaiji) && !s.escaped?
|
36
45
|
# 消してあった※を復活させて
|
37
46
|
ans.concat(GAIJI_MARK)
|
38
47
|
end
|
39
48
|
ans.concat(s.to_s)
|
40
49
|
end
|
41
|
-
[ans
|
50
|
+
[ans, @raw]
|
42
51
|
end
|
43
52
|
|
44
|
-
def process
|
53
|
+
def process
|
45
54
|
catch(:terminate) do
|
46
|
-
|
47
|
-
parse
|
48
|
-
end
|
55
|
+
parse
|
49
56
|
end
|
50
57
|
general_output
|
51
58
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
# 本文テキスト用バッファ
|
5
|
+
#
|
6
|
+
# 要素はString以外も含む
|
7
|
+
# to_sすると文字列化できる
|
8
|
+
class TextBuffer < Array
|
9
|
+
# 行出力時に@bufferが空かどうか調べる
|
10
|
+
#
|
11
|
+
# @bufferの中身によって行末の出力が異なるため
|
12
|
+
#
|
13
|
+
# @return [true, false, :inline] 空文字ではない文字列が入っていればfalse、1行注記なら:inline、それ以外しか入っていなければtrue
|
14
|
+
#
|
15
|
+
def blank_type
|
16
|
+
each do |token|
|
17
|
+
return false if token.is_a?(String) && token != ''
|
18
|
+
|
19
|
+
if token.is_a?(Aozora2Html::Tag::OnelineIndent)
|
20
|
+
return :inline
|
21
|
+
end
|
22
|
+
end
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
# 行末で<br />を出力するべきかどうかの判別用
|
27
|
+
#
|
28
|
+
# @return [true, false] Multilineの注記しか入っていなければfalse、Multilineでも空文字でもない要素が含まれていればtrue
|
29
|
+
#
|
30
|
+
def terpri?
|
31
|
+
flag = true
|
32
|
+
each do |x|
|
33
|
+
case x
|
34
|
+
when Aozora2Html::Tag::Multiline
|
35
|
+
flag = false
|
36
|
+
when ''
|
37
|
+
# skip
|
38
|
+
else
|
39
|
+
return true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
flag
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_s
|
47
|
+
join
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|