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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 635bbe67e2511af4a4f8ccc8a820bdb87991d75d88fa9aa7ca9a90f2f67d7785
4
- data.tar.gz: ac7c5d1f77f0c4b89d24f93e6117107d3ee4ac5890aef5e082368f0fa7e8e318
3
+ metadata.gz: 5a2a25b5bae94f8cd3f95db62357eb5de12a99fafe7681132ca045067f72dadc
4
+ data.tar.gz: 8e4474f765260485a1f4917de8cf8b81438f6a6863b2614b9e5d3f9d50abca29
5
5
  SHA512:
6
- metadata.gz: a939ef551dd506ae1f7ca4d608fbbe747aa7b4ada56a07fd83385c330fade541353d80f66fa8f4ed5d1342cd01d65af74c6c973ed2979c1dce12dcc7b10830a2
7
- data.tar.gz: 5c982a53cdffc60bad3c98406b74f640af4c1896fed6b42398a91025788962b4d2377950d40a0b25e4553fd92f94ac69c4ed8ac34fa21918cd0cb2148a1b0def
6
+ metadata.gz: b61e229c27b0b90fca3982e566b7fd51683ee9cabc0c1b77988c46d994ac5fb20d295ad5916da8b7a70947337bad034f45780ad335b9f9993562cf655e6b056f
7
+ data.tar.gz: 4c693c649646c27596545ae7f0577b1336d9afdb21d6380f63f9e2558253796b1c37d54818a9cc90414a01cf0fdcf5e1e01b2997a31fc86a1c770d9d42e3b5ac
@@ -0,0 +1,19 @@
1
+ name: rubocop
2
+ on: [pull_request]
3
+ jobs:
4
+ rubocop:
5
+ name: runner / rubocop
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - name: Check out code
9
+ uses: actions/checkout@v2
10
+ - name: Setup Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.3
14
+ bundler-cache: true
15
+ - name: Run rubocop
16
+ run: |
17
+ gem install bundler --no-document
18
+ bundle install --retry 3
19
+ bundle exec rubocop -P
@@ -18,8 +18,11 @@ jobs:
18
18
  strategy:
19
19
  fail-fast: false
20
20
  matrix:
21
- ruby: [ '3.0', '2.7', '2.6', '2.5', '2.4' ]
21
+ ruby: [ '3.1', '3.0', '2.7' ]
22
22
  os: [ubuntu-latest, macos-latest, windows-latest]
23
+ exclude:
24
+ - os: windows-latest
25
+ ruby: '3.1'
23
26
  steps:
24
27
  - uses: actions/checkout@v1
25
28
  - name: Set up Ruby
data/.rubocop.yml CHANGED
@@ -1,175 +1,78 @@
1
- inherit_gem:
2
- meowcop:
3
- - config/rubocop.yml
1
+ inherit_from: .rubocop_todo.yml
4
2
 
5
- AllCops:
6
- TargetRubyVersion: 2.1
3
+ # inherit_from: .rubocop_todo.yml
7
4
 
8
- # EnforcedStyle: with_first_parameter => 0 offense
9
- # EnforcedStyle: with_fixed_indentation => 17 offenses
10
- Layout/AlignParameters:
11
- EnforcedStyle: with_first_parameter
12
- Enabled: true
5
+ require:
6
+ - rubocop-performance
7
+ - rubocop-rake
13
8
 
14
- # EnforcedStyle: empty_lines => 80 offenses
15
- # EnforcedStyle: no_empty_lines => 0 offense
16
- Layout/EmptyLinesAroundBlockBody:
17
- EnforcedStyle: no_empty_lines
18
- Enabled: true
19
-
20
- # EnforcedStyleInsidePipes: space => 39 offenses
21
- # EnforcedStyleInsidePipes: no_space => 0 offense
22
- Layout/SpaceAroundBlockParameters:
23
- EnforcedStyleInsidePipes: no_space
24
- Enabled: true
25
-
26
- # EnforcedStyle: space => 42 offenses
27
- # EnforcedStyle: no_space => 4 offenses
28
- Layout/SpaceBeforeBlockBraces:
29
- EnforcedStyle: no_space
30
- Enabled: true
31
-
32
- # EnforcedStyle: space => 98 offenses
33
- # EnforcedStyle: no_space => 0 offense
34
- Layout/SpaceInsideStringInterpolation:
35
- EnforcedStyle: no_space
36
- Enabled: true
9
+ AllCops:
10
+ TargetRubyVersion: 2.7
11
+ NewCops: enable
37
12
 
