aozora2html 0.7.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/rubocop.yml +19 -0
  3. data/.github/workflows/ruby.yml +37 -0
  4. data/.gitignore +8 -3
  5. data/.rubocop.yml +111 -0
  6. data/.rubocop_todo.yml +7 -0
  7. data/CHANGELOG.md +59 -0
  8. data/Gemfile +2 -0
  9. data/Guardfile +3 -1
  10. data/HACKING.md +45 -0
  11. data/LICENSE +116 -0
  12. data/README.md +29 -16
  13. data/Rakefile +12 -5
  14. data/aozora2html.gemspec +24 -24
  15. data/bin/aozora2html +25 -71
  16. data/lib/aozora2html/accent_parser.rb +99 -0
  17. data/lib/aozora2html/error.rb +17 -0
  18. data/lib/aozora2html/header.rb +141 -0
  19. data/lib/aozora2html/i18n.rb +48 -0
  20. data/lib/aozora2html/ruby_buffer.rb +116 -0
  21. data/lib/aozora2html/string_refinements.rb +36 -0
  22. data/lib/aozora2html/style_stack.rb +33 -0
  23. data/lib/aozora2html/tag/accent.rb +37 -0
  24. data/lib/aozora2html/tag/block.rb +21 -0
  25. data/lib/aozora2html/tag/chitsuki.rb +19 -0
  26. data/lib/aozora2html/tag/dakuten_katakana.rb +25 -0
  27. data/lib/aozora2html/tag/decorate.rb +19 -0
  28. data/lib/aozora2html/tag/dir.rb +17 -0
  29. data/lib/aozora2html/tag/editor_note.rb +19 -0
  30. data/lib/aozora2html/tag/embed_gaiji.rb +52 -0
  31. data/lib/aozora2html/tag/font_size.rb +20 -0
  32. data/lib/aozora2html/tag/gaiji.rb +12 -0
  33. data/lib/aozora2html/tag/img.rb +21 -0
  34. data/lib/aozora2html/tag/indent.rb +8 -0
  35. data/lib/aozora2html/tag/inline.rb +16 -0
  36. data/lib/aozora2html/tag/inline_caption.rb +17 -0
  37. data/lib/aozora2html/tag/inline_font_size.rb +19 -0
  38. data/lib/aozora2html/tag/inline_keigakomi.rb +17 -0
  39. data/lib/aozora2html/tag/inline_yokogumi.rb +17 -0
  40. data/lib/aozora2html/tag/jisage.rb +17 -0
  41. data/lib/aozora2html/tag/jizume.rb +19 -0
  42. data/lib/aozora2html/tag/kaeriten.rb +17 -0
  43. data/lib/aozora2html/tag/keigakomi.rb +19 -0
  44. data/lib/aozora2html/tag/kunten.rb +12 -0
  45. data/lib/aozora2html/tag/midashi.rb +20 -0
  46. data/lib/aozora2html/tag/multiline.rb +9 -0
  47. data/lib/aozora2html/tag/multiline_caption.rb +13 -0
  48. data/lib/aozora2html/tag/multiline_chitsuki.rb +10 -0
  49. data/lib/aozora2html/tag/multiline_jisage.rb +10 -0
  50. data/lib/aozora2html/tag/multiline_midashi.rb +25 -0
  51. data/lib/aozora2html/tag/multiline_style.rb +19 -0
  52. data/lib/aozora2html/tag/multiline_yokogumi.rb +14 -0
  53. data/lib/aozora2html/tag/okurigana.rb +17 -0
  54. data/lib/aozora2html/tag/oneline_chitsuki.rb +10 -0
  55. data/lib/aozora2html/tag/oneline_indent.rb +9 -0
  56. data/lib/aozora2html/tag/oneline_jisage.rb +10 -0
  57. data/lib/aozora2html/tag/reference_mentioned.rb +47 -0
  58. data/lib/aozora2html/tag/ruby.rb +202 -0
  59. data/lib/aozora2html/tag/un_embed_gaiji.rb +30 -0
  60. data/lib/aozora2html/tag.rb +57 -0
  61. data/lib/aozora2html/tag_parser.rb +60 -0
  62. data/lib/aozora2html/text_buffer.rb +50 -0
  63. data/lib/aozora2html/utils.rb +156 -0
  64. data/lib/aozora2html/version.rb +3 -1
  65. data/lib/aozora2html/yaml_loader.rb +37 -0
  66. data/lib/aozora2html/zip.rb +4 -0
  67. data/lib/aozora2html.rb +1359 -8
  68. data/lib/extensions.rb +12 -0
  69. data/lib/jstream.rb +139 -0
  70. data/sample/chukiichiran_kinyurei.html +15 -2
  71. data/sample/chukiichiran_kinyurei.txt +15 -2
  72. data/test/test_aozora2html.rb +323 -73
  73. data/test/test_aozora_accent_parser.rb +34 -6
  74. data/test/test_command_parse.rb +216 -0
  75. data/test/test_compat.rb +3 -4
  76. data/test/test_dakuten_katakana_tag.rb +12 -13
  77. data/test/test_decorate_tag.rb +11 -7
  78. data/test/test_dir_tag.rb +11 -7
  79. data/test/test_editor_note_tag.rb +9 -6
  80. data/test/test_exception.rb +11 -9
  81. data/test/test_font_size_tag.rb +22 -11
  82. data/test/test_gaiji_tag.rb +22 -14
  83. data/test/test_header.rb +45 -0
  84. data/test/test_helper.rb +3 -1
  85. data/test/test_i18n.rb +39 -0
  86. data/test/test_img_tag.rb +11 -6
  87. data/test/test_inline_caption_tag.rb +11 -7
  88. data/test/test_inline_font_size_tag.rb +15 -11
  89. data/test/test_inline_keigakomi_tag.rb +11 -7
  90. data/test/test_inline_yokogumi_tag.rb +11 -7
  91. data/test/test_jizume_tag.rb +11 -8
  92. data/test/test_jstream.rb +33 -30
  93. data/test/test_kaeriten_tag.rb +11 -7
  94. data/test/test_keigakomi_tag.rb +14 -11
  95. data/test/test_midashi_tag.rb +39 -0
  96. data/test/test_multiline_caption_tag.rb +11 -8
  97. data/test/test_multiline_midashi_tag.rb +26 -26
  98. data/test/test_multiline_style_tag.rb +11 -8
  99. data/test/test_multiline_yokogumi_tag.rb +11 -8
  100. data/test/test_okurigana_tag.rb +11 -7
  101. data/test/test_ruby_parse.rb +130 -0
  102. data/test/test_ruby_tag.rb +11 -7
  103. data/test/test_tag_parser.rb +31 -29
  104. data/vendor/jis2ucs/README.md +3 -6
  105. data/yml/accent_table.yml +240 -0
  106. data/yml/command_table.yml +61 -0
  107. data/yml/jis2ucs.yml +11234 -0
  108. metadata +99 -21
  109. data/.travis.yml +0 -12
  110. data/appveyor.yml +0 -23
  111. data/lib/accent_tag.rb +0 -23
  112. data/lib/aozora2html/jis2ucs.rb +0 -11237
  113. data/lib/embed_gaiji_tag.rb +0 -34
  114. data/lib/t2hs.rb +0 -2535
