aozora2html 0.7.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/rubocop.yml +19 -0
- data/.github/workflows/ruby.yml +37 -0
- data/.gitignore +8 -3
- data/.rubocop.yml +111 -0
- data/.rubocop_todo.yml +7 -0
- data/CHANGELOG.md +59 -0
- data/Gemfile +2 -0
- data/Guardfile +3 -1
- data/HACKING.md +45 -0
- data/LICENSE +116 -0
- data/README.md +29 -16
- data/Rakefile +12 -5
- data/aozora2html.gemspec +24 -24
- data/bin/aozora2html +25 -71
- data/lib/aozora2html/accent_parser.rb +99 -0
- data/lib/aozora2html/error.rb +17 -0
- data/lib/aozora2html/header.rb +141 -0
- data/lib/aozora2html/i18n.rb +48 -0
- data/lib/aozora2html/ruby_buffer.rb +116 -0
- data/lib/aozora2html/string_refinements.rb +36 -0
- data/lib/aozora2html/style_stack.rb +33 -0
- data/lib/aozora2html/tag/accent.rb +37 -0
- data/lib/aozora2html/tag/block.rb +21 -0
- data/lib/aozora2html/tag/chitsuki.rb +19 -0
- data/lib/aozora2html/tag/dakuten_katakana.rb +25 -0
- data/lib/aozora2html/tag/decorate.rb +19 -0
- data/lib/aozora2html/tag/dir.rb +17 -0
- data/lib/aozora2html/tag/editor_note.rb +19 -0
- data/lib/aozora2html/tag/embed_gaiji.rb +52 -0
- data/lib/aozora2html/tag/font_size.rb +20 -0
- data/lib/aozora2html/tag/gaiji.rb +12 -0
- data/lib/aozora2html/tag/img.rb +21 -0
- data/lib/aozora2html/tag/indent.rb +8 -0
- data/lib/aozora2html/tag/inline.rb +16 -0
- data/lib/aozora2html/tag/inline_caption.rb +17 -0
- data/lib/aozora2html/tag/inline_font_size.rb +19 -0
- data/lib/aozora2html/tag/inline_keigakomi.rb +17 -0
- data/lib/aozora2html/tag/inline_yokogumi.rb +17 -0
- data/lib/aozora2html/tag/jisage.rb +17 -0
- data/lib/aozora2html/tag/jizume.rb +19 -0
- data/lib/aozora2html/tag/kaeriten.rb +17 -0
- data/lib/aozora2html/tag/keigakomi.rb +19 -0
- data/lib/aozora2html/tag/kunten.rb +12 -0
- data/lib/aozora2html/tag/midashi.rb +20 -0
- data/lib/aozora2html/tag/multiline.rb +9 -0
- data/lib/aozora2html/tag/multiline_caption.rb +13 -0
- data/lib/aozora2html/tag/multiline_chitsuki.rb +10 -0
- data/lib/aozora2html/tag/multiline_jisage.rb +10 -0
- data/lib/aozora2html/tag/multiline_midashi.rb +25 -0
- data/lib/aozora2html/tag/multiline_style.rb +19 -0
- data/lib/aozora2html/tag/multiline_yokogumi.rb +14 -0
- data/lib/aozora2html/tag/okurigana.rb +17 -0
- data/lib/aozora2html/tag/oneline_chitsuki.rb +10 -0
- data/lib/aozora2html/tag/oneline_indent.rb +9 -0
- data/lib/aozora2html/tag/oneline_jisage.rb +10 -0
- data/lib/aozora2html/tag/reference_mentioned.rb +47 -0
- data/lib/aozora2html/tag/ruby.rb +202 -0
- data/lib/aozora2html/tag/un_embed_gaiji.rb +30 -0
- data/lib/aozora2html/tag.rb +57 -0
- data/lib/aozora2html/tag_parser.rb +60 -0
- data/lib/aozora2html/text_buffer.rb +50 -0
- data/lib/aozora2html/utils.rb +156 -0
- data/lib/aozora2html/version.rb +3 -1
- data/lib/aozora2html/yaml_loader.rb +37 -0
- data/lib/aozora2html/zip.rb +4 -0
- data/lib/aozora2html.rb +1359 -8
- data/lib/extensions.rb +12 -0
- data/lib/jstream.rb +139 -0
- data/sample/chukiichiran_kinyurei.html +15 -2
- data/sample/chukiichiran_kinyurei.txt +15 -2
- data/test/test_aozora2html.rb +323 -73
- data/test/test_aozora_accent_parser.rb +34 -6
- data/test/test_command_parse.rb +216 -0
- data/test/test_compat.rb +3 -4
- data/test/test_dakuten_katakana_tag.rb +12 -13
- data/test/test_decorate_tag.rb +11 -7
- data/test/test_dir_tag.rb +11 -7
- data/test/test_editor_note_tag.rb +9 -6
- data/test/test_exception.rb +11 -9
- data/test/test_font_size_tag.rb +22 -11
- data/test/test_gaiji_tag.rb +22 -14
- data/test/test_header.rb +45 -0
- data/test/test_helper.rb +3 -1
- data/test/test_i18n.rb +39 -0
- data/test/test_img_tag.rb +11 -6
- data/test/test_inline_caption_tag.rb +11 -7
- data/test/test_inline_font_size_tag.rb +15 -11
- data/test/test_inline_keigakomi_tag.rb +11 -7
- data/test/test_inline_yokogumi_tag.rb +11 -7
- data/test/test_jizume_tag.rb +11 -8
- data/test/test_jstream.rb +33 -30
- data/test/test_kaeriten_tag.rb +11 -7
- data/test/test_keigakomi_tag.rb +14 -11
- data/test/test_midashi_tag.rb +39 -0
- data/test/test_multiline_caption_tag.rb +11 -8
- data/test/test_multiline_midashi_tag.rb +26 -26
- data/test/test_multiline_style_tag.rb +11 -8
- data/test/test_multiline_yokogumi_tag.rb +11 -8
- data/test/test_okurigana_tag.rb +11 -7
- data/test/test_ruby_parse.rb +130 -0
- data/test/test_ruby_tag.rb +11 -7
- data/test/test_tag_parser.rb +31 -29
- data/vendor/jis2ucs/README.md +3 -6
- data/yml/accent_table.yml +240 -0
- data/yml/command_table.yml +61 -0
- data/yml/jis2ucs.yml +11234 -0
- metadata +99 -21
- data/.travis.yml +0 -12
- data/appveyor.yml +0 -23
- data/lib/accent_tag.rb +0 -23
- data/lib/aozora2html/jis2ucs.rb +0 -11237
- data/lib/embed_gaiji_tag.rb +0 -34
- data/lib/t2hs.rb +0 -2535
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# 地付き記法
|
6
|
+
#
|
7
|
+
# 直接使わない。実際に使うのはサブクラス
|
8
|
+
class Chitsuki < Aozora2Html::Tag::Indent
|
9
|
+
def initialize(parser, length)
|
10
|
+
@length = length
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"<div class=\"chitsuki_#{@length}\" style=\"text-align:right; margin-right: #{@length}em\">"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# 濁点つきカタカナ用
|
6
|
+
class DakutenKatakana < Aozora2Html::Tag::Inline
|
7
|
+
def initialize(parser, num, katakana, gaiji_dir:)
|
8
|
+
@n = num
|
9
|
+
@katakana = katakana
|
10
|
+
@gaiji_dir = gaiji_dir
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def char_type
|
15
|
+
:katakana
|
16
|
+
end
|
17
|
+
|
18
|
+
using StringRefinements
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"<img src=\"#{@gaiji_dir}/1-07/1-07-8#{@n}.png\" alt=\"" + '※(濁点付き片仮名「'.to_sjis + @katakana + '」、1-07-8'.to_sjis + "#{@n})\" class=\"gaiji\" />"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# 装飾用
|
6
|
+
class Decorate < Aozora2Html::Tag::ReferenceMentioned
|
7
|
+
def initialize(parser, target, html_class, html_tag)
|
8
|
+
@target = target
|
9
|
+
@close = "</#{html_tag}>"
|
10
|
+
@open = "<#{html_tag} class=\"#{html_class}\">"
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
@open + @target.to_s + @close
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# 書字方向(LTR)の指定用
|
6
|
+
class Dir < Aozora2Html::Tag::ReferenceMentioned
|
7
|
+
def initialize(parser, target)
|
8
|
+
@target = target
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"<span dir=\"ltr\">#{@target}</span>"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# 編集者による訂正用
|
6
|
+
class EditorNote < Aozora2Html::Tag::Inline
|
7
|
+
def initialize(parser, desc)
|
8
|
+
@desc = desc
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
using StringRefinements
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
'<span class="notes">[#'.to_sjis + @desc + ']</span>'.to_sjis
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# 外字注記用
|
6
|
+
class EmbedGaiji < Aozora2Html::Tag::Gaiji
|
7
|
+
attr_accessor :unicode
|
8
|
+
|
9
|
+
@use_jisx0213 = nil
|
10
|
+
@use_unicode = nil
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_writer :use_jisx0213
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
attr_reader :use_jisx0213
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
attr_writer :use_unicode
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
attr_reader :use_unicode
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(parser, folder, code, name, unicode_num = nil, gaiji_dir:)
|
29
|
+
@folder = folder
|
30
|
+
@code = code
|
31
|
+
@name = name
|
32
|
+
@unicode = unicode_num
|
33
|
+
@gaiji_dir = gaiji_dir
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
def jisx0213_to_unicode(code)
|
38
|
+
Aozora2Html::JIS2UCS[code]
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_s
|
42
|
+
if Aozora2Html::Tag::EmbedGaiji.use_jisx0213 && @code
|
43
|
+
jisx0213_to_unicode(@code.to_sym)
|
44
|
+
elsif Aozora2Html::Tag::EmbedGaiji.use_unicode && @unicode
|
45
|
+
"&#x#{@unicode};"
|
46
|
+
else
|
47
|
+
"<img src=\"#{@gaiji_dir}#{@folder}/#{@code}.png\" alt=\"" + GAIJI_MARK + "(#{@name})\" class=\"gaiji\" />"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# フォントサイズ指定用
|
6
|
+
class FontSize < Aozora2Html::Tag::Block
|
7
|
+
include Aozora2Html::Tag::Multiline
|
8
|
+
|
9
|
+
def initialize(parser, times, daisho)
|
10
|
+
@class = daisho.to_s + times.to_s
|
11
|
+
@style = Utils.create_font_size(times, daisho)
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
"<div class=\"#{@class}\" style=\"font-size: #{@style};\">"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# 画像用
|
6
|
+
class Img < Aozora2Html::Tag::Inline
|
7
|
+
def initialize(parser, filename, css_class, alt, width, height)
|
8
|
+
@filename = filename
|
9
|
+
@css_class = css_class
|
10
|
+
@alt = alt
|
11
|
+
@width = width
|
12
|
+
@height = height
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"<img class=\"#{@css_class}\" width=\"#{@width}\" height=\"#{@height}\" src=\"#{@filename}\" alt=\"#{@alt}\" />"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# インラインタグ用class
|
6
|
+
#
|
7
|
+
# 全ての青空記法はHTML elementに変換される
|
8
|
+
# したがって、block/inlineの区別がある
|
9
|
+
# 全ての末端青空classはどちらかのclassのサブクラスになる必要がある
|
10
|
+
class Inline < Aozora2Html::Tag
|
11
|
+
def initialize(*_args)
|
12
|
+
super()
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# インラインキャプション
|
6
|
+
class InlineCaption < Aozora2Html::Tag::ReferenceMentioned
|
7
|
+
def initialize(parser, target)
|
8
|
+
@target = target
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"<span class=\"caption\">#{@target}</span>"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# インラインフォントサイズ指定用
|
6
|
+
class InlineFontSize < Aozora2Html::Tag::ReferenceMentioned
|
7
|
+
def initialize(parser, target, times, daisho)
|
8
|
+
@target = target
|
9
|
+
@class = daisho.to_s + times.to_s
|
10
|
+
@style = Utils.create_font_size(times, daisho)
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"<span class=\"#{@class}\" style=\"font-size: #{@style};\">#{@target}</span>"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# インライン罫囲み用
|
6
|
+
class InlineKeigakomi < Aozora2Html::Tag::ReferenceMentioned
|
7
|
+
def initialize(parser, target)
|
8
|
+
@target = target
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"<span class=\"keigakomi\">#{@target}</span>"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# インライン横組み用
|
6
|
+
class InlineYokogumi < Aozora2Html::Tag::ReferenceMentioned
|
7
|
+
def initialize(parser, target)
|
8
|
+
@target = target
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"<span class=\"yokogumi\">#{@target}</span>"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# 字下げ用
|
6
|
+
class Jisage < Aozora2Html::Tag::Indent
|
7
|
+
def initialize(parser, width)
|
8
|
+
@width = width
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"<div class=\"jisage_#{@width}\" style=\"margin-left: #{@width}em\">"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# 字詰め用
|
6
|
+
class Jizume < Aozora2Html::Tag::Indent
|
7
|
+
include Aozora2Html::Tag::Multiline
|
8
|
+
|
9
|
+
def initialize(parser, width)
|
10
|
+
@w = width
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"<div class=\"jizume_#{@w}\" style=\"width: #{@w}em\">"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# 返り点用
|
6
|
+
class Kaeriten < Aozora2Html::Tag::Kunten
|
7
|
+
def initialize(parser, string)
|
8
|
+
@string = string
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"<sub class=\"kaeriten\">#{@string}</sub>"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
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
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"<div class=\"keigakomi\" style=\"border: solid #{@size}px\">"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# 見出し用
|
6
|
+
class Midashi < Aozora2Html::Tag::ReferenceMentioned
|
7
|
+
def initialize(parser, target, size, type)
|
8
|
+
super
|
9
|
+
@target = target
|
10
|
+
@tag = Utils.create_midashi_tag(size)
|
11
|
+
@id = parser.new_midashi_id(size)
|
12
|
+
@class = Utils.create_midashi_class(type, @tag)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
"<#{@tag} class=\"#{@class}\"><a class=\"midashi_anchor\" id=\"midashi#{@id}\">#{@target}</a></#{@tag}>"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# ブロックでの見出し指定用
|
6
|
+
class MultilineMidashi < Aozora2Html::Tag::Block
|
7
|
+
include Aozora2Html::Tag::Multiline
|
8
|
+
|
9
|
+
def initialize(parser, size, type)
|
10
|
+
super
|
11
|
+
@tag = Utils.create_midashi_tag(size)
|
12
|
+
@id = parser.new_midashi_id(size)
|
13
|
+
@class = Utils.create_midashi_class(type, @tag)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"<#{@tag} class=\"#{@class}\"><a class=\"midashi_anchor\" id=\"midashi#{@id}\">"
|
18
|
+
end
|
19
|
+
|
20
|
+
def close_tag
|
21
|
+
"</a></#{@tag}>"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# ブロックでのスタイル指定用
|
6
|
+
class MultilineStyle < Aozora2Html::Tag::Block
|
7
|
+
include Aozora2Html::Tag::Multiline
|
8
|
+
|
9
|
+
def initialize(parser, style)
|
10
|
+
@style = style
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"<div class=\"#{@style}\">"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# 訓点送り仮名用
|
6
|
+
class Okurigana < Aozora2Html::Tag::Kunten
|
7
|
+
def initialize(parser, string)
|
8
|
+
@string = string
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"<sup class=\"okurigana\">#{@string}</sup>"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aozora2Html
|
4
|
+
class Tag
|
5
|
+
# 参照先用
|
6
|
+
#
|
7
|
+
# 前方参照でこいつだけは中身をチェックする
|
8
|
+
# 子要素を持つAozora2Html::Tag::Inlineは全てこいつのサブクラス
|
9
|
+
class ReferenceMentioned < Aozora2Html::Tag::Inline
|
10
|
+
attr_accessor :target
|
11
|
+
|
12
|
+
def initialize(*_args) # rubocop:disable Lint/MissingSuper
|
13
|
+
return unless defined?(@target) && block_element?(@target)
|
14
|
+
|
15
|
+
syntax_error
|
16
|
+
end
|
17
|
+
|
18
|
+
def block_element?(elt)
|
19
|
+
case elt
|
20
|
+
when Array
|
21
|
+
elt.any? { |x| block_element?(x) }
|
22
|
+
when String
|
23
|
+
elt.include?('<div')
|
24
|
+
else
|
25
|
+
elt.is_a?(Aozora2Html::Tag::Block)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def target_string
|
30
|
+
case @target
|
31
|
+
when Aozora2Html::Tag::ReferenceMentioned
|
32
|
+
@target.target_string
|
33
|
+
when Array
|
34
|
+
@target.collect do |x|
|
35
|
+
if x.is_a?(Aozora2Html::Tag::ReferenceMentioned)
|
36
|
+
x.target_string
|
37
|
+
else
|
38
|
+
x
|
39
|
+
end
|
40
|
+
end.join
|
41
|
+
else
|
42
|
+
@target
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|