aozora2html 2.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +19 -0
  3. data/.github/workflows/ruby.yml +5 -3
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +38 -151
  6. data/.rubocop_todo.yml +7 -0
  7. data/CHANGELOG.md +41 -0
  8. data/Gemfile +2 -0
  9. data/Guardfile +3 -1
  10. data/HACKING.md +45 -0
  11. data/README.md +14 -6
  12. data/Rakefile +12 -5
  13. data/aozora2html.gemspec +25 -23
  14. data/bin/aozora2html +21 -19
  15. data/lib/aozora2html/accent_parser.rb +62 -54
  16. data/lib/aozora2html/error.rb +5 -4
  17. data/lib/aozora2html/header.rb +20 -18
  18. data/lib/aozora2html/i18n.rb +40 -20
  19. data/lib/aozora2html/midashi_counter.rb +32 -0
  20. data/lib/aozora2html/ruby_buffer.rb +63 -28
  21. data/lib/aozora2html/string_refinements.rb +36 -0
  22. data/lib/aozora2html/style_stack.rb +6 -0
  23. data/lib/aozora2html/tag/accent.rb +10 -12
  24. data/lib/aozora2html/tag/block.rb +11 -9
  25. data/lib/aozora2html/tag/chitsuki.rb +6 -2
  26. data/lib/aozora2html/tag/dakuten_katakana.rb +10 -8
  27. data/lib/aozora2html/tag/decorate.rb +4 -3
  28. data/lib/aozora2html/tag/dir.rb +4 -2
  29. data/lib/aozora2html/tag/editor_note.rb +7 -4
  30. data/lib/aozora2html/tag/embed_gaiji.rb +15 -11
  31. data/lib/aozora2html/tag/font_size.rb +5 -2
  32. data/lib/aozora2html/tag/gaiji.rb +4 -3
  33. data/lib/aozora2html/tag/img.rb +4 -4
  34. data/lib/aozora2html/tag/indent.rb +3 -3
  35. data/lib/aozora2html/tag/inline.rb +10 -7
  36. data/lib/aozora2html/tag/inline_caption.rb +4 -2
  37. data/lib/aozora2html/tag/inline_font_size.rb +4 -3
  38. data/lib/aozora2html/tag/inline_keigakomi.rb +4 -2
  39. data/lib/aozora2html/tag/inline_yokogumi.rb +4 -3
  40. data/lib/aozora2html/tag/jisage.rb +3 -1
  41. data/lib/aozora2html/tag/jizume.rb +3 -0
  42. data/lib/aozora2html/tag/kaeriten.rb +4 -2
  43. data/lib/aozora2html/tag/keigakomi.rb +15 -9
  44. data/lib/aozora2html/tag/kunten.rb +4 -4
  45. data/lib/aozora2html/tag/midashi.rb +3 -1
  46. data/lib/aozora2html/tag/multiline.rb +3 -0
  47. data/lib/aozora2html/tag/multiline_caption.rb +6 -8
  48. data/lib/aozora2html/tag/multiline_chitsuki.rb +3 -1
  49. data/lib/aozora2html/tag/multiline_jisage.rb +3 -1
  50. data/lib/aozora2html/tag/multiline_midashi.rb +6 -3
  51. data/lib/aozora2html/tag/multiline_style.rb +5 -3
  52. data/lib/aozora2html/tag/multiline_yokogumi.rb +6 -9
  53. data/lib/aozora2html/tag/okurigana.rb +4 -2
  54. data/lib/aozora2html/tag/oneline_chitsuki.rb +3 -2
  55. data/lib/aozora2html/tag/oneline_indent.rb +8 -1
  56. data/lib/aozora2html/tag/oneline_jisage.rb +3 -0
  57. data/lib/aozora2html/tag/reference_mentioned.rb +22 -21
  58. data/lib/aozora2html/tag/ruby.rb +174 -70
  59. data/lib/aozora2html/tag/un_embed_gaiji.rb +8 -2
  60. data/lib/aozora2html/tag.rb +40 -38
  61. data/lib/aozora2html/tag_parser.rb +23 -16
  62. data/lib/aozora2html/text_buffer.rb +50 -0
  63. data/lib/aozora2html/utils.rb +113 -50
  64. data/lib/aozora2html/version.rb +3 -1
  65. data/lib/aozora2html/yaml_loader.rb +8 -2
  66. data/lib/aozora2html/zip.rb +4 -0
  67. data/lib/aozora2html.rb +1329 -3
  68. data/lib/extensions.rb +2 -34
  69. data/lib/jstream.rb +96 -25
  70. data/sample/chukiichiran_kinyurei.html +42 -29
  71. data/sample/chukiichiran_kinyurei.txt +16 -3
  72. metadata +80 -83
  73. data/.travis.yml +0 -12
  74. data/lib/t2hs.rb +0 -1607
  75. data/test/test_aozora2html.rb +0 -379
  76. data/test/test_aozora_accent_parser.rb +0 -31
  77. data/test/test_command_parse.rb +0 -213
  78. data/test/test_compat.rb +0 -11
  79. data/test/test_dakuten_katakana_tag.rb +0 -27
  80. data/test/test_decorate_tag.rb +0 -24
  81. data/test/test_dir_tag.rb +0 -24
  82. data/test/test_editor_note_tag.rb +0 -22
  83. data/test/test_exception.rb +0 -23
  84. data/test/test_font_size_tag.rb +0 -41
  85. data/test/test_gaiji_tag.rb +0 -49
  86. data/test/test_header.rb +0 -60
  87. data/test/test_helper.rb +0 -5
  88. data/test/test_i18n.rb +0 -23
  89. data/test/test_img_tag.rb +0 -23
  90. data/test/test_inline_caption_tag.rb +0 -24
  91. data/test/test_inline_font_size_tag.rb +0 -34
  92. data/test/test_inline_keigakomi_tag.rb +0 -24
  93. data/test/test_inline_yokogumi_tag.rb +0 -24
  94. data/test/test_jizume_tag.rb +0 -25
  95. data/test/test_jstream.rb +0 -57
  96. data/test/test_kaeriten_tag.rb +0 -24
  97. data/test/test_keigakomi_tag.rb +0 -31
  98. data/test/test_midashi_tag.rb +0 -38
  99. data/test/test_multiline_caption_tag.rb +0 -25
  100. data/test/test_multiline_midashi_tag.rb +0 -55
  101. data/test/test_multiline_style_tag.rb +0 -25
  102. data/test/test_multiline_yokogumi_tag.rb +0 -25
  103. data/test/test_okurigana_tag.rb +0 -24
  104. data/test/test_ruby_parse.rb +0 -130
  105. data/test/test_ruby_tag.rb +0 -24
  106. data/test/test_tag_parser.rb +0 -80
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 635bbe67e2511af4a4f8ccc8a820bdb87991d75d88fa9aa7ca9a90f2f67d7785
4
- data.tar.gz: ac7c5d1f77f0c4b89d24f93e6117107d3ee4ac5890aef5e082368f0fa7e8e318
3
+ metadata.gz: c5603337dda546fd478b05be81b81cb319feb015901766eb37d9aaf5a1787362
4
+ data.tar.gz: ea232f106d8c887b46752f09d23b3ba03ab642b0d2499d787c335f3e2ce5e702
5
5
  SHA512:
6
- metadata.gz: a939ef551dd506ae1f7ca4d608fbbe747aa7b4ada56a07fd83385c330fade541353d80f66fa8f4ed5d1342cd01d65af74c6c973ed2979c1dce12dcc7b10830a2
7
- data.tar.gz: 5c982a53cdffc60bad3c98406b74f640af4c1896fed6b42398a91025788962b4d2377950d40a0b25e4553fd92f94ac69c4ed8ac34fa21918cd0cb2148a1b0def
6
+ metadata.gz: 58b0f885285fc410914695223c6b938c826c745d1d9fad39d38c62dbed6813028eb7ee0e1ca2dbec81056563f221b7b02e420f5111eece65e4f6909a6a5d9965
7
+ data.tar.gz: 1adf2fb829035e60b9d649268062cbfcc4dd35914b0f552918355c03cfce0d68238548d27045bef04d2aca39fd2a5a442ad383614679856986c349f57811ebab
@@ -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,10 +18,13 @@ 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.2', '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
- - uses: actions/checkout@v1
27
+ - uses: actions/checkout@v4
25
28
  - name: Set up Ruby
26
29
  uses: ruby/setup-ruby@v1
27
30
  with:
@@ -29,6 +32,5 @@ jobs:
29
32
  - name: Build and test with Rake
