aozora2html 2.0.0 → 3.0.0
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 +4 -1
- data/.rubocop.yml +36 -152
- data/.rubocop_todo.yml +7 -0
- data/CHANGELOG.md +26 -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 +24 -22
- 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/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 +1358 -3
- data/lib/extensions.rb +2 -34
- data/lib/jstream.rb +96 -25
- data/sample/chukiichiran_kinyurei.html +15 -2
- data/sample/chukiichiran_kinyurei.txt +15 -2
- data/test/test_aozora2html.rb +137 -148
- data/test/test_aozora_accent_parser.rb +26 -9
- data/test/test_command_parse.rb +25 -22
- data/test/test_compat.rb +3 -4
- data/test/test_dakuten_katakana_tag.rb +10 -12
- data/test/test_decorate_tag.rb +9 -6
- data/test/test_dir_tag.rb +9 -6
- data/test/test_editor_note_tag.rb +8 -5
- data/test/test_exception.rb +10 -8
- data/test/test_font_size_tag.rb +16 -13
- data/test/test_gaiji_tag.rb +15 -14
- data/test/test_header.rb +25 -40
- data/test/test_helper.rb +3 -1
- data/test/test_i18n.rb +22 -6
- data/test/test_img_tag.rb +9 -5
- data/test/test_inline_caption_tag.rb +9 -6
- data/test/test_inline_font_size_tag.rb +13 -10
- data/test/test_inline_keigakomi_tag.rb +9 -6
- data/test/test_inline_yokogumi_tag.rb +9 -6
- data/test/test_jizume_tag.rb +9 -7
- data/test/test_jstream.rb +33 -30
- data/test/test_kaeriten_tag.rb +9 -6
- data/test/test_keigakomi_tag.rb +11 -9
- data/test/test_midashi_tag.rb +15 -14
- data/test/test_multiline_caption_tag.rb +7 -5
- data/test/test_multiline_midashi_tag.rb +24 -25
- data/test/test_multiline_style_tag.rb +9 -7
- data/test/test_multiline_yokogumi_tag.rb +7 -5
- data/test/test_okurigana_tag.rb +9 -6
- data/test/test_ruby_parse.rb +14 -14
- data/test/test_ruby_tag.rb +9 -6
- data/test/test_tag_parser.rb +28 -26
- metadata +60 -14
- data/.travis.yml +0 -12
- data/lib/t2hs.rb +0 -1607
data/lib/aozora2html/utils.rb
CHANGED
@@ -1,27 +1,31 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
class Aozora2Html
|
4
|
+
# ユーティリティ関数モジュール
|
3
5
|
module Utils
|
6
|
+
using StringRefinements
|
7
|
+
|
8
|
+
KANJI_NUMS = '一二三四五六七八九〇'.to_sjis
|
9
|
+
KANJI_TEN = '十'.to_sjis
|
10
|
+
ZENKAKU_NUMS = '0-9'.to_sjis
|
4
11
|
|
5
12
|
def create_font_size(times, daisho)
|
6
|
-
size =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
raise Aozora2Html::Error, I18n.t(:invalid_font_size)
|
17
|
-
end
|
18
|
-
end
|
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
|
19
23
|
|
20
24
|
case daisho
|
21
25
|
when :dai
|
22
|
-
size <<
|
26
|
+
size << 'large'
|
23
27
|
when :sho
|
24
|
-
size <<
|
28
|
+
size << 'small'
|
25
29
|
else
|
26
30
|
raise Aozora2Html::Error, I18n.t(:invalid_font_size)
|
27
31
|
end
|
@@ -32,11 +36,11 @@ class Aozora2Html
|
|
32
36
|
|
33
37
|
def create_midashi_tag(size)
|
34
38
|
if size.match(SIZE_SMALL)
|
35
|
-
|
39
|
+
'h5'
|
36
40
|
elsif size.match(SIZE_MIDDLE)
|
37
|
-
|
41
|
+
'h4'
|
38
42
|
elsif size.match(SIZE_LARGE)
|
39
|
-
|
43
|
+
'h3'
|
40
44
|
else
|
41
45
|
raise Aozora2Html::Error, I18n.t(:undefined_header)
|
42
46
|
end
|
@@ -44,34 +48,31 @@ class Aozora2Html
|
|
44
48
|
module_function :create_midashi_tag
|
45
49
|
|
46
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
|
+
|
47
69
|
case type
|
48
70
|
when :normal
|
49
|
-
|
50
|
-
when "h5"
|
51
|
-
"ko-midashi"
|
52
|
-
when "h4"
|
53
|
-
"naka-midashi"
|
54
|
-
when "h3"
|
55
|
-
"o-midashi"
|
56
|
-
end
|
71
|
+
normal_midashi_tag[tag]
|
57
72
|
when :dogyo
|
58
|
-
|
59
|
-
when "h5"
|
60
|
-
"dogyo-ko-midashi"
|
61
|
-
when "h4"
|
62
|
-
"dogyo-naka-midashi"
|
63
|
-
when "h3"
|
64
|
-
"dogyo-o-midashi"
|
65
|
-
end
|
73
|
+
dogyo_midashi_tag[tag]
|
66
74
|
when :mado
|
67
|
-
|
68
|
-
when "h5"
|
69
|
-
"mado-ko-midashi"
|
70
|
-
when "h4"
|
71
|
-
"mado-naka-midashi"
|
72
|
-
when "h3"
|
73
|
-
"mado-o-midashi"
|
74
|
-
end
|
75
|
+
mado_midashi_tag[tag]
|
75
76
|
else
|
76
77
|
raise Aozora2Html::Error, I18n.t(:undefined_header)
|
77
78
|
end
|
@@ -79,15 +80,77 @@ class Aozora2Html
|
|
79
80
|
module_function :create_midashi_class
|
80
81
|
|
81
82
|
def convert_japanese_number(command)
|
82
|
-
tmp = command.tr(
|
83
|
-
tmp.tr!(
|
84
|
-
tmp.gsub!(/(\d)#{
|
85
|
-
tmp.gsub!(/(\d)#{
|
86
|
-
tmp.gsub!(/#{
|
87
|
-
tmp.gsub!(/#{
|
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')
|
88
89
|
tmp
|
89
90
|
end
|
90
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
|
91
155
|
end
|
92
156
|
end
|
93
|
-
|
data/lib/aozora2html/version.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'yaml'
|
4
|
+
|
2
5
|
class Aozora2Html
|
6
|
+
# YAML Loader class for Shift_JIS
|
3
7
|
class YamlLoader
|
4
8
|
def initialize(base_dir)
|
5
9
|
@base_dir = base_dir
|
@@ -10,10 +14,12 @@ class Aozora2Html
|
|
10
14
|
normalize_data(tmp_data)
|
11
15
|
end
|
12
16
|
|
17
|
+
using StringRefinements
|
18
|
+
|
13
19
|
def normalize_data(data)
|
14
20
|
case data
|
15
21
|
when String
|
16
|
-
data.
|
22
|
+
data.to_sjis
|
17
23
|
when Hash
|
18
24
|
new_data = {}
|
19
25
|
data.each do |k, v|
|
@@ -21,7 +27,7 @@ class Aozora2Html
|
|
21
27
|
end
|
22
28
|
new_data
|
23
29
|
when Array
|
24
|
-
data.map{|item| normalize_data(item)}
|
30
|
+
data.map { |item| normalize_data(item) }
|
25
31
|
else
|
26
32
|
# noop
|
27
33
|
data
|