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,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # 装飾用
3
6
  class Decorate < Aozora2Html::Tag::ReferenceMentioned
4
-
5
7
  def initialize(parser, target, html_class, html_tag)
6
8
  @target = target
7
9
  @close = "</#{html_tag}>"
@@ -10,9 +12,8 @@ class Aozora2Html
10
12
  end
11
13
 
12
14
  def to_s
13
- @open+@target.to_s+@close
15
+ @open + @target.to_s + @close
14
16
  end
15
17
  end
16
18
  end
17
19
  end
18
-
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # 書字方向(LTR)の指定用
3
6
  class Dir < Aozora2Html::Tag::ReferenceMentioned
4
-
5
7
  def initialize(parser, target)
6
8
  @target = target
7
9
  super
8
10
  end
9
11
 
10
12
  def to_s
11
- "<span dir=\"ltr\">#{@target.to_s}</span>"
13
+ "<span dir=\"ltr\">#{@target}</span>"
12
14
  end
13
15
  end
14
16
  end
@@ -1,15 +1,18 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  class Aozora2Html
3
4
  class Tag
4
- class EditorNote < Aozora2Html::Tag
5
- include Aozora2Html::Tag::Inline
5
+ # 編集者による訂正用
6
+ class EditorNote < Aozora2Html::Tag::Inline
6
7
  def initialize(parser, desc)
7
8
  @desc = desc
8
9
  super
9
10
  end
10
11
 
12
+ using StringRefinements
13
+
11
14
  def to_s
12
- '<span class="notes">[#'.encode("shift_jis") + @desc + ']</span>'.encode("shift_jis")
15
+ '<span class="notes">[#'.to_sjis + @desc + ']</span>'.to_sjis
13
16
  end
14
17
  end
15
18
  end
@@ -1,32 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # 外字注記用
3
6
  class EmbedGaiji < Aozora2Html::Tag::Gaiji
4
7
  attr_accessor :unicode
5
8
 
6
9
  @use_jisx0213 = nil
7
10
  @use_unicode = nil
8
11
 
9
- def self.use_jisx0213=(val)
10
- @use_jisx0213 = val
12
+ class << self
13
+ attr_writer :use_jisx0213
11
14
  end
12
15
 
13
- def self.use_jisx0213
14
- @use_jisx0213
16
+ class << self
17
+ attr_reader :use_jisx0213
15
18
  end
16
19
 
17
- def self.use_unicode=(val)
18
- @use_unicode = val
20
+ class << self
21
+ attr_writer :use_unicode
19
22
  end
20
23
 
21
- def self.use_unicode
22
- @use_unicode
24
+ class << self
25
+ attr_reader :use_unicode
23
26
  end
24
27
 
25
- def initialize(parser, folder, code, name, unicode_num = nil)
28
+ def initialize(parser, folder, code, name, unicode_num = nil, gaiji_dir:)
26
29
  @folder = folder
27
30
  @code = code
28
31
  @name = name
29
32
  @unicode = unicode_num
33
+ @gaiji_dir = gaiji_dir
30
34
  super
31
35
  end
32
36
 
@@ -38,9 +42,9 @@ class Aozora2Html
38
42
  if Aozora2Html::Tag::EmbedGaiji.use_jisx0213 && @code
39
43
  jisx0213_to_unicode(@code.to_sym)
40
44
  elsif Aozora2Html::Tag::EmbedGaiji.use_unicode && @unicode
41
- '&#x'+@unicode+';'
45
+ "&#x#{@unicode};"
42
46
  else
43
- "<img src=\"#{$gaiji_dir}#{@folder}/#{@code}.png\" alt=\"" + GAIJI_MARK + "(#{@name})\" class=\"gaiji\" />"
47
+ "<img src=\"#{@gaiji_dir}#{@folder}/#{@code}.png\" alt=\"" + GAIJI_MARK + "(#{@name})\" class=\"gaiji\" />"
44
48
  end
45
49
  end
46
50
  end
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
3
- class FontSize < Aozora2Html::Tag
4
- include Aozora2Html::Tag::Block, Aozora2Html::Tag::Multiline
5
+ # フォントサイズ指定用
6
+ class FontSize < Aozora2Html::Tag::Block
7
+ include Aozora2Html::Tag::Multiline
5
8
 
6
9
  def initialize(parser, times, daisho)