30
33
  shell: bash
31
34
  run: |
32
- gem install bundler --no-document
33
35
  bundle install --jobs 4 --retry 3
34
36
  bundle exec rake
data/.gitignore CHANGED
@@ -5,5 +5,6 @@
5
5
  /.ruby-version
6
6
  /.yardoc/
7
7
  /Gemfile.lock
8
+ /coverage/
8
9
  /doc/
9
10
  /pkg/
data/.rubocop.yml CHANGED
@@ -1,175 +1,81 @@
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
9
+ AllCops:
10
+ TargetRubyVersion: 2.7
11
+ NewCops: enable
31
12
 
32
- # EnforcedStyle: space => 98 offenses
33
- # EnforcedStyle: no_space => 0 offense
34
- Layout/SpaceInsideStringInterpolation:
35
- EnforcedStyle: no_space
36
- Enabled: true
13
+ Gemspec/DevelopmentDependencies:
14
+ Enabled: false
37
15
 
38
- # EnforcedStyle: percent_q => 0 offense
39
- # EnforcedStyle: bare_percent => 30 offenses
40
16
  Style/BarePercentLiterals:
41
17
  EnforcedStyle: percent_q
42
- Enabled: true
43
18
 
44
- # EnforcedStyle: nested => 2 offenses
45
- # EnforcedStyle: compact => 81 offenses
46
- Style/ClassAndModuleChildren:
47
- EnforcedStyle: nested
48
- Enabled: true
19
+ Style/Documentation:
20
+ Exclude:
21
+ - 'test/**/*'
49
22
 
50
- # EnforcedStyle: compact => 24 offenses
51
- # EnforcedStyle: expanded => 0 offense
52
23
  Style/EmptyMethod:
53
24
  EnforcedStyle: expanded
54
25
  Enabled: true
55
26
 
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
27
+ Style/FormatString:
28
+ EnforcedStyle: sprintf
107
29
 
108
- Style/StringLiterals:
109
- Enabled: false
30
+ Style/FormatStringToken:
31
+ EnforcedStyle: unannotated
110
32
 
111
- Layout/SpaceAfterComma:
112
- Enabled: false
33
+ Style/FrozenStringLiteralComment:
34
+ Exclude:
35
+ - 'lib/aozora2html.rb'
113
36
 
114
- Layout/SpaceAroundOperators:
115
- Enabled: false
116
-
117
- Layout/SpaceInsideBlockBraces:
118
- Enabled: false
119
-
120
- Style/UnneededPercentQ:
37
+ Style/RedundantPercentQ:
121
38
  Enabled: false
122
39
 
123
40
  Style/PercentQLiterals:
124
41
  Enabled: false
125
42
 
126
- Style/SpecialGlobalVars:
127
- Enabled: false
128
-
129
- Style/Encoding:
130
- Enabled: false
131
-
132
43
  Style/ParallelAssignment:
133
44
  Enabled: false
134
45
 
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
46
  Style/AsciiComments:
151
47
  Enabled: false
152
48
 
153
49
  Style/LineEndConcatenation:
154
50
  Enabled: false
155
51
 
156
- Style/MethodCallWithoutArgsParentheses:
52
+ Style/IfUnlessModifier:
157
53
  Enabled: false
158
54
 
159
- Style/GlobalVars:
55
+ Style/NumericPredicate:
160
56
  Enabled: false
161
57
 
162
- Style/IfUnlessModifier:
58
+ Style/PerlBackrefs:
163
59
  Enabled: false
164
60
 
165
- Style/NumericPredicate:
61
+ Style/SpecialGlobalVars:
166
62
  Enabled: false
167
63
 
64
+ Style/SymbolArray:
65
+ EnforcedStyle: brackets
66
+
67
+ Style/WordArray:
68
+ EnforcedStyle: brackets
69
+
168
70
  Style/ZeroLengthPredicate:
