review 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +43 -1
- data/.rubocop_todo.yml +605 -0
- data/.travis.yml +9 -0
- data/ChangeLog +4 -0
- data/Dockerfile +22 -0
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/bin/review-check +8 -21
- data/bin/review-compile +9 -15
- data/bin/review-epubmaker-legacy +6 -6
- data/bin/review-index +2 -13
- data/bin/review-preproc +1 -14
- data/bin/review-validate +1 -1
- data/bin/review-vol +1 -13
- data/doc/NEWS.ja.md +22 -0
- data/doc/NEWS.md +22 -0
- data/doc/quickstart.ja.md +1 -1
- data/doc/quickstart.md +1 -1
- data/lib/epubmaker/content.rb +3 -3
- data/lib/epubmaker/epubcommon.rb +91 -108
- data/lib/epubmaker/epubv2.rb +14 -67
- data/lib/epubmaker/epubv3.rb +25 -59
- data/lib/epubmaker/producer.rb +12 -0
- data/lib/review/book/base.rb +12 -4
- data/lib/review/book/compilable.rb +1 -3
- data/lib/review/book/index.rb +4 -4
- data/lib/review/builder.rb +6 -11
- data/lib/review/compiler.rb +7 -7
- data/lib/review/configure.rb +20 -8
- data/lib/review/epubbuilder.rb +1 -1
- data/lib/review/epubmaker.rb +52 -122
- data/lib/review/ewbbuilder.rb +4 -4
- data/lib/review/exception.rb +1 -1
- data/lib/review/htmlbuilder.rb +49 -54
- data/lib/review/htmltoc.rb +45 -0
- data/lib/review/htmlutils.rb +3 -3
- data/lib/review/i18n.rb +6 -2
- data/lib/review/i18n.yml +1 -1
- data/lib/review/idgxmlbuilder.rb +4 -5
- data/lib/review/inaobuilder.rb +1 -1
- data/lib/review/latexbuilder.rb +2 -2
- data/lib/review/latexutils.rb +6 -6
- data/lib/review/markdownbuilder.rb +4 -3
- data/lib/review/pdfmaker.rb +92 -92
- data/lib/review/preprocessor.rb +14 -51
- data/lib/review/template.rb +21 -0
- data/lib/review/textbuilder.rb +1 -1
- data/lib/review/textutils.rb +0 -28
- data/lib/review/tocparser.rb +3 -3
- data/lib/review/tocprinter.rb +8 -31
- data/lib/review/topbuilder.rb +2 -3
- data/lib/review/unfold.rb +2 -2
- data/lib/review/version.rb +1 -1
- data/review.gemspec +2 -1
- data/templates/html/layout-html5.html.erb +17 -0
- data/templates/html/layout-xhtml1.html.erb +20 -0
- data/templates/ncx/epubv2.ncx.erb +11 -0
- data/templates/opf/epubv2.opf.erb +21 -0
- data/templates/opf/epubv3.opf.erb +18 -0
- data/templates/xml/container.xml.erb +6 -0
- data/test/assets/test.xml.erb +3 -0
- data/test/test.re +1 -1
- data/test/test_book.rb +4 -4
- data/test/test_book_chapter.rb +0 -76
- data/test/test_book_part.rb +1 -1
- data/test/test_builder.rb +0 -49
- data/test/test_configure.rb +50 -0
- data/test/test_htmlbuilder.rb +54 -4
- data/test/test_htmltoc.rb +32 -0
- data/test/test_i18n.rb +3 -5
- data/test/test_idgxmlbuilder.rb +0 -2
- data/test/test_inaobuilder.rb +2 -4
- data/test/test_latexbuilder.rb +2 -4
- data/test/test_lineinput.rb +0 -18
- data/test/test_markdownbuilder.rb +5 -4
- data/test/test_pdfmaker.rb +11 -10
- data/test/test_template.rb +26 -0
- data/test/test_topbuilder.rb +0 -2
- metadata +35 -4
- data/rubocop-todo.yml +0 -456
data/lib/review/ewbbuilder.rb
CHANGED
@@ -62,7 +62,7 @@ module ReVIEW
|
|
62
62
|
lines.each do |line|
|
63
63
|
if noescape
|
64
64
|
puts detab(line)
|
65
|
-
elsif /\AC:.*?>(.+)/ =~ line
|
65
|
+
elsif /\AC:.*?>(.+)/ =~ line # DOS prompt hack
|
66
66
|
prompt, cmd = *line.split('>', 2)
|
67
67
|
puts "#{escape(prompt)}>//command{#{escape(cmd)}}//}"
|
68
68
|
else
|
@@ -198,7 +198,7 @@ module ReVIEW
|
|
198
198
|
# FIXME
|
199
199
|
end
|
200
200
|
|
201
|
-
Z_SPACE = "\241\241"
|
201
|
+
Z_SPACE = "\241\241" # zen-kaku space in EUC-JP
|
202
202
|
|
203
203
|
def paragraph(lines)
|
204
204
|
if @noindent
|
@@ -263,10 +263,10 @@ module ReVIEW
|
|
263
263
|
if abbr
|
264
264
|
add_index(word) + "//g{#{word}//}" +
|
265
265
|
add_index(abbr) + "(#{abbr}, " +
|
266
|
-
add_index(eng)
|
266
|
+
add_index(eng) + "#{eng})"
|
267
267
|
elsif eng
|
268
268
|
add_index(word) + "//g{#{word}//}" +
|
269
|
-
add_index(eng)
|
269
|
+
add_index(eng) + "(#{eng})"
|
270
270
|
else
|
271
271
|
add_index(word) + "//g{#{word}//}"
|
272
272
|
end
|
data/lib/review/exception.rb
CHANGED
data/lib/review/htmlbuilder.rb
CHANGED
@@ -70,7 +70,7 @@ module ReVIEW
|
|
70
70
|
if ENV["REVIEW_SAFE_MODE"].to_i & 4 > 0
|
71
71
|
warn "user's layout is prohibited in safe mode. ignored."
|
72
72
|
else
|
73
|
-
title =
|
73
|
+
title = strip_html(compile_inline(@chapter.title))
|
74
74
|
|
75
75
|
toc = ""
|
76
76
|
toc_level = 0
|
@@ -101,44 +101,21 @@ module ReVIEW
|
|
101
101
|
end
|
102
102
|
|
103
103
|
# default XHTML header/footer
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
EOT
|
104
|
+
@error_messages = error_messages
|
105
|
+
@warning_messages = warning_messages
|
106
|
+
@title = strip_html(compile_inline(@chapter.title))
|
107
|
+
@body = @output.string
|
108
|
+
@language = @book.config['language']
|
109
|
+
@stylesheets = @book.config["stylesheet"]
|
110
|
+
|
111
|
+
if @book.htmlversion == 5
|
112
|
+
htmlfilename = "layout-html5.html.erb"
|
114
113
|
else
|
115
|
-
|
116
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
117
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="#{@book.config["language"]}">
|
118
|
-
<head>
|
119
|
-
<meta http-equiv="Content-Type" content="text/html;charset=#{@book.config["outencoding"] || "UTF-8"}" />
|
120
|
-
<meta http-equiv="Content-Style-Type" content="text/css" />
|
121
|
-
EOT
|
122
|
-
end
|
123
|
-
|
124
|
-
unless @book.config["stylesheet"].nil?
|
125
|
-
@book.config["stylesheet"].each do |style|
|
126
|
-
header += <<EOT
|
127
|
-
<link rel="stylesheet" type="text/css" href="#{style}" />
|
128
|
-
EOT
|
129
|
-
end
|
114
|
+
htmlfilename = "layout-xhtml1.html.erb"
|
130
115
|
end
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
</head>
|
135
|
-
<body>
|
136
|
-
EOT
|
137
|
-
footer = <<EOT
|
138
|
-
</body>
|
139
|
-
</html>
|
140
|
-
EOT
|
141
|
-
header + messages() + convert_outencoding(@output.string, @book.config["outencoding"]) + footer
|
116
|
+
tmplfile = File.expand_path('./html/'+htmlfilename, ReVIEW::Template::TEMPLATE_DIR)
|
117
|
+
tmpl = ReVIEW::Template.load(tmplfile)
|
118
|
+
tmpl.result(binding)
|
142
119
|
end
|
143
120
|
|
144
121
|
def xmlns_ops_prefix
|
@@ -177,7 +154,7 @@ EOT
|
|
177
154
|
"<ul>\n" +
|
178
155
|
@errors.map {|file, line, msg|
|
179
156
|
"<li>#{escape_html(file)}:#{line}: #{escape_html(msg.to_s)}</li>\n"
|
180
|
-
|
157
|
+
}.join('') +
|
181
158
|
"</ul>\n"
|
182
159
|
end
|
183
160
|
|
@@ -373,7 +350,7 @@ EOT
|
|
373
350
|
|
374
351
|
def ol_begin
|
375
352
|
if @ol_num
|
376
|
-
puts "<ol start=\"#{@ol_num}\">"
|
353
|
+
puts "<ol start=\"#{@ol_num}\">" ## it's OK in HTML5, but not OK in XHTML1.1
|
377
354
|
@ol_num = nil
|
378
355
|
else
|
379
356
|
puts '<ol>'
|
@@ -490,10 +467,18 @@ EOT
|
|
490
467
|
end
|
491
468
|
|
492
469
|
def listnum_body(lines, lang)
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
470
|
+
if highlight?
|
471
|
+
body = lines.inject(''){|i, j| i + detab(j) + "\n"}
|
472
|
+
lexer = lang
|
473
|
+
puts highlight(:body => body, :lexer => lexer, :format => 'html',
|
474
|
+
:options => {:linenos => 'inline', :nowrap => false})
|
475
|
+
else
|
476
|
+
print '<pre class="list">'
|
477
|
+
lines.each_with_index do |line, i|
|
478
|
+
puts detab((i+1).to_s.rjust(2) + ": " + line)
|
479
|
+
end
|
480
|
+
puts '</pre>'
|
481
|
+
end
|
497
482
|
end
|
498
483
|
|
499
484
|
def emlist(lines, caption = nil, lang = nil)
|
@@ -514,10 +499,20 @@ EOT
|
|
514
499
|
if caption.present?
|
515
500
|
puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
|
516
501
|
end
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
502
|
+
|
503
|
+
if highlight?
|
504
|
+
body = lines.inject(''){|i, j| i + detab(j) + "\n"}
|
505
|
+
lexer = lang
|
506
|
+
puts highlight(:body => body, :lexer => lexer, :format => 'html',
|
507
|
+
:options => {:linenos => 'inline', :nowrap => false})
|
508
|
+
else
|
509
|
+
print '<pre class="emlist">'
|
510
|
+
lines.each_with_index do |line, i|
|
511
|
+
puts detab((i+1).to_s.rjust(2) + ": " + line)
|
512
|
+
end
|
513
|
+
puts '</pre>'
|
514
|
+
end
|
515
|
+
|
521
516
|
puts '</div>'
|
522
517
|
end
|
523
518
|
|
@@ -830,7 +825,7 @@ QUOTE
|
|
830
825
|
end
|
831
826
|
|
832
827
|
def compile_ruby(base, ruby)
|
833
|
-
if @book.
|
828
|
+
if @book.htmlversion == 5
|
834
829
|
%Q[<ruby>#{escape_html(base)}<rp>#{I18n.t("ruby_prefix")}</rp><rt>#{escape_html(ruby)}</rt><rp>#{I18n.t("ruby_postfix")}</rp></ruby>]
|
835
830
|
else
|
836
831
|
%Q[<ruby><rb>#{escape_html(base)}</rb><rp>#{I18n.t("ruby_prefix")}</rp><rt>#{ruby}</rt><rp>#{I18n.t("ruby_postfix")}</rp></ruby>]
|
@@ -863,7 +858,7 @@ QUOTE
|
|
863
858
|
end
|
864
859
|
|
865
860
|
def inline_tti(str)
|
866
|
-
if @book.
|
861
|
+
if @book.htmlversion == 5
|
867
862
|
%Q(<code class="tt"><i>#{escape_html(str)}</i></code>)
|
868
863
|
else
|
869
864
|
%Q(<tt><i>#{escape_html(str)}</i></tt>)
|
@@ -871,7 +866,7 @@ QUOTE
|
|
871
866
|
end
|
872
867
|
|
873
868
|
def inline_ttb(str)
|
874
|
-
if @book.
|
869
|
+
if @book.htmlversion == 5
|
875
870
|
%Q(<code class="tt"><b>#{escape_html(str)}</b></code>)
|
876
871
|
else
|
877
872
|
%Q(<tt><b>#{escape_html(str)}</b></tt>)
|
@@ -883,7 +878,7 @@ QUOTE
|
|
883
878
|
end
|
884
879
|
|
885
880
|
def inline_code(str)
|
886
|
-
if @book.
|
881
|
+
if @book.htmlversion == 5
|
887
882
|
%Q(<code class="inline-code tt">#{escape_html(str)}</code>)
|
888
883
|
else
|
889
884
|
%Q(<tt class="inline-code">#{escape_html(str)}</tt>)
|
@@ -939,7 +934,7 @@ QUOTE
|
|
939
934
|
end
|
940
935
|
|
941
936
|
def inline_bib(id)
|
942
|
-
%Q(<a href="#{@book.bib_file.gsub(
|
937
|
+
%Q(<a href="#{@book.bib_file.gsub(/\.re\Z/, ".#{@book.config['htmlext']}")}#bib-#{normalize_id(id)}">[#{@chapter.bibpaper(id).number}]</a>)
|
943
938
|
end
|
944
939
|
|
945
940
|
def inline_hd_chap(chap, id)
|
@@ -1079,7 +1074,7 @@ QUOTE
|
|
1079
1074
|
end
|
1080
1075
|
|
1081
1076
|
def inline_tt(str)
|
1082
|
-
if @book.
|
1077
|
+
if @book.htmlversion == 5
|
1083
1078
|
%Q(<code class="tt">#{escape_html(str)}</code>)
|
1084
1079
|
else
|
1085
1080
|
%Q(<tt>#{escape_html(str)}</tt>)
|
@@ -1159,4 +1154,4 @@ QUOTE
|
|
1159
1154
|
end
|
1160
1155
|
end
|
1161
1156
|
|
1162
|
-
end
|
1157
|
+
end # module ReVIEW
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'review'
|
2
|
+
module ReVIEW
|
3
|
+
class HTMLToc
|
4
|
+
def initialize(basedir)
|
5
|
+
@tochtmltxt = "toc-html.txt"
|
6
|
+
@basedir = basedir
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_item(level, filename, title, args)
|
10
|
+
args_str = encode_args(args)
|
11
|
+
line = [level, filename, title, args_str].join("\t")
|
12
|
+
File.open(tocfilename, "a") do |f|
|
13
|
+
f.write "#{line}\n"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def each_item
|
18
|
+
File.open(tocfilename) do |f|
|
19
|
+
f.each_line do |line|
|
20
|
+
level, file, title, args_str = line.chomp.split("\t")
|
21
|
+
args = decode_args(args_str)
|
22
|
+
yield level, file, title, args
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def tocfilename
|
28
|
+
File.join(@basedir, @tochtmltxt)
|
29
|
+
end
|
30
|
+
|
31
|
+
def decode_args(args_str)
|
32
|
+
args = Hash.new
|
33
|
+
args_str.split(/,\s*/).each do |pair|
|
34
|
+
key, val = pair.split("=")
|
35
|
+
args[key.to_sym] = val
|
36
|
+
end
|
37
|
+
args
|
38
|
+
end
|
39
|
+
|
40
|
+
def encode_args(args)
|
41
|
+
args.map{|k,v| "#{k}=#{v}"}.join(",")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
data/lib/review/htmlutils.rb
CHANGED
@@ -40,7 +40,7 @@ module ReVIEW
|
|
40
40
|
str.gsub('-', '-')
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
43
|
+
def highlight?
|
44
44
|
@book.config["pygments"].present? ||
|
45
45
|
@book.config["highlight"] && @book.config["highlight"]["html"] == "pygments"
|
46
46
|
end
|
@@ -58,7 +58,7 @@ module ReVIEW
|
|
58
58
|
if ops[:options] && ops[:options].kind_of?(Hash)
|
59
59
|
options.merge!(ops[:options])
|
60
60
|
end
|
61
|
-
return body if !
|
61
|
+
return body if !highlight?
|
62
62
|
|
63
63
|
begin
|
64
64
|
require 'pygments'
|
@@ -87,4 +87,4 @@ module ReVIEW
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
end
|
90
|
+
end # module ReVIEW
|
data/lib/review/i18n.rb
CHANGED
@@ -38,7 +38,7 @@ module ReVIEW
|
|
38
38
|
end
|
39
39
|
|
40
40
|
class << self
|
41
|
-
|
41
|
+
alias_method :v, :t ## for EPUBMaker backward compatibility
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.update(user_i18n, locale = nil)
|
@@ -65,7 +65,11 @@ module ReVIEW
|
|
65
65
|
locale = user_i18n["locale"]
|
66
66
|
if locale
|
67
67
|
user_i18n.delete("locale")
|
68
|
-
@store[locale]
|
68
|
+
if @store[locale]
|
69
|
+
@store[locale].merge!(user_i18n)
|
70
|
+
else
|
71
|
+
@store[locale] = user_i18n
|
72
|
+
end
|
69
73
|
else
|
70
74
|
user_i18n.each do |key, values|
|
71
75
|
raise KeyError, "Invalid locale file: #{path}" unless values.kind_of? Hash
|
data/lib/review/i18n.yml
CHANGED
data/lib/review/idgxmlbuilder.rb
CHANGED
@@ -541,7 +541,7 @@ module ReVIEW
|
|
541
541
|
totallength = 0
|
542
542
|
cellwidth.size.times do |n|
|
543
543
|
cellwidth[n] = cellwidth[n].to_f / 0.351 # mm -> pt
|
544
|
-
totallength
|
544
|
+
totallength += cellwidth[n]
|
545
545
|
warn "total length exceeds limit for table: #{id}" if totallength > tablewidth
|
546
546
|
end
|
547
547
|
if cellwidth.size < col
|
@@ -1084,7 +1084,7 @@ module ReVIEW
|
|
1084
1084
|
lines.each do |l|
|
1085
1085
|
print l.gsub("<", "<").gsub(">", ">").gsub(""", "\"").gsub("&", "&")
|
1086
1086
|
print "\n" unless lines.length == no
|
1087
|
-
no
|
1087
|
+
no += 1
|
1088
1088
|
end
|
1089
1089
|
end
|
1090
1090
|
|
@@ -1095,8 +1095,7 @@ module ReVIEW
|
|
1095
1095
|
def inline_chapref(id)
|
1096
1096
|
chs = ["", "「", "」"]
|
1097
1097
|
unless @book.config["chapref"].nil?
|
1098
|
-
_chs =
|
1099
|
-
@book.config["inencoding"]).split(",")
|
1098
|
+
_chs = @book.config["chapref"].split(",")
|
1100
1099
|
if _chs.size != 3
|
1101
1100
|
error "--chapsplitter must have exactly 3 parameters with comma."
|
1102
1101
|
else
|
@@ -1195,4 +1194,4 @@ module ReVIEW
|
|
1195
1194
|
|
1196
1195
|
end
|
1197
1196
|
|
1198
|
-
end
|
1197
|
+
end # module ReVIEW
|
data/lib/review/inaobuilder.rb
CHANGED
data/lib/review/latexbuilder.rb
CHANGED
@@ -505,7 +505,7 @@ module ReVIEW
|
|
505
505
|
|
506
506
|
def th(s)
|
507
507
|
## use shortstack for @<br>
|
508
|
-
if
|
508
|
+
if /\\\\/i =~ s
|
509
509
|
macro('reviewth', macro('shortstack[l]', s))
|
510
510
|
else
|
511
511
|
macro('reviewth', s)
|
@@ -514,7 +514,7 @@ module ReVIEW
|
|
514
514
|
|
515
515
|
def td(s)
|
516
516
|
## use shortstack for @<br>
|
517
|
-
if
|
517
|
+
if /\\\\/ =~ s
|
518
518
|
macro('shortstack[l]', s)
|
519
519
|
else
|
520
520
|
s
|
data/lib/review/latexutils.rb
CHANGED
@@ -17,18 +17,18 @@ module ReVIEW
|
|
17
17
|
module LaTeXUtils
|
18
18
|
|
19
19
|
METACHARS = {
|
20
|
-
'#'
|
21
|
-
"$"
|
20
|
+
'#' => '\#',
|
21
|
+
"$" => '\textdollar{}',
|
22
22
|
'%' => '\%',
|
23
23
|
'&' => '\&',
|
24
24
|
'{' => '\{',
|
25
25
|
'}' => '\}',
|
26
|
-
'_'
|
26
|
+
'_' => '\textunderscore{}',
|
27
27
|
'^' => '\textasciicircum{}',
|
28
28
|
'~' => '\textasciitilde{}',
|
29
29
|
'|' => '\textbar{}',
|
30
|
-
'<'
|
31
|
-
'>'
|
30
|
+
'<' => '\textless{}',
|
31
|
+
'>' => '\textgreater{}',
|
32
32
|
"\\" => '\reviewbackslash{}',
|
33
33
|
"-" => '{-}',
|
34
34
|
|
@@ -70,7 +70,7 @@ module ReVIEW
|
|
70
70
|
alias_method :escape, :escape_latex
|
71
71
|
|
72
72
|
def unescape_latex(str)
|
73
|
-
metachars_invert_re = Regexp.new(METACHARS_INVERT.keys.collect{|key|
|
73
|
+
metachars_invert_re = Regexp.new(METACHARS_INVERT.keys.collect{|key| Regexp.escape(key)}.join('|'))
|
74
74
|
str.gsub(metachars_invert_re) {|s|
|
75
75
|
METACHARS_INVERT[s] or raise "unknown trans char: #{s}"
|
76
76
|
}
|
@@ -51,9 +51,9 @@ module ReVIEW
|
|
51
51
|
|
52
52
|
def list_header(id, caption, lang)
|
53
53
|
if get_chap.nil?
|
54
|
-
|
54
|
+
print %Q[リスト#{@chapter.list(id).number} #{compile_inline(caption)}\n\n]
|
55
55
|
else
|
56
|
-
|
56
|
+
print %Q[リスト#{get_chap}.#{@chapter.list(id).number} #{compile_inline(caption)}\n\n]
|
57
57
|
end
|
58
58
|
lang ||= ""
|
59
59
|
puts "```#{lang}"
|
@@ -103,6 +103,7 @@ module ReVIEW
|
|
103
103
|
blank
|
104
104
|
if caption
|
105
105
|
puts caption
|
106
|
+
print "\n"
|
106
107
|
end
|
107
108
|
lang ||= ""
|
108
109
|
puts "```#{lang}"
|
@@ -274,4 +275,4 @@ module ReVIEW
|
|
274
275
|
end
|
275
276
|
end
|
276
277
|
|
277
|
-
end
|
278
|
+
end # module ReVIEW
|