7
10
  @class = daisho.to_s + times.to_s
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
3
- class Gaiji < Aozora2Html::Tag
4
- include Aozora2Html::Tag::Inline
5
-
5
+ # 外字用
6
+ class Gaiji < Aozora2Html::Tag::Inline
6
7
  def char_type
7
8
  :kanji
8
9
  end
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
3
- class Img < Aozora2Html::Tag
4
- include Aozora2Html::Tag::Inline
5
-
5
+ # 画像用
6
+ class Img < Aozora2Html::Tag::Inline
6
7
  def initialize(parser, filename, css_class, alt, width, height)
7
8
  @filename = filename
8
9
  @css_class = css_class
@@ -18,4 +19,3 @@ class Aozora2Html
18
19
  end
19
20
  end
20
21
  end
21
-
@@ -1,8 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
3
- class Indent < Aozora2Html::Tag
4
- include Aozora2Html::Tag::Block
5
+ class Indent < Aozora2Html::Tag::Block
5
6
  end
6
7
  end
7
8
  end
8
-
@@ -1,13 +1,16 @@
1
- # 全ての青空記法はHTML elementに変換される
2
- # したがって、block/inlineの区別がある
3
- # 全ての末端青空classはどちらかのmoduleをincludeする必要がある
1
+ # frozen_string_literal: true
2
+
4
3
  class Aozora2Html
5
4
  class Tag
6
- module Inline
7
- def initialize(*args)
8
- true
5
+ # インラインタグ用class
6
+ #
7
+ # 全ての青空記法はHTML elementに変換される
8
+ # したがって、block/inlineの区別がある
9
+ # 全ての末端青空classはどちらかのclassのサブクラスになる必要がある
10
+ class Inline < Aozora2Html::Tag
11
+ def initialize(*_args)
12
+ super()
9
13
  end
10
14
  end
11
15
  end
12
16
  end
13
-
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # インラインキャプション
3
6
  class InlineCaption < Aozora2Html::Tag::ReferenceMentioned
4
7
  def initialize(parser, target)
5
8
  @target = target
@@ -7,9 +10,8 @@ class Aozora2Html
7
10
  end
8
11
 
9
12
  def to_s
10
- "<span class=\"caption\">#{@target.to_s}</span>"
13
+ "<span class=\"caption\">#{@target}</span>"
11
14
  end
12
15
  end
13
16
  end
14
17
  end
15
-
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # インラインフォントサイズ指定用
3
6
  class InlineFontSize < Aozora2Html::Tag::ReferenceMentioned
4
-
5
7
  def initialize(parser, target, times, daisho)
6
8
  @target = target
7
9
  @class = daisho.to_s + times.to_s
@@ -10,9 +12,8 @@ class Aozora2Html
10
12
  end
11
13
 
12
14
  def to_s
13
- "<span class=\"#{@class}\" style=\"font-size: #{@style};\">" + @target.to_s + "</span>"
15
+ "<span class=\"#{@class}\" style=\"font-size: #{@style};\">#{@target}</span>"
14
16
  end
15
17
  end
16
18
  end
17
19
  end
18
-
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # インライン罫囲み用
3
6
  class InlineKeigakomi < Aozora2Html::Tag::ReferenceMentioned
4
7
  def initialize(parser, target)
5
8
  @target = target
@@ -7,9 +10,8 @@ class Aozora2Html
7
10
  end
8
11
 
9
12
  def to_s
10
- "<span class=\"keigakomi\">#{@target.to_s}</span>"
13
+ "<span class=\"keigakomi\">#{@target}</span>"
11
14
  end
12
15
  end
13
16
  end
14
17
  end
15
-
@@ -1,16 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # インライン横組み用
3
6
  class InlineYokogumi < Aozora2Html::Tag::ReferenceMentioned
4
-
5
7
  def initialize(parser, target)
6
8
  @target = target
7
9
  super
8
10
  end
9
11
 
10
12
  def to_s
11
- "<span class=\"yokogumi\">#{@target.to_s}</span>"
13
+ "<span class=\"yokogumi\">#{@target}</span>"
12
14
  end
13
15
  end
14
16
  end
15
17
  end
16
-
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # 字下げ用
3
6
  class Jisage < Aozora2Html::Tag::Indent
4
-
5
7
  def initialize(parser, width)