38
- # EnforcedStyle: percent_q => 0 offense
39
- # EnforcedStyle: bare_percent => 30 offenses
40
13
  Style/BarePercentLiterals:
41
14
  EnforcedStyle: percent_q
42
- Enabled: true
43
15
 
44
- # EnforcedStyle: nested => 2 offenses
45
- # EnforcedStyle: compact => 81 offenses
46
- Style/ClassAndModuleChildren:
47
- EnforcedStyle: nested
48
- Enabled: true
16
+ Style/Documentation:
17
+ Exclude:
18
+ - 'test/**/*'
49
19
 
50
- # EnforcedStyle: compact => 24 offenses
51
- # EnforcedStyle: expanded => 0 offense
52
20
  Style/EmptyMethod:
53
21
  EnforcedStyle: expanded
54
22
  Enabled: true
55
23
 
56
- # EnforcedStyle: when_needed => 10 offenses
57
- # EnforcedStyle: always => 57 offenses
58
- # EnforcedStyle: never => 32 offenses
59
- Style/Encoding:
60
- EnforcedStyle: when_needed
61
- Enabled: true
62
-
63
- # EnforcedStyle: for => 13 offenses
64
- # EnforcedStyle: each => 0 offense
65
- Style/For:
66
- EnforcedStyle: each
67
- Enabled: true
68
-
69
- # EnforcedStyle: require_parentheses => 0 offense
70
- # EnforcedStyle: require_no_parentheses => 112 offenses
71
- # EnforcedStyle: require_no_parentheses_except_multiline => 112 offenses
72
- Style/MethodDefParentheses:
73
- EnforcedStyle: require_parentheses
74
- Enabled: true
75
-
76
- # EnforcedStyle: snake_case => 0 offense
77
- # EnforcedStyle: camelCase => 268 offenses
78
- Style/MethodName:
79
- EnforcedStyle: snake_case
80
- Enabled: true
81
-
82
- # EnforcedStyle: compact => 25 offenses
83
- # EnforcedStyle: exploded => 0 offense
84
- Style/RaiseArgs:
85
- EnforcedStyle: exploded
86
- Enabled: true
87
-
88
- # EnforcedStyle: only_raise => 0 offense
89
- # EnforcedStyle: only_fail => 26 offenses
90
- # EnforcedStyle: semantic => 25 offenses
91
- Style/SignalException:
92
- EnforcedStyle: only_raise
93
- Enabled: true
94
-
95
- # EnforcedStyle: snake_case => 0 offense
96
- # EnforcedStyle: camelCase => 126 offenses
97
- Style/VariableName:
98
- EnforcedStyle: snake_case
99
- Enabled: true
100
-
101
- # EnforcedStyle: snake_case => 11 offenses
102
- # EnforcedStyle: normalcase => 0 offense
103
- # EnforcedStyle: non_integer => 11 offenses
104
- Style/VariableNumber:
105
- EnforcedStyle: normalcase
106
- Enabled: true
24
+ Style/FormatString:
25
+ EnforcedStyle: sprintf
107
26
 
108
- Style/StringLiterals:
109
- Enabled: false
27
+ Style/FormatStringToken:
28
+ EnforcedStyle: unannotated
110
29
 
111
- Layout/SpaceAfterComma:
112
- Enabled: false
30
+ Style/FrozenStringLiteralComment:
31
+ Exclude:
32
+ - 'lib/aozora2html.rb'
113
33
 
114
- Layout/SpaceAroundOperators:
115
- Enabled: false
116
-
117
- Layout/SpaceInsideBlockBraces:
118
- Enabled: false
119
-
120
- Style/UnneededPercentQ:
34
+ Style/RedundantPercentQ:
121
35
  Enabled: false
122
36
 
123
37
  Style/PercentQLiterals:
124
38
  Enabled: false
125
39
 
126
- Style/SpecialGlobalVars:
127
- Enabled: false
128
-
129
- Style/Encoding:
130
- Enabled: false
131
-
132
40
  Style/ParallelAssignment:
133
41
  Enabled: false
134
42
 
135
- Style/IfInsideElse:
136
- Enabled: false
137
-
138
- Style/PercentLiteralDelimiters:
139
- Enabled: false
140
-
141
- Style/ClassCheck:
142
- Enabled: false
143
-
144
- Style/RedundantBegin:
145
- Enabled: false
146
-
147
- Layout/EmptyLineAfterMagicComment:
148
- Enabled: false
149
-
150
43
  Style/AsciiComments:
151
44
  Enabled: false
152
45
 
153
46
  Style/LineEndConcatenation:
154
47
  Enabled: false
155
48
 
156
- Style/MethodCallWithoutArgsParentheses:
49
+ Style/IfUnlessModifier:
157
50
  Enabled: false
158
51
 
159
- Style/GlobalVars:
52
+ Style/NumericPredicate:
160
53
  Enabled: false
161
54
 
162
- Style/IfUnlessModifier:
55
+ Style/PerlBackrefs:
163
56
  Enabled: false
164
57
 
165
- Style/NumericPredicate:
58
+ Style/SpecialGlobalVars:
166
59
  Enabled: false
167
60
 
61
+ Style/SymbolArray:
62
+ EnforcedStyle: brackets
63
+
64
+ Style/WordArray:
65
+ EnforcedStyle: brackets
66
+
168
67
  Style/ZeroLengthPredicate:
169
68
  Enabled: false
170
69
 
171
- Layout/TrailingBlankLines:
172
- Enabled: false
70
+ Layout/LineLength:
71
+ Enabled: true
72
+ Max: 500
73
+
74
+ Lint/EmptyClass:
75
+ AllowComments: true
173
76
 
174
77
  Metrics/AbcSize:
175
78
  Enabled: true
@@ -191,17 +94,13 @@ Metrics/CyclomaticComplexity:
191
94
  Enabled: true
192
95
  Max: 100
193
96
 
194
- Metrics/LineLength:
195
- Enabled: true
196
- Max: 500
197
-
198
97
  Metrics/MethodLength:
199
98
  Enabled: true
200
99
  Max: 200
201
100
 
202
101
  Metrics/ModuleLength:
203
102
  Enabled: true
204
- Max: 100
103
+ Max: 200
205
104
 
206
105
  Metrics/ParameterLists:
207
106
  Enabled: true
@@ -210,18 +109,3 @@ Metrics/ParameterLists:
210
109
  Metrics/PerceivedComplexity:
211
110
  Enabled: true
212
111
  Max: 100
