aozora2html 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +19 -0
  3. data/.github/workflows/ruby.yml +4 -1
  4. data/.rubocop.yml +36 -152
  5. data/.rubocop_todo.yml +7 -0
  6. data/CHANGELOG.md +26 -0
  7. data/Gemfile +2 -0
  8. data/Guardfile +3 -1
  9. data/HACKING.md +45 -0
  10. data/README.md +14 -6
  11. data/Rakefile +12 -5
  12. data/aozora2html.gemspec +24 -22
  13. data/bin/aozora2html +21 -19
  14. data/lib/aozora2html/accent_parser.rb +62 -54
  15. data/lib/aozora2html/error.rb +5 -4
  16. data/lib/aozora2html/header.rb +20 -18
  17. data/lib/aozora2html/i18n.rb +40 -20
  18. data/lib/aozora2html/ruby_buffer.rb +63 -28
  19. data/lib/aozora2html/string_refinements.rb +36 -0
  20. data/lib/aozora2html/style_stack.rb +6 -0
  21. data/lib/aozora2html/tag/accent.rb +10 -12
  22. data/lib/aozora2html/tag/block.rb +11 -9
  23. data/lib/aozora2html/tag/chitsuki.rb +6 -2
  24. data/lib/aozora2html/tag/dakuten_katakana.rb +10 -8
  25. data/lib/aozora2html/tag/decorate.rb +4 -3
  26. data/lib/aozora2html/tag/dir.rb +4 -2
  27. data/lib/aozora2html/tag/editor_note.rb +7 -4
  28. data/lib/aozora2html/tag/embed_gaiji.rb +15 -11
  29. data/lib/aozora2html/tag/font_size.rb +5 -2
  30. data/lib/aozora2html/tag/gaiji.rb +4 -3
  31. data/lib/aozora2html/tag/img.rb +4 -4
  32. data/lib/aozora2html/tag/indent.rb +3 -3
  33. data/lib/aozora2html/tag/inline.rb +10 -7
  34. data/lib/aozora2html/tag/inline_caption.rb +4 -2
  35. data/lib/aozora2html/tag/inline_font_size.rb +4 -3
  36. data/lib/aozora2html/tag/inline_keigakomi.rb +4 -2
  37. data/lib/aozora2html/tag/inline_yokogumi.rb +4 -3
  38. data/lib/aozora2html/tag/jisage.rb +3 -1
  39. data/lib/aozora2html/tag/jizume.rb +3 -0
  40. data/lib/aozora2html/tag/kaeriten.rb +4 -2
  41. data/lib/aozora2html/tag/keigakomi.rb +15 -9
  42. data/lib/aozora2html/tag/kunten.rb +4 -4
  43. data/lib/aozora2html/tag/midashi.rb +3 -1
  44. data/lib/aozora2html/tag/multiline.rb +3 -0
  45. data/lib/aozora2html/tag/multiline_caption.rb +6 -8
  46. data/lib/aozora2html/tag/multiline_chitsuki.rb +3 -1
  47. data/lib/aozora2html/tag/multiline_jisage.rb +3 -1
  48. data/lib/aozora2html/tag/multiline_midashi.rb +6 -3
  49. data/lib/aozora2html/tag/multiline_style.rb +5 -3
  50. data/lib/aozora2html/tag/multiline_yokogumi.rb +6 -9
  51. data/lib/aozora2html/tag/okurigana.rb +4 -2
  52. data/lib/aozora2html/tag/oneline_chitsuki.rb +3 -2
  53. data/lib/aozora2html/tag/oneline_indent.rb +8 -1
  54. data/lib/aozora2html/tag/oneline_jisage.rb +3 -0
  55. data/lib/aozora2html/tag/reference_mentioned.rb +22 -21
  56. data/lib/aozora2html/tag/ruby.rb +174 -70
  57. data/lib/aozora2html/tag/un_embed_gaiji.rb +8 -2
  58. data/lib/aozora2html/tag.rb +40 -38
  59. data/lib/aozora2html/tag_parser.rb +23 -16
  60. data/lib/aozora2html/text_buffer.rb +50 -0
  61. data/lib/aozora2html/utils.rb +113 -50
  62. data/lib/aozora2html/version.rb +3 -1
  63. data/lib/aozora2html/yaml_loader.rb +8 -2
  64. data/lib/aozora2html/zip.rb +4 -0
  65. data/lib/aozora2html.rb +1358 -3
  66. data/lib/extensions.rb +2 -34
  67. data/lib/jstream.rb +96 -25
  68. data/sample/chukiichiran_kinyurei.html +15 -2
  69. data/sample/chukiichiran_kinyurei.txt +15 -2
  70. data/test/test_aozora2html.rb +137 -148
  71. data/test/test_aozora_accent_parser.rb +26 -9
  72. data/test/test_command_parse.rb +25 -22
  73. data/test/test_compat.rb +3 -4
  74. data/test/test_dakuten_katakana_tag.rb +10 -12
  75. data/test/test_decorate_tag.rb +9 -6
  76. data/test/test_dir_tag.rb +9 -6
  77. data/test/test_editor_note_tag.rb +8 -5
  78. data/test/test_exception.rb +10 -8
  79. data/test/test_font_size_tag.rb +16 -13
  80. data/test/test_gaiji_tag.rb +15 -14
  81. data/test/test_header.rb +25 -40
  82. data/test/test_helper.rb +3 -1
  83. data/test/test_i18n.rb +22 -6
  84. data/test/test_img_tag.rb +9 -5
  85. data/test/test_inline_caption_tag.rb +9 -6
  86. data/test/test_inline_font_size_tag.rb +13 -10
  87. data/test/test_inline_keigakomi_tag.rb +9 -6
  88. data/test/test_inline_yokogumi_tag.rb +9 -6
  89. data/test/test_jizume_tag.rb +9 -7
  90. data/test/test_jstream.rb +33 -30
  91. data/test/test_kaeriten_tag.rb +9 -6
  92. data/test/test_keigakomi_tag.rb +11 -9
  93. data/test/test_midashi_tag.rb +15 -14
  94. data/test/test_multiline_caption_tag.rb +7 -5
  95. data/test/test_multiline_midashi_tag.rb +24 -25
  96. data/test/test_multiline_style_tag.rb +9 -7
  97. data/test/test_multiline_yokogumi_tag.rb +7 -5
  98. data/test/test_okurigana_tag.rb +9 -6
  99. data/test/test_ruby_parse.rb +14 -14
  100. data/test/test_ruby_tag.rb +9 -6
  101. data/test/test_tag_parser.rb +28 -26
  102. metadata +60 -14
  103. data/.travis.yml +0 -12
  104. data/lib/t2hs.rb +0 -1607