6
8
  @width = width
7
9
  super
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # 字詰め用
3
6
  class Jizume < Aozora2Html::Tag::Indent
4
7
  include Aozora2Html::Tag::Multiline
5
8
 
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # 返り点用
3
6
  class Kaeriten < Aozora2Html::Tag::Kunten
4
-
5
7
  def initialize(parser, string)
6
8
  @string = string
7
9
  super
8
10
  end
9
11
 
10
12
  def to_s
11
- "<sub class=\"kaeriten\">#{@string.to_s}</sub>"
13
+ "<sub class=\"kaeriten\">#{@string}</sub>"
12
14
  end
13
15
  end
14
16
  end
@@ -1,13 +1,19 @@
1
- class Aozora2Html::Tag::Keigakomi < Aozora2Html::Tag
2
- include Aozora2Html::Tag::Block, Aozora2Html::Tag::Multiline
1
+ # frozen_string_literal: true
3
2
 
4
- def initialize(parser, size = 1)
5
- @size = size
6
- super
7
- end
3
+ class Aozora2Html
4
+ class Tag
5
+ # 罫囲み用
6
+ class Keigakomi < Aozora2Html::Tag::Block
7
+ include Aozora2Html::Tag::Multiline
8
+
9
+ def initialize(parser, size = 1)
10
+ @size = size
11
+ super
12
+ end
8
13
 
9
- def to_s
10
- "<div class=\"keigakomi\" style=\"border: solid #{@size}px\">"
14
+ def to_s
15
+ "<div class=\"keigakomi\" style=\"border: solid #{@size}px\">"
16
+ end
17
+ end
11
18
  end
12
19
  end
13
-
@@ -1,12 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
3
- class Kunten < Aozora2Html::Tag
4
- include Aozora2Html::Tag::Inline
5
-
5
+ # 訓点用
6
+ class Kunten < Aozora2Html::Tag::Inline
6
7
  def char_type
7
8
  :else # just remove this line
8
9
  end
9
10
  end
10
11
  end
11
12
  end
12
-
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # 見出し用
3
6
  class Midashi < Aozora2Html::Tag::ReferenceMentioned
4
-
5
7
  def initialize(parser, target, size, type)
6
8
  super
7
9
  @target = target
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # 複数行記法用
3
6
  module Multiline
4
7
  end
5
8
  end
@@ -1,14 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
3
- class MultilineCaption < Aozora2Html::Tag
4
- include Aozora2Html::Tag::Block, Aozora2Html::Tag::Multiline
5
-
6
- def initialize(parser)
7
- super
8
- end
9
-
5
+ # 複数行キャプション用
6
+ class MultilineCaption < Aozora2Html::Tag::Block
7
+ include Aozora2Html::Tag::Multiline
10
8
  def to_s
11
- "<div class=\"caption\">"
9
+ '<div class="caption">'
12
10
  end
13
11
  end
14
12
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # ブロックでの地付き指定用
3
6
  class MultilineChitsuki < Aozora2Html::Tag::Chitsuki
4
7
  include Aozora2Html::Tag::Multiline
5
8
  end
6
9
  end
7
10
  end
8
-
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # ブロックでの字下げ指定用
3
6
  class MultilineJisage < Aozora2Html::Tag::Jisage
4
7
  include Aozora2Html::Tag::Multiline
5
8
  end
6
9
  end
7
10
  end
8
-
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
3
- class MultilineMidashi < Aozora2Html::Tag
4
- include Aozora2Html::Tag::Block, Aozora2Html::Tag::Multiline
5
+ # ブロックでの見出し指定用
6
+ class MultilineMidashi < Aozora2Html::Tag::Block
7
+ include Aozora2Html::Tag::Multiline
5
8
 
6
- def initialize(parser,size,type)
9
+ def initialize(parser, size, type)
7
10
  super
8
11
  @tag = Utils.create_midashi_tag(size)
9
12
  @id = parser.new_midashi_id(size)
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
3
- class MultilineStyle < Aozora2Html::Tag
4
- include Aozora2Html::Tag::Block, Aozora2Html::Tag::Multiline
5
+ # ブロックでのスタイル指定用
6
+ class MultilineStyle < Aozora2Html::Tag::Block
7
+ include Aozora2Html::Tag::Multiline
5
8
 
6
9
  def initialize(parser, style)