213
-
214
-
215
- ###
216
- Performance/RedundantMatch:
217
- Enabled: false
218
- Performance/StringReplacement:
219
- Enabled: false
220
- Layout/SpaceBeforeBlockBraces:
221
- Enabled: false
222
-
223
- ### あとで直す
224
- Lint/StringConversionInInterpolation:
225
- Enabled: false
226
- Style/ClassAndModuleChildren:
227
- Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,7 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config --exclude-limit 99999 --no-offense-counts --no-auto-gen-timestamp`
3
+ # using RuboCop version 1.23.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ <a name="3.0.0"></a>
2
+ ## 3.0.0
3
+
4
+ ### Breaking Changes
5
+
6
+ * Ruby 2.7未満をサポート対象外にしました。Ruby 3.0以降を推奨します。それ以前のRubyを使われる場合はv2.0.0をご利用ください https://github.com/aozorahack/aozora2html/pull/49
7
+ * t2hs.rbを廃止し、bin/aozora2html以外からは実行できなくしました https://github.com/aozorahack/aozora2html/pull/65 
8
+ * t2hs.rbにあったメソッドのうち、通常外部から使われないメソッドをprivateにしました https://github.com/aozorahack/aozora2html/pull/93
9
+
10
+ ### Bug Fixes
11
+
12
+ * 以前は全角空白であったところが半角空白になっていたので修正しました https://github.com/aozorahack/aozora2html/pull/62
13
+
14
+ ### Features
15
+
16
+ * エラーメッセージがUTF-8になる `--error-utf8` オプションを追加しました https://github.com/aozorahack/aozora2html/pull/72
17
+ * `sample/chukiichiran_kinyurei.txt`に他の例を追加しました https://github.com/aozorahack/aozora2html/pull/78
18
+ * `rake chuuki`で`sample/chukiichiran_kinyurei.txt`を`sample/chukiichiran_kinyurei.html`に変換できるrakeタスクを追加しました https://github.com/aozorahack/aozora2html/pull/95
19
+
20
+ <a name="2.0.0"></a>
21
+ ## 2.0.0
22
+
23
+ ### Bug Fixes
24
+
25
+ * Ruby 3.0でエラーになる挙動を修正しました https://github.com/aozorahack/aozora2html/pull/36, https://github.com/aozorahack/aozora2html/pull/41
26
+
1
27
  <a name="0.9.1"></a>
2
28
  ## 0.9.1
3
29
 
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in aozora2html.gemspec
data/Guardfile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  guard :test do
2
4
  watch(%r{^test/test_.+\.rb$})
3
- watch('test/test_helper.rb') { 'test' }
5
+ watch('test/test_helper.rb') { 'test' }
4
6
 
5
7
  # Non-rails
6
8
  watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
data/HACKING.md ADDED
@@ -0,0 +1,45 @@
1
+ # HACKING
2
+
3
+ aozora2htmlの技術的なnoteです。
4
+
5
+ ## `char_type`について
6
+
7
+ aozora2htmlでは、`String#char_type`というメソッドが追加されています。
8
+
9
+ `char_type`はルビの範囲を判別するために使われるメソッドです。
10
+
11
+ * ひらがな: :hiragana
12
+ * カタカナ: :katakana
13
+ * 全角英数(ギリシア文字含む): :zenkaku
14
+ * 半角英数(記号#-&',含む): :hankaku
15
+ * 漢字: :kanji
16
+ * 半角句読点等(.;"?!)): :hankaku_terminate
17
+ * その他: :else
18
+
19
+ 欧文アクセント文字は半角英数、濁点つきカタカナはカタカナ、外字は漢字、訓点はその他、ルビ付き文字はその他になります。
20
+
21
+ RubyBufferも`RubyBuffer#char_type`を持っています。これはRubyBufferの中身次第で変更されます。複数のchar_typeを内部で持つ場合、char_typeは:elseになります。
22
+
23
+
24
+ ## `Aozora2Html::TextBuffer`について
25
+
26
+ 古いRubyでは、`Array#to_s`はArrayの全要素が文字列だった場合、`join`と同じ挙動でした。
27
+
28
+ 現在のRubyでは、同様のことをするには`Array#join`を使わなければならなくなっており、`Array#to_s`をすると`[]`等が出力されます。これは埋め込み文字列に使った場合も同様です。
29
+ そのため、aozora2htmlでは`Array`の代わりに`Aozora2Html::TextBuffer`クラスを導入しています。`Aozora2Html::TextBuffer#to_s`は適切な文字列を返します。
30
+
31
+
32
+ ## `Jstream`について
33
+
34
+ `JStream`は`IO`の代わりとなるクラスです。
35
+
36
+ 主に、読み込み行の行数の管理と、任意の文字数の先読みを行うために使われています。
37
+
38
+ 先読みは同一行内のみ有効で、CRLFを超える先読みは動作が保証されません。
39
+
40
+
41
+ ## `Aozora2Html::Tag::Multiline`について
42
+
43
+ `Aozora2Html::Tag::Multiline`は、そのタグが複数行であることを表すマーカー用のモジュールです。
44
+
45
+ マーカーとして使われるため、メソッド等は特に持っていない、空のモジュールとして実装されています。実行中に追加されたりすることもありません。
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # Aozora2Html
2
2
 
3
- [![Build Status](https://travis-ci.org/aozorahack/aozora2html.svg?branch=master)](https://travis-ci.org/aozorahack/aozora2html)
4
3
  [![Build Status](https://github.com/aozorahack/aozora2html/workflows/Test/badge.svg)](https://github.com/aozorahack/aozora2html/actions)
5
4
  [![Gem Version](https://badge.fury.io/rb/aozora2html.svg)](https://badge.fury.io/rb/aozora2html)
6
5
  [![Code Climate](https://codeclimate.com/github/aozorahack/aozora2html/badges/gpa.svg)](https://codeclimate.com/github/aozorahack/aozora2html)
@@ -9,7 +8,9 @@
9
8
 
10
9
  ## 動作環境
11
10
 
12
- Ruby 2.0以上が推奨ですが、1.9でも動くはずです。
11
+ Ruby 3.0以上が推奨ですが、2.7.xでも動くはずです。
12
+
13
+ それ以前のRuby 2.xで利用する場合は、aozora2html-2.0.xをご利用ください。
13
14
 
14
15
  ## インストール
15
16
 
@@ -54,10 +55,13 @@ $ aozora2html http://example.jp/foo/bar.zip foo.html
54
55
  $ aozora2html foo.txt
55
56
  ```
56
57
 
57
- コマンドラインオプションとして`--gaiji-dir`と`--use-jisx0213`、`--use-unicode`があります。
58
- `--gaiji-dir`は外字画像のパスを指定します。
59
- `--use-jisx0213`はJIS X 0213の外字画像を使わず、数値実体参照として表示します。
60
- `--use-unicode`はUnicodeのコードポイントが指定されている外字を数値実体参照として表示します。
58
+ コマンドラインオプションとして`--gaiji-dir`と`--css-files`、`--use-jisx0213`、`--use-unicode`、`--error-utf8`があります。
59
+
60
+ * `--gaiji-dir`は外字画像のパスを指定します。
61
+ * `--css-files`はCSSファイルを`,`区切りで指定します。
62
+ * `--use-jisx0213`はJIS X 0213の外字画像を使わず、数値実体参照として表示します。
63
+ * `--use-unicode`はUnicodeのコードポイントが指定されている外字を数値実体参照として表示します。
64
+ * `--error-utf8`はエラーメッセージをUTF-8で出力するようにします。
61
65
 
62
66
  可能な限り数値実体参照を使って表示するには、以下のようにオプションを指定します。
63
67
 
@@ -78,6 +82,10 @@ $ rake test
78
82
 
79
83
  主な更新履歴は[CHANGELOG.md](CHANGELOG.md)にあります。
80
84
 
85
+ ## コードについて
86
+
87
+ コードに関する技術的なnoteは[HACKING.md](HACKING.md)にあります。
88
+
81
89
  ## License
82
90
 
83
91
  CC0
data/Rakefile CHANGED
@@ -1,12 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
- require "bundler/gem_tasks"
4
+ require 'bundler/gem_tasks'
3
5
  require 'rake/testtask'
4
6
  require 'rake/clean'
5
7
 
6
- task :default => [:test]
8
+ task default: [:test]
7
9
 
8
- Rake::TestTask.new("test") do |t|
9
- t.libs << "test"
10
- t.test_files = Dir.glob("test/**/test_*.rb")
10
+ Rake::TestTask.new('test') do |t|
11
+ t.libs << 'test'
12
+ t.test_files = Dir.glob('test/**/test_*.rb')
11
13
  t.verbose = true
12
14
  end
15
+
16
+ desc 'convert sample/chukiichiran_kinyurei.txt'
17
+ task :chuuki do
18
+ sh 'bundle exec aozora2html --error-utf8 sample/chukiichiran_kinyurei.txt sample/chukiichiran_kinyurei.html'
19
+ end
data/aozora2html.gemspec CHANGED
@@ -1,33 +1,35 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'aozora2html/version'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/aozora2html/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "aozora2html"
6
+ spec.name = 'aozora2html'
8
7
  spec.version = Aozora2Html::VERSION
9
8
  spec.platform = Gem::Platform::RUBY
10
- spec.license = "CC0"
11
- spec.authors = ["aozorahack team"]
12
- spec.email = ["takahashimm@gmail.com"]
9
+ spec.license = 'CC0'
10
+ spec.authors = ['aozorahack team']
11
+ spec.email = ['takahashimm@gmail.com']
13
12
 
14
- spec.summary = %q{converter from Aozora Bunko format into xhtml. It's based of t2hs.rb from kumihan.aozora.gr.jp.}
15
- spec.description = %q{converter from Aozora Bunko format into xhtml. It's based of t2hs.rb from kumihan.aozora.gr.jp.}
16
- spec.homepage = "https://github.com/aozorahack/aozora2html"
13
+ spec.summary = %q(converter from Aozora Bunko format into xhtml. It's based of t2hs.rb from kumihan.aozora.gr.jp.)
14
+ spec.description = %q(converter from Aozora Bunko format into xhtml. It's based of t2hs.rb from kumihan.aozora.gr.jp.)
15
+ spec.homepage = 'https://github.com/aozorahack/aozora2html'
17
16
 
17
+ spec.required_ruby_version = '>= 2.7.0'
18
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- spec.bindir = "bin"
19
+ spec.bindir = 'bin'
20
20
  spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
21
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
22
+ spec.require_paths = ['lib']
23
23
 
24
- if RUBY_VERSION < "2.4.0"
25
- spec.add_dependency "rubyzip", "~> 1.3"
26
- else
27
- spec.add_dependency "rubyzip", "~> 2.0"
28
- end
29
- spec.add_development_dependency "bundler"
30
- spec.add_development_dependency "rake", "~> 12.0"
31
- spec.add_development_dependency "test-unit"
32
- spec.add_development_dependency "test-unit-rr"
24
+ spec.add_dependency 'rubyzip'
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'rake', '~> 12.0'
27
+ spec.add_development_dependency 'rubocop'
28
+ spec.add_development_dependency 'rubocop-performance'
29
+ spec.add_development_dependency 'rubocop-rake'
30
+ spec.add_development_dependency 'test-unit'
31
+ spec.add_development_dependency 'test-unit-rr'
32
+ spec.metadata = {
33
+ 'rubygems_mfa_required' => 'true'
34
+ }
33
35
  end
data/bin/aozora2html CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'aozora2html'
4
5
  require 'optparse'
5
- require "tempfile"
6
+ require 'tempfile'
6
7
  require 'open-uri'
7
8
 
8
9
  opt = OptionParser.new("Usage: aozora2html [options] <text file> [<html file>]\n")
@@ -10,26 +11,27 @@ opt.on('--gaiji-dir DIR', 'setting gaiji directory')
10
11
  opt.on('--css-files FILES', 'setting css directory')
11
12
  opt.on('--use-jisx0213', 'use JIS X 0213 character')
12
13
  opt.on('--use-unicode', 'use Unicode character')
14
+ opt.on('--error-utf8', 'show error messages in UTF-8, not Shift_JIS')
13
15
  opt.version = Aozora2Html::VERSION
14
16
  options = opt.getopts
15
17
 
16
- if options["gaiji-dir"]
17
- $gaiji_dir = options["gaiji-dir"]
18
- end
18
+ gaiji_dir = options['gaiji-dir'] || nil
19
19
 
20
- if options["css-files"]
21
- $css_files = options["css-files"].split(",")
22
- end
20
+ css_files = options['css-files']&.split(',')
23
21
 
24
- if options["use-jisx0213"]
22
+ if options['use-jisx0213']
25
23
  Aozora2Html::Tag::EmbedGaiji.use_jisx0213 = true
26
24
  Aozora2Html::Tag::Accent.use_jisx0213 = true
27
25
  end
28
26
 
29
- if options["use-unicode"]
27
+ if options['use-unicode']
30
28
  Aozora2Html::Tag::EmbedGaiji.use_unicode = true
31
29
  end
32
30
 
31
+ if options['error-utf8']
32
+ Aozora2Html::I18n.use_utf8 = true
33
+ end
34
+
33
35
  if ARGV.size < 1 || ARGV.size > 2
34
36
  $stderr.print opt.banner
35
37
  exit 1
@@ -39,34 +41,34 @@ src_file, dest_file = ARGV[0], ARGV[1]
39
41
 
40
42
  Dir.mktmpdir do |dir|
41
43
  if dest_file.nil?
42
- dest_file = File.join(dir, "output.html")
44
+ dest_file = File.join(dir, 'output.html')
43
45
  end
44
- if src_file =~ /\Ahttps?:/
46
+ if /\Ahttps?:/.match?(src_file)
45
47
  down_file = File.join(dir, File.basename(src_file))
46
48
  begin
47
49
  File.write(down_file, URI.parse(src_file).read)
48
50
  src_file = down_file
49
- rescue
51
+ rescue StandardError
50
52
  $stderr.print "file not found: #{src_file}\n"
51
53
  $stderr.print "Download Error: #{$!}\n"
52
54
  exit 1
53
55
  end
54
56
  else
55
- if !File.exist?(src_file)
57
+ unless File.exist?(src_file)
56
58
  $stderr.print "file not found: #{src_file}\n"
57
59
  exit 1
58
60
  end
59
61
  end
60
62
 
61
- if File.extname(src_file) == ".zip"
62
- require "aozora2html/zip"
63
- tmpfile = File.join(dir, "aozora.txt")
63
+ if File.extname(src_file) == '.zip'
64
+ require 'aozora2html/zip'
65
+ tmpfile = File.join(dir, 'aozora.txt')
64
66
  Aozora2Html::Zip.unzip(src_file, tmpfile)
65
- Aozora2Html.new(tmpfile, dest_file).process
67
+ Aozora2Html.new(tmpfile, dest_file, gaiji_dir: gaiji_dir, css_files: css_files).process
66
68
  else
67
- Aozora2Html.new(src_file, dest_file).process
69
+ Aozora2Html.new(src_file, dest_file, gaiji_dir: gaiji_dir, css_files: css_files).process
68
70
  end
69
- if !ARGV[1]
71
+ unless ARGV[1]
70
72
  output = File.read(dest_file)
71
73
  print output
72
74
  end