@@ -1,98 +1,202 @@
1
- # encoding: utf-8
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.to_s}</rb><rp>" + "(".encode("shift_jis") + "</rp><rt>#{@ruby.to_s}</rt><rp>" + ")".encode("shift_jis") + "</rp></ruby>"
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
- # complex ruby is waiting for IE support and CSS3 candidate
30
- =begin
31
- def to_s
32
- ans = "<ruby class=\"complex_ruby\"><rbc>" # indicator of new version of aozora ruby
33
- if @ruby.is_a?(Array) and @ruby.length > 0
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
- # target
47
- if @rbspan
48
- @target.each{|x|
49
- ans.concat("<rb>#{x.to_s}</rb>")
50
- }
51
- else
52
- ans.concat("<rb>#{@target.to_s}</rb>")
53
- end
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
- ans.concat("</rbc><rtc>")
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
- # upper ruby
58
- if @ruby.is_a?(Array)
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
- ans.concat("</rtc>")
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
- # under_ruby (if exists)
75
- if @under_ruby.length > 0
76
- ans.concat("<rtc>")
77
- if @under_ruby.is_a?(Array)
78
- @under_ruby.each{|x|
79
- ans.concat(gen_rt(x))
80
- }
81
- elsif @rbspan
82
- ans.concat("<rt class=\"real_ruby\" rbspan=\"#{@rbspan}\">#{@under_ruby}</rt>")
83
- else
84
- ans.concat(gen_rt(@under_ruby))
85
- end
86
- ans.concat("</rtc>")
87
- end
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
- # finalize
90
- ans.concat("</ruby>")
103
+ Aozora2Html::Tag::Ruby.new(parser, new_targets, new_upper, new_under)
104
+ end
91
105
 
92
- ans
93
- end
94
- =end
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
- # encoding: utf-8
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">['.encode("shift_jis") + @desc + ']</span>'.encode("shift_jis")
18
+ '<span class="notes">['.to_sjis + @desc + ']</span>'.to_sjis
13
19
  end
14
20
 
15
21
  def escaped?
@@ -1,43 +1,45 @@
1
- require "aozora2html/tag/inline"
2
- require "aozora2html/tag/block"
3
- require "aozora2html/tag/accent"
4
- require "aozora2html/tag/gaiji"
5
- require "aozora2html/tag/embed_gaiji"
6
- require "aozora2html/tag/un_embed_gaiji"
7
- require "aozora2html/tag/editor_note"
8
- require "aozora2html/tag/indent"
9
- require "aozora2html/tag/oneline_indent"
10
- require "aozora2html/tag/multiline"
11
- require "aozora2html/tag/multiline_style"
12
- require "aozora2html/tag/font_size"
13
- require "aozora2html/tag/jizume"
14
- require "aozora2html/tag/keigakomi"
15
- require "aozora2html/tag/multiline_yokogumi"
16
- require "aozora2html/tag/multiline_caption"
17
- require "aozora2html/tag/multiline_midashi"
18
- require "aozora2html/tag/jisage"
19
- require "aozora2html/tag/oneline_jisage"
20
- require "aozora2html/tag/multiline_jisage"
21
- require "aozora2html/tag/chitsuki"
22
- require "aozora2html/tag/oneline_chitsuki"
23
- require "aozora2html/tag/multiline_chitsuki"
24
- require "aozora2html/tag/reference_mentioned"
25
- require "aozora2html/tag/midashi"
26
- require "aozora2html/tag/ruby"
27
- require "aozora2html/tag/kunten"
28
- require "aozora2html/tag/kaeriten"
29
- require "aozora2html/tag/okurigana"
30
- require "aozora2html/tag/inline_keigakomi"
31
- require "aozora2html/tag/inline_yokogumi"
32
- require "aozora2html/tag/inline_caption"
33
- require "aozora2html/tag/inline_font_size"
34
- require "aozora2html/tag/decorate"
35
- require "aozora2html/tag/dakuten_katakana"
36
- require "aozora2html/tag/dir"
37
- require "aozora2html/tag/img"
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
- require 'aozora2html/ruby_buffer'
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
- if not(input.is_a?(Jstream))
7
- raise ArgumentError, "tag_parser must supply Jstream as input"
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
- @buffer = []
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
- def read_char # method override!
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
- def general_output # 出力は[String,String]返しで!
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) and !s.escaped?
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,@raw]
50
+ [ans, @raw]
42
51
  end
43
52
 
44
- def process()
53
+ def process
45
54
  catch(:terminate) do
46
- loop do
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