@@ -0,0 +1,202 @@
1
+ # frozen_string_literal: true
2
+
3
+ # complex ruby markup
4
+ # if css3 is major supported, please fix ruby position with property "ruby-position"
5
+ # see also: http://www.w3.org/TR/2001/WD-css3-ruby-20010216/
6
+ class Aozora2Html
7
+ class Tag
8
+ # ルビ用
9
+ #
10
+ # 現状、under_rubyは無視しているのに注意
11
+ class Ruby < Aozora2Html::Tag::ReferenceMentioned
12
+ attr_accessor :ruby, :under_ruby
13
+ attr_reader :target
14
+
15
+ def initialize(parser, string, ruby, under_ruby = '')
16
+ @target = string
17
+ @ruby = ruby
18
+ @under_ruby = under_ruby
19
+ super
20
+ end
21
+
22
+ def to_s
23
+ "<ruby><rb>#{@target}</rb><rp>#{PAREN_BEGIN_MARK}</rp><rt>#{@ruby}</rt><rp>#{PAREN_END_MARK}</rp></ruby>"
24
+ end
25
+
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
31
+
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
46
+
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)
51
+
52
+ if x.ruby == ''
53
+ raise Aozora2Html::Error, I18n.t(:dont_use_double_ruby) unless new_under.is_a?(Array)
54
+
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)
58
+
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
102
+
103
+ Aozora2Html::Tag::Ruby.new(parser, new_targets, new_upper, new_under)
104
+ end
105
+
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
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
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../string_refinements'
4
+
5
+ class Aozora2Html
6
+ class Tag
7
+ # 非埋め込み外字
8
+ class UnEmbedGaiji < Aozora2Html::Tag::Gaiji
9
+ def initialize(parser, desc)
10
+ @desc = desc
11
+ @escaped = false
12
+ super
13
+ end
14
+
15
+ using StringRefinements
16
+
17
+ def to_s
18
+ '<span class="notes">['.to_sjis + @desc + ']</span>'.to_sjis
19
+ end
20
+
21
+ def escaped?
22
+ @escaped
23
+ end
24
+
25
+ def escape!
26
+ @escaped = true
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,57 @@
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'
40
+
41
+ class Aozora2Html
42
+ # 変換される青空記法class
43
+ class Tag
44
+ # debug用
45
+ def inspect
46
+ to_s
47
+ end
48
+
49
+ def char_type
50
+ :else
51
+ end
52
+
53
+ def syntax_error
54
+ raise Aozora2Html::Error, I18n.t(:tag_syntax_error)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'ruby_buffer'
4
+
5
+ class Aozora2Html
6
+ # 注記記法parser
7
+ #
8
+ # 青空記法の入れ子に対応(?)
9
+ class TagParser < Aozora2Html
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'
13
+ end
14
+
15
+ @stream = input
16
+ @gaiji_dir = gaiji_dir
17
+ @buffer = TextBuffer.new
18
+ @ruby_buf = RubyBuffer.new
19
+ @chuuki_table = chuuki
20
+ @images = image # globalな環境を記録するアイテムは共有する必要あり
21
+ @endchar = endchar # 改行を越えるべきか否か…
22
+ @section = :tail # 末尾処理と記法内はインデントをしないので等価
23
+ @raw = +'' # 外字変換前の生テキストを残したいことがあるらしい
24
+ end
25
+
26
+ # method override!
27
+ def read_char
28
+ c = @stream.read_char
29
+ @raw.concat(c)
30
+ c
31
+ end
32
+
33
+ def read_to_nest(endchar)
34
+ ans = super(endchar)
35
+ @raw.concat(ans[1])
36
+ ans
37
+ end
38
+
39
+ # 出力は[String,String]返しで!
40
+ def general_output
41
+ @ruby_buf.dump_into(@buffer)
42
+ ans = +''
43
+ @buffer.each do |s|
44
+ if s.is_a?(Aozora2Html::Tag::UnEmbedGaiji) && !s.escaped?
45
+ # 消してあった※を復活させて
46
+ ans.concat(GAIJI_MARK)
47
+ end
48
+ ans.concat(s.to_s)
49
+ end
50
+ [ans, @raw]
51
+ end
52
+
53
+ def process
54
+ catch(:terminate) do
55
+ parse
56
+ end
57
+ general_output
58
+ end
59
+ end
60
+ 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
@@ -0,0 +1,156 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Aozora2Html
4
+ # ユーティリティ関数モジュール
5
+ module Utils
6
+ using StringRefinements
7
+
8
+ KANJI_NUMS = '一二三四五六七八九〇'.to_sjis
9
+ KANJI_TEN = '十'.to_sjis
10
+ ZENKAKU_NUMS = '0-9'.to_sjis
11
+
12
+ def create_font_size(times, daisho)
13
+ size = case times
14
+ when 1
15
+ +''
16
+ when 2
17
+ +'x-'
18
+ else
19
+ raise Aozora2Html::Error, I18n.t(:invalid_font_size) unless times >= 3
20
+
21
+ +'xx-'
22
+ end
23
+
24
+ case daisho
25
+ when :dai
26
+ size << 'large'
27
+ when :sho
28
+ size << 'small'
29
+ else
30
+ raise Aozora2Html::Error, I18n.t(:invalid_font_size)
31
+ end
32
+
33
+ size
34
+ end
35
+ module_function :create_font_size
36
+
37
+ def create_midashi_tag(size)
38
+ if size.match(SIZE_SMALL)
39
+ 'h5'
40
+ elsif size.match(SIZE_MIDDLE)
41
+ 'h4'
42
+ elsif size.match(SIZE_LARGE)
43
+ 'h3'
44
+ else
45
+ raise Aozora2Html::Error, I18n.t(:undefined_header)
46
+ end
47
+ end
48
+ module_function :create_midashi_tag
49
+
50
+ def create_midashi_class(type, tag)
51
+ normal_midashi_tag = {
52
+ 'h5' => 'ko-midashi',
53
+ 'h4' => 'naka-midashi',
54
+ 'h3' => 'o-midashi'
55
+ }
56
+
57
+ dogyo_midashi_tag = {
58
+ 'h5' => 'dogyo-ko-midashi',
59
+ 'h4' => 'dogyo-naka-midashi',
60
+ 'h3' => 'dogyo-o-midashi'
61
+ }
62
+
63
+ mado_midashi_tag = {
64
+ 'h5' => 'mado-ko-midashi',
65
+ 'h4' => 'mado-naka-midashi',
66
+ 'h3' => 'mado-o-midashi'
67
+ }
68
+
69
+ case type
70
+ when :normal
71
+ normal_midashi_tag[tag]
72
+ when :dogyo
73
+ dogyo_midashi_tag[tag]
74
+ when :mado
75
+ mado_midashi_tag[tag]
76
+ else
77
+ raise Aozora2Html::Error, I18n.t(:undefined_header)
78
+ end
79
+ end
80
+ module_function :create_midashi_class
81
+
82
+ def convert_japanese_number(command)
83
+ tmp = command.tr(ZENKAKU_NUMS, '0-9')
84
+ tmp.tr!(KANJI_NUMS, '1234567890')
85
+ tmp.gsub!(/(\d)#{KANJI_TEN}(\d)/o) { "#{$1}#{$2}" }
86
+ tmp.gsub!(/(\d)#{KANJI_TEN}/o) { "#{$1}0" }
87
+ tmp.gsub!(/#{KANJI_TEN}(\d)/o) { "1#{$1}" }
88
+ tmp.gsub!(/#{KANJI_TEN}/o, '10')
89
+ tmp
90
+ end
91
+ module_function :convert_japanese_number
92
+
93
+ # 使うべきではない文字があるかチェックする
94
+ #
95
+ # 警告を出力するだけで結果には影響を与えない。警告する文字は以下:
96
+ #
97
+ # * 1バイト文字
98
+ # * `#`ではなく`♯`
99
+ # * JIS(JIS X 0208)外字
100
+ #
101
+ # @return [void]
102
+ #
103
+ def illegal_char_check(char, line)
104
+ return unless char.is_a?(String)
105
+
106
+ code = char.unpack1('H*')
107
+ if (code == '21') ||
108
+ (code == '23') ||
109
+ ((code >= 'a1') && (code <= 'a5')) ||
110
+ ((code >= '28') && (code <= '29')) ||
111
+ (code == '5b') ||
112
+ (code == '5d') ||
113
+ (code == '3d') ||
114
+ (code == '3f') ||
115
+ (code == '2b') ||
116
+ ((code >= '7b') && (code <= '7d'))
117
+ puts I18n.t(:warn_onebyte, line, char)
118
+ end
119
+
120
+ if code == '81f2'
121
+ puts I18n.t(:warn_chuki, line, char)
122
+ end
123
+
124
+ if ((code >= '81ad') && (code <= '81b7')) ||
125
+ ((code >= '81c0') && (code <= '81c7')) ||
126
+ ((code >= '81cf') && (code <= '81d9')) ||
127
+ ((code >= '81e9') && (code <= '81ef')) ||
128
+ ((code >= '81f8') && (code <= '81fb')) ||
129
+ ((code >= '8240') && (code <= '824e')) ||
130
+ ((code >= '8259') && (code <= '825f')) ||
131
+ ((code >= '827a') && (code <= '8280')) ||
132
+ ((code >= '829b') && (code <= '829e')) ||
133
+ ((code >= '82f2') && (code <= '82fc')) ||
134
+ ((code >= '8397') && (code <= '839e')) ||
135
+ ((code >= '83b7') && (code <= '83be')) ||
136
+ ((code >= '83d7') && (code <= '83fc')) ||
137
+ ((code >= '8461') && (code <= '846f')) ||
138
+ ((code >= '8492') && (code <= '849e')) ||
139
+ ((code >= '84bf') && (code <= '84fc')) ||
140
+ ((code >= '8540') && (code <= '85fc')) ||
141
+ ((code >= '8640') && (code <= '86fc')) ||
142
+ ((code >= '8740') && (code <= '87fc')) ||
143
+ ((code >= '8840') && (code <= '889e')) ||
144
+ ((code >= '9873') && (code <= '989e')) ||
145
+ ((code >= 'eaa5') && (code <= 'eafc')) ||
146
+ ((code >= 'eb40') && (code <= 'ebfc')) ||
147
+ ((code >= 'ec40') && (code <= 'ecfc')) ||
148
+ ((code >= 'ed40') && (code <= 'edfc')) ||
149
+ ((code >= 'ee40') && (code <= 'eefc')) ||
150
+ ((code >= 'ef40') && (code <= 'effc'))
151
+ puts I18n.t(:warn_jis_gaiji, line, char)
152
+ end
153
+ end
154
+ module_function :illegal_char_check
155
+ end
156
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aozora2Html
2
- VERSION = "0.7.1"
4
+ VERSION = '3.0.0'
3
5
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ class Aozora2Html
6
+ # YAML Loader class for Shift_JIS
7
+ class YamlLoader
8
+ def initialize(base_dir)
9
+ @base_dir = base_dir
10
+ end
11
+
12
+ def load(path)
13
+ tmp_data = YAML.load_file(File.join(@base_dir, path))
14
+ normalize_data(tmp_data)
15
+ end
16
+
17
+ using StringRefinements
18
+
19
+ def normalize_data(data)
20
+ case data
21
+ when String
22
+ data.to_sjis
23
+ when Hash
24
+ new_data = {}
25
+ data.each do |k, v|
26
+ new_data[normalize_data(k)] = normalize_data(v)
27
+ end
28
+ new_data
29
+ when Array
30
+ data.map { |item| normalize_data(item) }
31
+ else
32
+ # noop
33
+ data
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'zip'
4
+
2
5
  class Aozora2Html
6
+ # zipファイルからテキストを抽出する
3
7
  class Zip
4
8
  def self.unzip(zipfilename, textfilename)
5
9
  ::Zip::File.open(zipfilename) do |zip_file|