169
71
  Enabled: false
170
72
 
171
- Layout/TrailingBlankLines:
172
- Enabled: false
73
+ Layout/LineLength:
74
+ Enabled: true
75
+ Max: 500
76
+
77
+ Lint/EmptyClass:
78
+ AllowComments: true
173
79
 
174
80
  Metrics/AbcSize:
175
81
  Enabled: true
@@ -191,17 +97,13 @@ Metrics/CyclomaticComplexity:
191
97
  Enabled: true
192
98
  Max: 100
193
99
 
194
- Metrics/LineLength:
195
- Enabled: true
196
- Max: 500
197
-
198
100
  Metrics/MethodLength:
199
101
  Enabled: true
200
102
  Max: 200
201
103
 
202
104
  Metrics/ModuleLength:
203
105
  Enabled: true
204
- Max: 100
106
+ Max: 200
205
107
 
206
108
  Metrics/ParameterLists:
207
109
  Enabled: true
@@ -210,18 +112,3 @@ Metrics/ParameterLists:
210
112
  Metrics/PerceivedComplexity:
211
113
  Enabled: true
212
114
  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,44 @@
1
+ <a name="3.0.1"></a>
2
+ ## 3.0.1
3
+
4
+ ### Bug Fixes
5
+
6
+ * いくつかマイナーな修正を行いました
7
+ * https://github.com/aozorahack/aozora2html/pull/100
8
+ * https://github.com/aozorahack/aozora2html/pull/101
9
+ * https://github.com/aozorahack/aozora2html/pull/103
10
+ * その他コードの挙動とは関係ない修正を行いました
11
+ * https://github.com/aozorahack/aozora2html/pull/98
12
+ * https://github.com/aozorahack/aozora2html/pull/102
13
+ * https://github.com/aozorahack/aozora2html/pull/105
14
+ * https://github.com/aozorahack/aozora2html/pull/108
15
+
16
+ <a name="3.0.0"></a>
17
+ ## 3.0.0
18
+
19
+ ### Breaking Changes
20
+
21
+ * Ruby 2.7未満をサポート対象外にしました。Ruby 3.0以降を推奨します。それ以前のRubyを使われる場合はv2.0.0をご利用ください https://github.com/aozorahack/aozora2html/pull/49
22
+ * t2hs.rbを廃止し、bin/aozora2html以外からは実行できなくしました https://github.com/aozorahack/aozora2html/pull/65 
23
+ * t2hs.rbにあったメソッドのうち、通常外部から使われないメソッドをprivateにしました https://github.com/aozorahack/aozora2html/pull/93
24
+
25
+ ### Bug Fixes
26
+
27
+ * 以前は全角空白であったところが半角空白になっていたので修正しました https://github.com/aozorahack/aozora2html/pull/62
28
+
29
+ ### Features
30
+
31
+ * エラーメッセージがUTF-8になる `--error-utf8` オプションを追加しました https://github.com/aozorahack/aozora2html/pull/72
32
+ * `sample/chukiichiran_kinyurei.txt`に他の例を追加しました https://github.com/aozorahack/aozora2html/pull/78
33
+ * `rake chuuki`で`sample/chukiichiran_kinyurei.txt`を`sample/chukiichiran_kinyurei.html`に変換できるrakeタスクを追加しました https://github.com/aozorahack/aozora2html/pull/95
34
+
35
+ <a name="2.0.0"></a>
36
+ ## 2.0.0
37
+
38
+ ### Bug Fixes
39
+
40
+ * Ruby 3.0でエラーになる挙動を修正しました https://github.com/aozorahack/aozora2html/pull/36, https://github.com/aozorahack/aozora2html/pull/41
41
+
1
42
  <a name="0.9.1"></a>
2
43
  ## 0.9.1
3
44
 
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"
20
- spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ spec.bindir = 'bin'
21
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
23
22
 
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"
23
+ spec.add_dependency 'rubyzip'
24
+ spec.add_development_dependency 'bundler'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rubocop'
27
+ spec.add_development_dependency 'rubocop-performance'
28
+ spec.add_development_dependency 'rubocop-rake'
29
+ spec.add_development_dependency 'simplecov'
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