7
10
  @style = style
@@ -14,4 +17,3 @@ class Aozora2Html
14
17
  end
15
18
  end
16
19
  end
17
-
@@ -1,17 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
3
- class MultilineYokogumi < Aozora2Html::Tag
4
- include Aozora2Html::Tag::Block, Aozora2Html::Tag::Multiline
5
-
6
- def initialize(parser)
7
- super
8
- end
5
+ # ブロックでの横組指定用
6
+ class MultilineYokogumi < Aozora2Html::Tag::Block
7
+ include Aozora2Html::Tag::Multiline
9
8
 
10
9
  def to_s
11
- "<div class=\"yokogumi\">"
10
+ '<div class="yokogumi">'
12
11
  end
13
12
  end
14
13
  end
15
14
  end
16
-
17
-
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # 訓点送り仮名用
3
6
  class Okurigana < Aozora2Html::Tag::Kunten
4
-
5
7
  def initialize(parser, string)
6
8
  @string = string
7
9
  super
8
10
  end
9
11
 
10
12
  def to_s
11
- "<sup class=\"okurigana\">#{@string.to_s}</sup>"
13
+ "<sup class=\"okurigana\">#{@string}</sup>"
12
14
  end
13
15
  end
14
16
  end
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # 1行地付き用
3
6
  class OnelineChitsuki < Aozora2Html::Tag::Chitsuki
4
7
  include Aozora2Html::Tag::OnelineIndent
5
8
  end
6
9
  end
7
10
  end
8
-
9
-
@@ -1,2 +1,9 @@
1
- module Aozora2Html::Tag::OnelineIndent
1
+ # frozen_string_literal: true
2
+
3
+ class Aozora2Html
4
+ class Tag
5
+ # 1行字下げ用
6
+ module OnelineIndent
7
+ end
8
+ end
2
9
  end
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
4
  class Tag
5
+ # 1行字下げ用
3
6
  class OnelineJisage < Aozora2Html::Tag::Jisage
4
7
  include Aozora2Html::Tag::OnelineIndent
5
8
  end
@@ -1,42 +1,43 @@
1
- # 前方参照でこいつだけは中身をチェックする
2
- # 子要素を持つAozora2Html::Tag::Inlineは全てこいつのサブクラス
1
+ # frozen_string_literal: true
2
+
3
3
  class Aozora2Html
4
4
  class Tag
5
- class ReferenceMentioned < Aozora2Html::Tag
6
- include Aozora2Html::Tag::Inline
5
+ # 参照先用
6
+ #
7
+ # 前方参照でこいつだけは中身をチェックする
8
+ # 子要素を持つAozora2Html::Tag::Inlineは全てこいつのサブクラス
9
+ class ReferenceMentioned < Aozora2Html::Tag::Inline
7
10
  attr_accessor :target
8
11
 
9
- def initialize(*args)
10
- if defined?(@target) && block_element?(@target)
11
- syntax_error
12
- end
12
+ def initialize(*_args) # rubocop:disable Lint/MissingSuper
13
+ return unless defined?(@target) && block_element?(@target)
14
+
15
+ syntax_error
13
16
  end
14
17
 
15
18
  def block_element?(elt)
16
- if elt.is_a?(Array)
17
- elt.each do |x|
18
- if block_element?(x)
19
- return true
20
- end
21
- end
22
- nil
23
- elsif elt.is_a?(String)
24
- elt.match(/<div/)
19
+ case elt
20
+ when Array
21
+ elt.any? { |x| block_element?(x) }
22
+ when String
23
+ elt.include?('<div')
25
24
  else
26
25
  elt.is_a?(Aozora2Html::Tag::Block)
27
26
  end
28
27
  end
29
28
 
30
29
  def target_string
31
- if @target.is_a?(Aozora2Html::Tag::ReferenceMentioned)
30
+ case @target
31
+ when Aozora2Html::Tag::ReferenceMentioned
32
32
  @target.target_string
33
- elsif @target.is_a?(Array)
34
- @target.collect{|x|
33
+ when Array
34
+ @target.collect do |x|
35
35
  if x.is_a?(Aozora2Html::Tag::ReferenceMentioned)
36
36
  x.target_string
37
37
  else
38
38
  x
39
- end}.to_s
39
+ end
40
+ end.join
40
41
  else
41
42
  @target
42
43
  end