narou 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of narou might be problematic. Click here for more details.
- data/ChangeLog.md +17 -1
- data/README.md +18 -12
- data/bin/narou +1 -1
- data/lib/color.rb +89 -0
- data/lib/command.rb +1 -1
- data/lib/command/alias.rb +5 -5
- data/lib/command/browser.rb +4 -2
- data/lib/command/convert.rb +14 -12
- data/lib/command/diff.rb +8 -8
- data/lib/command/download.rb +1 -1
- data/lib/command/folder.rb +2 -2
- data/lib/command/freeze.rb +1 -1
- data/lib/command/help.rb +8 -6
- data/lib/command/init.rb +8 -8
- data/lib/command/inspect.rb +2 -2
- data/lib/command/interactive.rb +1 -1
- data/lib/command/list.rb +5 -2
- data/lib/command/new.rb +1 -1
- data/lib/command/remove.rb +2 -2
- data/lib/command/send.rb +7 -7
- data/lib/command/setting.rb +8 -8
- data/lib/command/update.rb +2 -2
- data/lib/command/version.rb +1 -1
- data/lib/commandbase.rb +6 -4
- data/lib/commandline.rb +2 -2
- data/lib/converterbase.rb +81 -44
- data/lib/database.rb +1 -1
- data/lib/device.rb +3 -3
- data/lib/device/kindle.rb +1 -1
- data/lib/device/kobo.rb +1 -1
- data/lib/device/library/windows.rb +2 -14
- data/lib/downloader.rb +41 -14
- data/lib/extensions/windows.rb +58 -0
- data/lib/globalsetting.rb +1 -1
- data/lib/helper.rb +1 -1
- data/lib/illustration.rb +1 -1
- data/lib/ini.rb +1 -1
- data/lib/inspector.rb +2 -2
- data/lib/kindlestrip.rb +1 -1
- data/lib/loadconverter.rb +2 -2
- data/lib/localsetting.rb +1 -1
- data/lib/logger.rb +26 -9
- data/lib/narou.rb +1 -1
- data/lib/narou/api.rb +41 -0
- data/lib/novelconverter.rb +14 -14
- data/lib/novelsetting.rb +7 -2
- data/lib/progressbar.rb +1 -1
- data/lib/ruby.rb +1 -1
- data/lib/sitesetting.rb +1 -1
- data/lib/template.rb +3 -3
- data/lib/version.rb +2 -2
- data/narou.gemspec +3 -2
- data/narou.rb +5 -3
- data/template/converter.rb.erb +1 -1
- data/template/diff.txt.erb +1 -1
- data/template/novel.txt.erb +2 -1
- data/template/replace.txt.erb +2 -2
- data/template/setting.ini.erb +1 -1
- data/webnovel/ncode.syosetu.com.yaml +2 -1
- data/webnovel/novel18.syosetu.com.yaml +2 -1
- metadata +48 -19
- checksums.yaml +0 -7
data/lib/command/init.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# -*- coding:
|
1
|
+
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
4
|
#
|
@@ -65,19 +65,19 @@ module Command
|
|
65
65
|
if !force && @global_setting["aozoraepub3dir"]
|
66
66
|
return
|
67
67
|
end
|
68
|
-
puts "AozoraEpub3
|
69
|
-
puts "!!!WARNING!!!".center(70)
|
68
|
+
puts "<green>AozoraEpub3の設定を行います</green>".termcolor
|
69
|
+
puts ("<red>" + "!!!WARNING!!!".center(70) + "</red>").termcolor
|
70
70
|
puts "AozoraEpub3の構成ファイルを書き換えます。narouコマンド用に別途新規インストールしておくことをオススメします"
|
71
71
|
aozora_path = ask_aozoraepub3_path
|
72
72
|
unless aozora_path
|
73
|
-
puts "設定をスキップしました。あとで narou init で再度設定出来ます"
|
73
|
+
puts "設定をスキップしました。あとで " + "<yellow>narou init</yellow>".termcolor + " で再度設定出来ます"
|
74
74
|
return
|
75
75
|
end
|
76
76
|
puts
|
77
77
|
rewrite_aozoraepub3_files(aozora_path)
|
78
78
|
@global_setting["aozoraepub3dir"] = aozora_path
|
79
79
|
GlobalSetting.get.save_settings("global_setting")
|
80
|
-
puts "AozoraEpub3
|
80
|
+
puts "<green>AozoraEpub3の設定を終了しました</green>".termcolor
|
81
81
|
end
|
82
82
|
|
83
83
|
def rewrite_aozoraepub3_files(aozora_path)
|
@@ -111,11 +111,11 @@ module Command
|
|
111
111
|
|
112
112
|
def ask_aozoraepub3_path
|
113
113
|
puts
|
114
|
-
print "AozoraEpub3
|
114
|
+
print "<green>AozoraEpub3のあるフォルダを入力して下さい:</green>\n(未入力でスキップ".termcolor
|
115
115
|
if @global_setting["aozoraepub3dir"]
|
116
116
|
print "、:keep で前回と同じ設定"
|
117
117
|
end
|
118
|
-
print ")
|
118
|
+
print ")\n>"
|
119
119
|
while input = $stdin.gets.rstrip
|
120
120
|
path = File.expand_path(input)
|
121
121
|
case
|
@@ -129,7 +129,7 @@ module Command
|
|
129
129
|
when input == ""
|
130
130
|
break
|
131
131
|
end
|
132
|
-
print "\n
|
132
|
+
print "\n<green>入力されたフォルダにAozoraEpub3がありません。もう一度入力して下さい:</green>\n>".termcolor
|
133
133
|
end
|
134
134
|
nil
|
135
135
|
end
|
data/lib/command/inspect.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# -*- coding:
|
1
|
+
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
4
|
#
|
@@ -43,7 +43,7 @@ module Command
|
|
43
43
|
Helper.print_horizontal_rule if i > 0
|
44
44
|
data = Downloader.get_data_by_target(target)
|
45
45
|
unless data
|
46
|
-
|
46
|
+
error "#{target} は存在しません"
|
47
47
|
next
|
48
48
|
end
|
49
49
|
display_log(data["title"])
|
data/lib/command/interactive.rb
CHANGED
data/lib/command/list.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# -*- coding:
|
1
|
+
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
4
|
#
|
@@ -38,8 +38,11 @@ module Command
|
|
38
38
|
puts " ID | 更新日 | タイトル"
|
39
39
|
novels.each do |novel|
|
40
40
|
id = novel["id"]
|
41
|
+
frozen = Narou.novel_frozen?(id)
|
42
|
+
disp_id = ((frozen ? "*" : "") + id.to_s).rjust(4)
|
43
|
+
disp_id = disp_id.sub("*", "<blue>*</blue>").termcolor if frozen
|
41
44
|
puts [
|
42
|
-
|
45
|
+
disp_id,
|
43
46
|
novel["last_update"].strftime("%y/%m/%d"),
|
44
47
|
novel["title"],
|
45
48
|
@options["url"] ? novel["toc_url"] : nil
|
data/lib/command/new.rb
CHANGED
data/lib/command/remove.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# -*- coding:
|
1
|
+
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
4
|
#
|
@@ -45,7 +45,7 @@ module Command
|
|
45
45
|
Helper.print_horizontal_rule if i > 0
|
46
46
|
data = Downloader.get_data_by_target(target)
|
47
47
|
unless data
|
48
|
-
|
48
|
+
error "#{target} は存在しません"
|
49
49
|
next
|
50
50
|
end
|
51
51
|
title = data["title"]
|
data/lib/command/send.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# -*- coding:
|
1
|
+
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
4
|
#
|
@@ -45,26 +45,26 @@ module Command
|
|
45
45
|
return
|
46
46
|
end
|
47
47
|
unless Helper.os_windows?
|
48
|
-
|
48
|
+
error "このコマンドはWindows専用です"
|
49
49
|
exit 1
|
50
50
|
end
|
51
51
|
device = get_device(argv)
|
52
52
|
unless device
|
53
|
-
|
53
|
+
error "デバイス名を指定して下さい"
|
54
54
|
exit 1
|
55
55
|
end
|
56
56
|
unless device.connecting?
|
57
|
-
|
57
|
+
error "#{device.name}が接続されていません"
|
58
58
|
exit 1
|
59
59
|
end
|
60
60
|
argv.each do |target|
|
61
61
|
ebook_path = Narou.get_ebook_file_path(target, device.ebook_file_ext)
|
62
62
|
unless ebook_path
|
63
|
-
|
63
|
+
error "#{target} は存在しません"
|
64
64
|
next
|
65
65
|
end
|
66
66
|
unless File.exists?(ebook_path)
|
67
|
-
|
67
|
+
error "まだファイル(#{File.basename(ebook_path)})が無いようです"
|
68
68
|
next
|
69
69
|
end
|
70
70
|
print "#{device.name}へ送信しています"
|
@@ -82,7 +82,7 @@ module Command
|
|
82
82
|
if copy_to_path
|
83
83
|
puts copy_to_path + " へコピーしました"
|
84
84
|
else
|
85
|
-
|
85
|
+
error "#{device.name}が見つからなかったためコピー出来ませんでした"
|
86
86
|
exit 1 # next しても次も失敗すると分かりきっているためここで終了する
|
87
87
|
end
|
88
88
|
end
|
data/lib/command/setting.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
# -*- coding:
|
1
|
+
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright 2013 whiteleaf. All rights reserved.
|
4
3
|
#
|
5
4
|
|
6
5
|
require_relative "../localsetting"
|
@@ -154,7 +153,7 @@ module Command
|
|
154
153
|
if value =~ / /
|
155
154
|
value = "'#{value}'"
|
156
155
|
end
|
157
|
-
puts "
|
156
|
+
puts "<green>#{name}</green>=#{value}".termcolor
|
158
157
|
end
|
159
158
|
end
|
160
159
|
end
|
@@ -172,16 +171,16 @@ module Command
|
|
172
171
|
argv.each do |arg|
|
173
172
|
name, value = arg.split("=", 2).map(&:strip)
|
174
173
|
if name == ""
|
175
|
-
|
174
|
+
error "書式が間違っています。変数名=値 のように書いて下さい"
|
176
175
|
next
|
177
176
|
end
|
178
177
|
scope = get_scope_of_variable_name(name)
|
179
178
|
unless scope
|
180
|
-
|
179
|
+
error "#{name} という変数は存在しません"
|
181
180
|
next
|
182
181
|
end
|
183
182
|
if value.nil?
|
184
|
-
|
183
|
+
error "書式が間違っています。#{name}=値 のように書いて下さい"
|
185
184
|
next
|
186
185
|
end
|
187
186
|
if value == ""
|
@@ -192,7 +191,7 @@ module Command
|
|
192
191
|
begin
|
193
192
|
scope, casted_value = casting_variable(name, value)
|
194
193
|
rescue InvalidVariableName, InvalidVariableType => e
|
195
|
-
|
194
|
+
error e.message
|
196
195
|
next
|
197
196
|
end
|
198
197
|
settings[scope][name] = casted_value
|
@@ -207,7 +206,7 @@ module Command
|
|
207
206
|
SETTING_VARIABLES[scope].each do |name, info|
|
208
207
|
if @options["all"] || info[2] != INVISIBLE
|
209
208
|
type_description = self.class.variable_type_to_description(info[0])
|
210
|
-
result << "
|
209
|
+
result << " <green>#{name.ljust(18)}</green> #{type_description} #{info[1]}\n".termcolor
|
211
210
|
end
|
212
211
|
end
|
213
212
|
result
|
@@ -246,6 +245,7 @@ module Command
|
|
246
245
|
"aozoraepub3dir" => [:directory, "AozoraEpub3のあるフォルダを指定", INVISIBLE],
|
247
246
|
"difftool" => [:string, "Diffで使うツールのパスを指定する"],
|
248
247
|
"difftool.arg" => [:string, "difftoolで使う引数を設定(オプション)"],
|
248
|
+
"no-color" => [:boolean, "表示内容に色を付けない"],
|
249
249
|
"over18" => [:boolean, "", INVISIBLE],
|
250
250
|
}
|
251
251
|
}
|
data/lib/command/update.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# -*- coding:
|
1
|
+
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
4
|
#
|
@@ -46,7 +46,7 @@ module Command
|
|
46
46
|
display_message = nil
|
47
47
|
data = Downloader.get_data_by_target(target)
|
48
48
|
if !data
|
49
|
-
display_message = "#{target} は管理小説の中に存在しません"
|
49
|
+
display_message = "<red>[ERROR]</red> #{target} は管理小説の中に存在しません".termcolor
|
50
50
|
elsif Narou.novel_frozen?(target)
|
51
51
|
if argv.length > 0
|
52
52
|
display_message = "#{data["title"]} は凍結中です"
|
data/lib/command/version.rb
CHANGED
data/lib/commandbase.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# -*- coding:
|
1
|
+
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
4
|
#
|
@@ -9,17 +9,19 @@ module Command
|
|
9
9
|
class CommandBase
|
10
10
|
def initialize(postfix = "")
|
11
11
|
@opt = OptionParser.new(nil, 20)
|
12
|
-
@opt.banner = "
|
12
|
+
@opt.banner = ("<green>" +
|
13
|
+
TermColor.escape("Usage: narou #{self.class.to_s.scan(/::(.+)$/)[0][0].downcase} #{postfix}") +
|
14
|
+
"</green>").termcolor
|
13
15
|
@options = {}
|
14
16
|
end
|
15
17
|
|
16
18
|
def execute(argv)
|
17
19
|
@opt.parse!(argv)
|
18
20
|
rescue OptionParser::InvalidOption => e
|
19
|
-
|
21
|
+
error "不正なオプションです(#{e})"
|
20
22
|
exit 1
|
21
23
|
rescue OptionParser::MissingArgument => e
|
22
|
-
|
24
|
+
error "オプションの引数が不正です(#{e})"
|
23
25
|
exit 1
|
24
26
|
end
|
25
27
|
|
data/lib/commandline.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# -*- coding:
|
1
|
+
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
4
|
#
|
@@ -25,7 +25,7 @@ module CommandLine
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
unless Command.get_list.include?(arg)
|
28
|
-
|
28
|
+
error "不明なコマンドです"
|
29
29
|
puts
|
30
30
|
arg = "help"
|
31
31
|
end
|
data/lib/converterbase.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# -*- coding:
|
1
|
+
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
4
|
#
|
@@ -245,9 +245,11 @@ class ConverterBase
|
|
245
245
|
# 記号を全角に変換
|
246
246
|
#
|
247
247
|
def symbols_to_zenkaku(data)
|
248
|
-
data.tr!("
|
249
|
-
data.gsub!(/"([^"]+)"/, "
|
250
|
-
data.gsub!(/'([^']+)'/, "
|
248
|
+
data.tr!("“”‘’〝〟", %!""''""!)
|
249
|
+
data.gsub!(/"([^"]+)"/, "〝\\1〟")
|
250
|
+
data.gsub!(/'([^']+)'/, "〝\\1〟") # MEMO: シングルミュート(ノノカギ)を表示出来るフォントはほとんど無い
|
251
|
+
data.gsub!("≪", "※[#始め二重山括弧]")
|
252
|
+
data.gsub!("≫", "※[#終わり二重山括弧]")
|
251
253
|
data.tr!("-=+/*《》'\"%$#&!?、<><>()|‐,._;:",
|
252
254
|
"-=+/*≪≫’”%$#&!?、〈〉〈〉()|-,._;:")
|
253
255
|
data.gsub!("\\", "¥")
|
@@ -269,6 +271,9 @@ class ConverterBase
|
|
269
271
|
# 見出しの中では自動で縦中横にはならないため、明示的指定をしておく
|
270
272
|
# 事前に !? は全角にしておく
|
271
273
|
data.gsub!(/!+/) do |match|
|
274
|
+
if "#{$`[-1]}#{$'[0]}".include?("?")
|
275
|
+
next match
|
276
|
+
end
|
272
277
|
len = match.length
|
273
278
|
if len == 3
|
274
279
|
tcy("!!!")
|
@@ -281,9 +286,16 @@ class ConverterBase
|
|
281
286
|
end
|
282
287
|
end
|
283
288
|
data.gsub!(/[!?]+/) do |match|
|
284
|
-
|
285
|
-
|
289
|
+
case match.length
|
290
|
+
when 2
|
286
291
|
tcy(match.tr("!?", "!?"))
|
292
|
+
when 3
|
293
|
+
# 見た目的にこのパターンだけ縦中横化を許容する
|
294
|
+
if %w(!!? ?!!).find { |v| v == match }
|
295
|
+
tcy(match.tr("!?", "!?"))
|
296
|
+
else
|
297
|
+
match
|
298
|
+
end
|
287
299
|
else
|
288
300
|
match
|
289
301
|
end
|
@@ -312,7 +324,7 @@ class ConverterBase
|
|
312
324
|
data.gsub!(/。([」』)])/, "\\1")
|
313
325
|
# 原則偶数個を1セットで使うべき文字を偶数個に補正
|
314
326
|
# MEMO:(―も偶数個セットにするべきだが、記号的な意味で使われる場合もあるので無視)
|
315
|
-
%w(
|
327
|
+
%w(…‥).each do |target|
|
316
328
|
data.gsub!(/#{target}+/) do |match|
|
317
329
|
len = match.length
|
318
330
|
len += 1 if len.odd?
|
@@ -320,6 +332,9 @@ class ConverterBase
|
|
320
332
|
end
|
321
333
|
end
|
322
334
|
# たまに見かける誤字対策
|
335
|
+
# MEMO: 。。。 検索結果:355作品
|
336
|
+
# 、、、 検索結果:171作品
|
337
|
+
# 上記の三点リーダー的使い方は考慮しない
|
323
338
|
data.gsub!(/。+/, "。")
|
324
339
|
data.gsub!(/、+/, "、")
|
325
340
|
data.gsub!(/。 /, "。")
|
@@ -645,11 +660,6 @@ class ConverterBase
|
|
645
660
|
#
|
646
661
|
# 小説家になろうのルビ対策
|
647
662
|
#
|
648
|
-
# TODO:
|
649
|
-
# 既知の問題―同一行にルビ開始文字でない|と、ルビ開始用|が同時に存在するとき、
|
650
|
-
# ルビ開始文字でない|が[#縦線]に置換されない
|
651
|
-
# →存在するかも疑わしいパターンなため、仕様とする
|
652
|
-
#
|
653
663
|
def narou_ruby(data)
|
654
664
|
# 《》なルビの対処
|
655
665
|
last_i = 0
|
@@ -657,23 +667,23 @@ class ConverterBase
|
|
657
667
|
data.gsub!(/(.+?)≪(.+?)≫/).with_index do |match, i|
|
658
668
|
ruby_str = to_ruby(match, $1, $2, ["≪", "≫"])
|
659
669
|
last_i = i
|
660
|
-
|
661
|
-
"[#ルビ=#{i}]"
|
670
|
+
ruby_str
|
662
671
|
end
|
663
672
|
# ()なルビの対処
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
673
|
+
if @text_type != "subtitle"
|
674
|
+
data.gsub!(/(.+?)(([ぁ-んァ-ヴーゞ・A-Za-zA-Za-z ]{,20}))/).with_index(last_i + 1) do |match, i|
|
675
|
+
ruby_str = to_ruby(match, $1, $2, ["(", ")"])
|
676
|
+
ruby_str
|
677
|
+
end
|
668
678
|
end
|
669
679
|
data.replace(replace_tatesen(data))
|
670
|
-
data.gsub!(
|
671
|
-
ruby_stack[$1.to_i]
|
672
|
-
end
|
680
|
+
data.gsub!("[#ルビ用縦線]", "|")
|
673
681
|
end
|
674
682
|
|
683
|
+
CHARACTER_OF_RUBY = "一-龠A-Za-zA-Za-z"
|
684
|
+
|
675
685
|
def object_of_ruby?(char)
|
676
|
-
char =~ /[
|
686
|
+
char =~ /[#{CHARACTER_OF_RUBY}]/
|
677
687
|
end
|
678
688
|
|
679
689
|
def sesame(str, ten)
|
@@ -697,10 +707,19 @@ class ConverterBase
|
|
697
707
|
when m2 =~ /^・+$/
|
698
708
|
# ルビが・だけの場合、傍点と判断
|
699
709
|
sesame(m1, m2)
|
700
|
-
when m1.include?("|")
|
701
|
-
"#{m1}《#{m2}》"
|
710
|
+
when m1.include?("|")
|
711
|
+
"#{m1.sub(/|([^|]*)$/, "[#ルビ用縦線]\\1")}《#{m2}》"
|
712
|
+
when object_of_ruby?(last_char)
|
713
|
+
# なろうのルビ対象文字を辿って|を挿入する(青空文庫となろうのルビ仕様の差異吸収のため)
|
714
|
+
m1.gsub(/([#{CHARACTER_OF_RUBY} ]+)$/) {
|
715
|
+
if $1[0] == " "
|
716
|
+
" [#ルビ用縦線]#{$1[1..-1]}"
|
717
|
+
else
|
718
|
+
"[#ルビ用縦線]#{$1}"
|
719
|
+
end
|
720
|
+
} + "《#{m2}》"
|
702
721
|
else
|
703
|
-
|
722
|
+
match
|
704
723
|
end
|
705
724
|
end
|
706
725
|
|
@@ -751,6 +770,21 @@ class ConverterBase
|
|
751
770
|
end
|
752
771
|
end
|
753
772
|
|
773
|
+
#
|
774
|
+
# 中黒(・)を並べて三点リーダーもどきにしているのを三点リーダーに変換
|
775
|
+
#
|
776
|
+
def convert_horizontal_ellipsis(data)
|
777
|
+
return if !@setting.enable_convert_horizontal_ellipsis || @text_type == "subtitle"
|
778
|
+
data.gsub!(/・{3,}/) do |match|
|
779
|
+
pre_char, post_char = $`[-1], $'[0]
|
780
|
+
if pre_char == "―" || post_char == "―"
|
781
|
+
match
|
782
|
+
else
|
783
|
+
"…" * ((match.length / 3.0 / 2).ceil * 2)
|
784
|
+
end
|
785
|
+
end
|
786
|
+
end
|
787
|
+
|
754
788
|
#
|
755
789
|
# [#改ページ]直後の行を見出しに設定する
|
756
790
|
#
|
@@ -810,7 +844,7 @@ class ConverterBase
|
|
810
844
|
#
|
811
845
|
# 小説データ全体に対して施す変換
|
812
846
|
#
|
813
|
-
def convert_for_all_data(data
|
847
|
+
def convert_for_all_data(data)
|
814
848
|
auto_join_in_brackets(data)
|
815
849
|
auto_join_line(data) if @setting.enable_auto_join_line
|
816
850
|
erase_comments_block(data)
|
@@ -827,44 +861,45 @@ class ConverterBase
|
|
827
861
|
insert_separate_space(data)
|
828
862
|
convert_special_characters(data)
|
829
863
|
convert_fraction_and_date(data)
|
830
|
-
if text_type == "body" || text_type == "textfile"
|
864
|
+
if @text_type == "body" || @text_type == "textfile"
|
831
865
|
half_indent_bracket(data)
|
832
866
|
auto_indent(data)
|
833
867
|
end
|
834
868
|
convert_dakuten_char_to_font(data)
|
835
869
|
end
|
836
870
|
|
837
|
-
def before_convert(io
|
838
|
-
before(io, text_type)
|
871
|
+
def before_convert(io)
|
872
|
+
before(io, @text_type)
|
839
873
|
end
|
840
874
|
|
841
|
-
def after_convert(io
|
842
|
-
after(io, text_type)
|
875
|
+
def after_convert(io)
|
876
|
+
after(io, @text_type)
|
843
877
|
end
|
844
878
|
|
845
879
|
def convert(text, text_type)
|
846
880
|
return "" if text == ""
|
881
|
+
@text_type = text_type
|
847
882
|
io = StringIO.new(rstrip_all_lines(text))
|
848
|
-
(io = before_convert(io
|
849
|
-
(io = convert_main(io
|
850
|
-
(io = after_convert(io
|
883
|
+
(io = before_convert(io)).rewind
|
884
|
+
(io = convert_main(io)).rewind
|
885
|
+
(io = after_convert(io)).rewind
|
851
886
|
return io.read
|
852
887
|
end
|
853
888
|
|
854
889
|
#
|
855
890
|
# 変換処理本体
|
856
891
|
#
|
857
|
-
# text_type: 渡されるテキストの種類。subtitle, introduction, body, postscript, textfile のどれか
|
892
|
+
# @text_type: 渡されるテキストの種類。subtitle, introduction, body, postscript, textfile のどれか
|
858
893
|
#
|
859
|
-
def convert_main(io
|
894
|
+
def convert_main(io)
|
860
895
|
@write_fp = StringIO.new
|
861
|
-
case text_type
|
896
|
+
case @text_type
|
862
897
|
when "introduction"
|
863
898
|
return @write_fp if @setting.enable_erase_introduction
|
864
899
|
when "postscript"
|
865
900
|
return @write_fp if @setting.enable_erase_postscript
|
866
901
|
end
|
867
|
-
if text_type == "textfile"
|
902
|
+
if @text_type == "textfile"
|
868
903
|
@write_fp.puts(io.gets + io.gets) # タイトル・著者名スキップ
|
869
904
|
data = io.read
|
870
905
|
progressbar = ProgressBar.new(data.count("\n") + 1)
|
@@ -873,17 +908,17 @@ class ConverterBase
|
|
873
908
|
data = io.read
|
874
909
|
end
|
875
910
|
initialize_member_values
|
876
|
-
convert_for_all_data(data
|
911
|
+
convert_for_all_data(data)
|
877
912
|
@read_fp = StringIO.new(data)
|
878
913
|
@read_fp.each_with_index do |line, i|
|
879
|
-
progressbar.output(i) if text_type == "textfile"
|
914
|
+
progressbar.output(i) if @text_type == "textfile"
|
880
915
|
@request_skip_output_line = false
|
881
916
|
zenkaku_rstrip(line)
|
882
917
|
if @request_insert_blank_next_line
|
883
918
|
outputs unless blank_line?(line)
|
884
919
|
@request_insert_blank_next_line = false
|
885
920
|
end
|
886
|
-
process_author_comment(line) if text_type == "textfile"
|
921
|
+
process_author_comment(line) if @text_type == "textfile"
|
887
922
|
insert_blank_line_to_border_symbol(line)
|
888
923
|
force_indent_special_chapter(line)
|
889
924
|
|
@@ -896,11 +931,11 @@ class ConverterBase
|
|
896
931
|
@before_line = line
|
897
932
|
end
|
898
933
|
end
|
899
|
-
author_comment_force_close if text_type == "textfile"
|
934
|
+
author_comment_force_close if @text_type == "textfile"
|
900
935
|
|
901
936
|
@write_fp.rewind
|
902
937
|
data = @write_fp.string
|
903
|
-
if text_type == "textfile"
|
938
|
+
if @text_type == "textfile"
|
904
939
|
if @setting.enable_author_comments
|
905
940
|
erase_introduction(data) if @setting.enable_erase_introduction
|
906
941
|
erase_postscript(data) if @setting.enable_erase_postscript
|
@@ -915,8 +950,10 @@ class ConverterBase
|
|
915
950
|
# rebuild_english_sentences で再構築された英文にルビがふられる可能性を考慮して、
|
916
951
|
# この位置でルビの処理を行う
|
917
952
|
narou_ruby(data) if @setting.enable_ruby
|
953
|
+
# 三点リーダーの変換は、ルビで圏点として・・・を使っている場合を考慮して、ルビ処理後にする
|
954
|
+
convert_horizontal_ellipsis(data)
|
918
955
|
data.strip!
|
919
|
-
progressbar.clear if text_type == "textfile"
|
956
|
+
progressbar.clear if @text_type == "textfile"
|
920
957
|
@write_fp
|
921
958
|
end
|
922
959
|
|