tmtms-review 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +9 -0
  3. data/COPYING +515 -0
  4. data/ChangeLog +2083 -0
  5. data/README.rdoc +50 -0
  6. data/Rakefile +56 -0
  7. data/VERSION +1 -0
  8. data/bin/review-check +178 -0
  9. data/bin/review-checkdep +63 -0
  10. data/bin/review-compile +205 -0
  11. data/bin/review-epubmaker +661 -0
  12. data/bin/review-epubmaker-ng +176 -0
  13. data/bin/review-index +118 -0
  14. data/bin/review-pdfmaker +208 -0
  15. data/bin/review-preproc +142 -0
  16. data/bin/review-validate +51 -0
  17. data/bin/review-vol +102 -0
  18. data/debian/README.Debian +12 -0
  19. data/debian/README.source +5 -0
  20. data/debian/changelog +5 -0
  21. data/debian/compat +1 -0
  22. data/debian/control +22 -0
  23. data/debian/copyright +62 -0
  24. data/debian/docs +6 -0
  25. data/debian/manpage.1.ex +59 -0
  26. data/debian/patches/path.diff +91 -0
  27. data/debian/patches/series +1 -0
  28. data/debian/review.install +13 -0
  29. data/debian/review.links +4 -0
  30. data/debian/rules +13 -0
  31. data/debian/source/format +1 -0
  32. data/doc/format.rdoc +582 -0
  33. data/doc/format_idg.rdoc +180 -0
  34. data/doc/libepubmaker/sample.yaml +90 -0
  35. data/doc/quickstart.rdoc +188 -0
  36. data/doc/ruby-uuid/README +11 -0
  37. data/doc/ruby-uuid/README.ja +34 -0
  38. data/doc/sample.css +108 -0
  39. data/doc/sample.yaml +62 -0
  40. data/lib/epubmaker.rb +28 -0
  41. data/lib/epubmaker/content.rb +82 -0
  42. data/lib/epubmaker/epubv2.rb +418 -0
  43. data/lib/epubmaker/epubv3.rb +249 -0
  44. data/lib/epubmaker/producer.rb +204 -0
  45. data/lib/epubmaker/resource.rb +66 -0
  46. data/lib/lineinput.rb +155 -0
  47. data/lib/review.rb +3 -0
  48. data/lib/review/book.rb +46 -0
  49. data/lib/review/book/base.rb +235 -0
  50. data/lib/review/book/chapter.rb +81 -0
  51. data/lib/review/book/compilable.rb +159 -0
  52. data/lib/review/book/index.rb +339 -0
  53. data/lib/review/book/page_metric.rb +38 -0
  54. data/lib/review/book/parameters.rb +97 -0
  55. data/lib/review/book/part.rb +44 -0
  56. data/lib/review/book/volume.rb +65 -0
  57. data/lib/review/builder.rb +444 -0
  58. data/lib/review/compiler.rb +550 -0
  59. data/lib/review/configure.rb +38 -0
  60. data/lib/review/epubbuilder.rb +18 -0
  61. data/lib/review/exception.rb +21 -0
  62. data/lib/review/extentions.rb +3 -0
  63. data/lib/review/extentions/object.rb +9 -0
  64. data/lib/review/extentions/string.rb +33 -0
  65. data/lib/review/htmlbuilder.rb +1097 -0
  66. data/lib/review/htmllayout.rb +19 -0
  67. data/lib/review/htmlutils.rb +36 -0
  68. data/lib/review/i18n.rb +30 -0
  69. data/lib/review/i18n.yaml +34 -0
  70. data/lib/review/idgxmlbuilder.rb +1145 -0
  71. data/lib/review/latexbuilder.rb +815 -0
  72. data/lib/review/latexindex.rb +35 -0
  73. data/lib/review/latexutils.rb +79 -0
  74. data/lib/review/preprocessor.rb +563 -0
  75. data/lib/review/review.tex.erb +232 -0
  76. data/lib/review/textbuilder.rb +17 -0
  77. data/lib/review/textutils.rb +66 -0
  78. data/lib/review/tocparser.rb +342 -0
  79. data/lib/review/tocprinter.rb +221 -0
  80. data/lib/review/topbuilder.rb +785 -0
  81. data/lib/review/unfold.rb +138 -0
  82. data/lib/uuid.rb +312 -0
  83. data/review.gemspec +141 -0
  84. data/test/CHAPS +2 -0
  85. data/test/bib.re +13 -0
  86. data/test/book_test_helper.rb +35 -0
  87. data/test/test.re +43 -0
  88. data/test/test_book.rb +598 -0
  89. data/test/test_book_chapter.rb +418 -0
  90. data/test/test_book_parameter.rb +42 -0
  91. data/test/test_book_part.rb +50 -0
  92. data/test/test_builder.rb +144 -0
  93. data/test/test_compiler.rb +44 -0
  94. data/test/test_epubmaker.rb +507 -0
  95. data/test/test_helper.rb +27 -0
  96. data/test/test_htmlbuilder.rb +554 -0
  97. data/test/test_htmlutils.rb +28 -0
  98. data/test/test_i18n.rb +64 -0
  99. data/test/test_idgxmlbuilder.rb +589 -0
  100. data/test/test_index.rb +31 -0
  101. data/test/test_latexbuilder.rb +656 -0
  102. data/test/test_lineinput.rb +198 -0
  103. data/test/test_preprocessor.rb +23 -0
  104. data/test/test_textutils.rb +68 -0
  105. data/test/test_topbuilder.rb +244 -0
  106. data/test/test_uuid.rb +156 -0
  107. metadata +161 -0
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ module ReVIEW
3
+ class Configure
4
+ def self.values
5
+ { # These parameters can be overridden by YAML file.
6
+ "bookname"=> "example", # it defines epub file name also
7
+ "booktitle" => "ReVIEW EPUBサンプル",
8
+ "title" => "example",
9
+ "aut" => nil, # author
10
+ "prt" => nil, # printer(publisher)
11
+ "asn" => nil, # associated name
12
+ "ant" => nil, # bibliographic antecedent
13
+ "clb" => nil, # Collaborator
14
+ "edt" => nil, # Editor
15
+ "dsr" => nil, # Designer
16
+ "ill" => nil, # Illustrator
17
+ "pht" => nil, # Photographer
18
+ "trl" => nil, # Translator
19
+ "date" => nil, # publishing date
20
+ "rights" => nil, # Copyright messages
21
+ "description" => nil, # Description
22
+ "urnid" => nil, # Identifier (nil makes random uuid)
23
+ "stylesheet" => "stylesheet.css", # stylesheet file
24
+ "coverfile" => nil, # content file of body of cover page
25
+ "mytoc" => nil, # whether make own table of contents or not
26
+ "params" => "", # specify review2html parameters
27
+ "toclevel" => 3, # level of toc
28
+ "secnolevel" => 2, # level of section #
29
+ "posthook" => nil, # command path of post hook
30
+ "epubversion" => 2,
31
+ "titlepage" => true, # Use title page
32
+ "toc" => true, # Use table of contents
33
+ "colophon" => false, # Use colophon
34
+ "debug" => nil, # debug flag
35
+ }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ # epubbuilder.rb
2
+ # just for compatibility
3
+ #
4
+ # Copyright (c) 2010 Kenshi Muto
5
+ #
6
+ # This program is free software.
7
+ # You can distribute or modify this program under the terms of
8
+ # the GNU LGPL, Lesser General Public License version 2.1.
9
+ #
10
+
11
+ require 'review/htmlbuilder'
12
+
13
+ module ReVIEW
14
+
15
+ class EPUBBuilder < HTMLBuilder
16
+ end
17
+
18
+ end # module ReVIEW
@@ -0,0 +1,21 @@
1
+ #
2
+ # $Id: exception.rb 3881 2008-02-09 14:44:17Z aamine $
3
+ #
4
+ # Copyright (c) 2002-2007 Minero Aoki
5
+ #
6
+ # This program is free software.
7
+ # You can distribute or modify this program under the terms of
8
+ # the GNU LGPL, Lesser General Public License version 2.1.
9
+ # For details of the GNU LGPL, see the file "COPYING".
10
+ #
11
+
12
+ module ReVIEW
13
+
14
+ class Error < ::StandardError; end
15
+ class ApplicationError < Error; end
16
+ class ConfigError < ApplicationError; end
17
+ class CompileError < ApplicationError; end
18
+ class SyntaxError < CompileError; end
19
+ class FileNotFound < ApplicationError; end
20
+ class KeyError < CompileError; end
21
+ end
@@ -0,0 +1,3 @@
1
+ require 'review/extentions/object'
2
+ require 'review/extentions/string'
3
+
@@ -0,0 +1,9 @@
1
+ class Object
2
+ def blank?
3
+ respond_to?(:empty?) ? empty? : !self
4
+ end
5
+
6
+ def present?
7
+ !blank?
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ if defined?(Encoding) && Encoding.respond_to?("default_external")
2
+ Encoding.default_external = "UTF-8"
3
+ end
4
+
5
+ unless String.method_defined?(:lines)
6
+ # Ruby 1.8
7
+ class String
8
+ alias lines to_a
9
+ end
10
+ end
11
+
12
+ if String.method_defined?(:bytesize)
13
+ # Ruby 1.9
14
+ class String
15
+ alias charsize size
16
+ end
17
+ else
18
+ # Ruby 1.8
19
+ class String
20
+ alias bytesize size
21
+
22
+ def charsize
23
+ split(//).size
24
+ end
25
+ end
26
+ end
27
+
28
+ unless String.method_defined?(:each)
29
+ # Ruby 1.9
30
+ class String
31
+ alias each each_line
32
+ end
33
+ end
@@ -0,0 +1,1097 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2002-2007 Minero Aoki
4
+ # 2008-2012 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
5
+ # KADO Masanori
6
+ #
7
+ # This program is free software.
8
+ # You can distribute or modify this program under the terms of
9
+ # the GNU LGPL, Lesser General Public License version 2.1.
10
+ #
11
+
12
+ require 'review/builder'
13
+ require 'review/htmlutils'
14
+ require 'review/htmllayout'
15
+ require 'review/textutils'
16
+
17
+ module ReVIEW
18
+
19
+ class HTMLBuilder < Builder
20
+
21
+ include TextUtils
22
+ include HTMLUtils
23
+
24
+ [:ref].each {|e| Compiler.definline(e) }
25
+ Compiler.defblock(:memo, 0..1)
26
+ Compiler.defblock(:tip, 0..1)
27
+ Compiler.defblock(:info, 0..1)
28
+ Compiler.defblock(:planning, 0..1)
29
+ Compiler.defblock(:best, 0..1)
30
+ Compiler.defblock(:important, 0..1)
31
+ Compiler.defblock(:security, 0..1)
32
+ Compiler.defblock(:caution, 0..1)
33
+ Compiler.defblock(:notice, 0..1)
34
+ Compiler.defblock(:point, 0..1)
35
+ Compiler.defblock(:shoot, 0..1)
36
+
37
+ def pre_paragraph
38
+ '<p>'
39
+ end
40
+ def post_paragraph
41
+ '</p>'
42
+ end
43
+
44
+ def extname
45
+ ".#{ReVIEW.book.param["htmlext"]}"
46
+ end
47
+
48
+ def builder_init(no_error = false)
49
+ @no_error = no_error
50
+ @section = 0
51
+ @subsection = 0
52
+ @subsubsection = 0
53
+ @subsubsubsection = 0
54
+ @noindent = nil
55
+ @ol_num = nil
56
+ end
57
+ private :builder_init
58
+
59
+ def builder_init_file
60
+ @warns = []
61
+ @errors = []
62
+ end
63
+ private :builder_init_file
64
+
65
+ def result
66
+ layout_file = File.join(@book.basedir, "layouts", "layout.erb")
67
+ if File.exists?(layout_file)
68
+ messages() +
69
+ HTMLLayout.new(@output.string, @chapter.title, layout_file).result
70
+ else
71
+ # default XHTML header/footer
72
+ header = <<EOT
73
+ <?xml version="1.0" encoding="#{ReVIEW.book.param["outencoding"] || :UTF-8}"?>
74
+ EOT
75
+
76
+ if ReVIEW.book.param["htmlversion"] == 5
77
+ header += <<EOT
78
+ <!DOCTYPE html>
79
+ EOT
80
+ else
81
+ header += <<EOT
82
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
83
+ EOT
84
+ end
85
+
86
+ header += <<EOT
87
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="#{ReVIEW.book.param["language"]}">
88
+ <head>
89
+ <meta http-equiv="Content-Type" content="text/html;charset=#{ReVIEW.book.param["outencoding"] || :UTF-8}" />
90
+ <meta http-equiv="Content-Style-Type" content="text/css" />
91
+ EOT
92
+ unless ReVIEW.book.param["stylesheet"].nil?
93
+ ReVIEW.book.param["stylesheet"].each do |style|
94
+ header += <<EOT
95
+ <link rel="stylesheet" type="text/css" href="#{style}" />
96
+ EOT
97
+ end
98
+ end
99
+ header += <<EOT
100
+ <meta name="generator" content="ReVIEW" />
101
+ <title>#{convert_outencoding(strip_html(compile_inline(@chapter.title)), ReVIEW.book.param["outencoding"])}</title>
102
+ </head>
103
+ <body>
104
+ EOT
105
+ footer = <<EOT
106
+ </body>
107
+ </html>
108
+ EOT
109
+ header + messages() + convert_outencoding(@output.string, ReVIEW.book.param["outencoding"]) + footer
110
+ end
111
+ end
112
+
113
+ def warn(msg)
114
+ if @no_error
115
+ @warns.push [@location.filename, @location.lineno, msg]
116
+ puts "----WARNING: #{escape_html(msg)}----"
117
+ else
118
+ $stderr.puts "#{@location}: warning: #{msg}"
119
+ end
120
+ end
121
+
122
+ def error(msg)
123
+ if @no_error
124
+ @errors.push [@location.filename, @location.lineno, msg]
125
+ puts "----ERROR: #{escape_html(msg)}----"
126
+ else
127
+ $stderr.puts "#{@location}: error: #{msg}"
128
+ end
129
+ end
130
+
131
+ def messages
132
+ error_messages() + warning_messages()
133
+ end
134
+
135
+ def error_messages
136
+ return '' if @errors.empty?
137
+ "<h2>Syntax Errors</h2>\n" +
138
+ "<ul>\n" +
139
+ @errors.map {|file, line, msg|
140
+ "<li>#{escape_html(file)}:#{line}: #{escape_html(msg.to_s)}</li>\n"
141
+ }.join('') +
142
+ "</ul>\n"
143
+ end
144
+
145
+ def warning_messages
146
+ return '' if @warns.empty?
147
+ "<h2>Warnings</h2>\n" +
148
+ "<ul>\n" +
149
+ @warns.map {|file, line, msg|
150
+ "<li>#{escape_html(file)}:#{line}: #{escape_html(msg)}</li>\n"
151
+ }.join('') +
152
+ "</ul>\n"
153
+ end
154
+
155
+ def headline_prefix(level)
156
+ anchor = ""
157
+ case level
158
+ when 1
159
+ @section = 0
160
+ @subsection = 0
161
+ @subsubsection = 0
162
+ @subsubsubsection = 0
163
+ anchor = "#{@chapter.number}"
164
+ if ReVIEW.book.param["secnolevel"] >= 1
165
+ placeholder = @chapter.is_a?(ReVIEW::Book::Part) ? "part" : "chapter"
166
+
167
+ if @chapter.number.to_s =~ /\A\d+\Z/
168
+ prefix = "#{I18n.t(placeholder, @chapter.number)}#{I18n.t("chapter_postfix")}"
169
+ elsif @chapter.number.present?
170
+ prefix = "#{@chapter.number}#{I18n.t("chapter_postfix")}"
171
+ end
172
+ end
173
+ when 2
174
+ @section += 1
175
+ @subsection = 0
176
+ @subsubsection = 0
177
+ @subsubsubsection = 0
178
+ anchor = "#{@chapter.number}-#{@section}"
179
+ if ReVIEW.book.param["secnolevel"] >= 2
180
+ if @chapter.number.to_s =~ /\A\d+\Z/
181
+ prefix = "#{@chapter.number}.#{@section}#{I18n.t("chapter_postfix")}"
182
+ elsif @chapter.number.present?
183
+ prefix = "#{@chapter.number}.#{@section}#{I18n.t("chapter_postfix")}"
184
+ end
185
+ end
186
+ when 3
187
+ @subsection += 1
188
+ @subsubsection = 0
189
+ @subsubsubsection = 0
190
+ anchor = "#{@chapter.number}-#{@section}-#{@subsection}"
191
+ if ReVIEW.book.param["secnolevel"] >= 3
192
+ if @chapter.number.to_s =~ /\A\d+\Z/
193
+ prefix = "#{@chapter.number}.#{@section}.#{@subsection}#{I18n.t("chapter_postfix")}"
194
+ elsif @chapter.number.present?
195
+ prefix = "#{@chapter.number}.#{@section}.#{@subsection}#{I18n.t("chapter_postfix")}"
196
+ end
197
+ end
198
+ when 4
199
+ @subsubsection += 1
200
+ @subsubsubsection = 0
201
+ anchor = "#{@chapter.number}-#{@section}-#{@subsection}-#{@subsubsection}"
202
+ if ReVIEW.book.param["secnolevel"] >= 4
203
+ if @chapter.number.to_s =~ /\A\d+\Z/
204
+ prefix = "#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}#{I18n.t("chapter_postfix")}"
205
+ elsif @chapter.number.present?
206
+ prefix = "#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}#{I18n.t("chapter_postfix")}"
207
+ end
208
+ end
209
+ when 5
210
+ @subsubsubsection += 1
211
+ anchor = "#{@chapter.number}-#{@section}-#{@subsection}-#{@subsubsection}-#{@subsubsubsection}"
212
+ if ReVIEW.book.param["secnolevel"] >= 5
213
+ if @chapter.number.to_s =~ /\A\d+\Z/
214
+ prefix = "#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection}#{I18n.t("chapter_postfix")}"
215
+ elsif @chapter.number.present?
216
+ prefix = "#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection}#{I18n.t("chapter_postfix")}"
217
+ end
218
+ end
219
+ end
220
+ [prefix, anchor]
221
+ end
222
+ private :headline_prefix
223
+
224
+ def headline(level, label, caption)
225
+ prefix, anchor = headline_prefix(level)
226
+ puts '' if level > 1
227
+ a_id = ""
228
+ unless anchor.nil?
229
+ a_id = %Q[<a id="h#{anchor}"></a>]
230
+ end
231
+ if caption.empty?
232
+ puts a_id unless label.nil?
233
+ else
234
+ if label.nil?
235
+ puts %Q[<h#{level}>#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>]
236
+ else
237
+ puts %Q[<h#{level} id="#{label}">#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>]
238
+ end
239
+ end
240
+ end
241
+
242
+ def nonum_begin(level, label, caption)
243
+ puts '' if level > 1
244
+ unless caption.empty?
245
+ if label.nil?
246
+ puts %Q[<h#{level}>#{compile_inline(caption)}</h#{level}>]
247
+ else
248
+ puts %Q[<h#{level} id="#{label}">#{compile_inline(caption)}</h#{level}>]
249
+ end
250
+ end
251
+ end
252
+
253
+ def nonum_end(level)
254
+ end
255
+
256
+ def column_begin(level, label, caption)
257
+ puts %Q[<div class="column">]
258
+ headline(level, label, caption)
259
+ end
260
+
261
+ def column_end(level)
262
+ puts '</div>'
263
+ end
264
+
265
+ def xcolumn_begin(level, label, caption)
266
+ puts %Q[<div class="xcolumn">]
267
+ headline(level, label, caption)
268
+ end
269
+
270
+ def xcolumn_end(level)
271
+ puts '</div>'
272
+ end
273
+
274
+ def ref_begin(level, label, caption)
275
+ print %Q[<div class="reference">]
276
+ headline(level, label, caption)
277
+ end
278
+
279
+ def ref_end(level)
280
+ puts '</div>'
281
+ end
282
+
283
+ def sup_begin(level, label, caption)
284
+ print %Q[<div class="supplement">]
285
+ headline(level, label, caption)
286
+ end
287
+
288
+ def sup_end(level)
289
+ puts '</div>'
290
+ end
291
+
292
+ def tsize(str)
293
+ # null
294
+ end
295
+
296
+ def captionblock(type, lines, caption)
297
+ puts %Q[<div class="#{type}">]
298
+ unless caption.nil?
299
+ puts %Q[<p class="caption">#{compile_inline(caption)}</p>]
300
+ end
301
+ if ReVIEW.book.param["deprecated-blocklines"].nil?
302
+ blocked_lines = split_paragraph(lines)
303
+ puts blocked_lines.join("\n")
304
+ else
305
+ lines.each {|l| puts "<p>#{l}</p>" }
306
+ end
307
+ puts '</div>'
308
+ end
309
+
310
+ def memo(lines, caption = nil)
311
+ captionblock("memo", lines, caption)
312
+ end
313
+
314
+ def tip(lines, caption = nil)
315
+ captionblock("tip", lines, caption)
316
+ end
317
+
318
+ def info(lines, caption = nil)
319
+ captionblock("info", lines, caption)
320
+ end
321
+
322
+ def planning(lines, caption = nil)
323
+ captionblock("planning", lines, caption)
324
+ end
325
+
326
+ def best(lines, caption = nil)
327
+ captionblock("best", lines, caption)
328
+ end
329
+
330
+ def important(lines, caption = nil)
331
+ captionblock("important", lines, caption)
332
+ end
333
+
334
+ def security(lines, caption = nil)
335
+ captionblock("security", lines, caption)
336
+ end
337
+
338
+ def caution(lines, caption = nil)
339
+ captionblock("caution", lines, caption)
340
+ end
341
+
342
+ def notice(lines, caption = nil)
343
+ captionblock("notice", lines, caption)
344
+ end
345
+
346
+ def point(lines, caption = nil)
347
+ captionblock("point", lines, caption)
348
+ end
349
+
350
+ def shoot(lines, caption = nil)
351
+ captionblock("shoot", lines, caption)
352
+ end
353
+
354
+ def box(lines, caption = nil)
355
+ puts %Q[<div class="syntax">]
356
+ puts %Q[<p class="caption">#{compile_inline(caption)}</p>] unless caption.nil?
357
+ print %Q[<pre class="syntax">]
358
+ lines.each {|line| puts detab(line) }
359
+ puts '</pre>'
360
+ puts '</div>'
361
+ end
362
+
363
+ def note(lines, caption = nil)
364
+ captionblock("note", lines, caption)
365
+ end
366
+
367
+ def ul_begin
368
+ puts '<ul>'
369
+ end
370
+
371
+ def ul_item(lines)
372
+ puts "<li>#{lines.join}</li>"
373
+ end
374
+
375
+ def ul_item_begin(lines)
376
+ print "<li>#{lines.join}"
377
+ end
378
+
379
+ def ul_item_end
380
+ puts "</li>"
381
+ end
382
+
383
+ def ul_end
384
+ puts '</ul>'
385
+ end
386
+
387
+ def ol_begin
388
+ if @ol_num
389
+ puts "<ol start=\"#{@ol_num}\">" ## it's OK in HTML5, but not OK in XHTML1.1
390
+ @ol_num = nil
391
+ else
392
+ puts '<ol>'
393
+ end
394
+ end
395
+
396
+ def ol_item(lines, num)
397
+ puts "<li>#{lines.join}</li>"
398
+ end
399
+
400
+ def ol_end
401
+ puts '</ol>'
402
+ end
403
+
404
+ def dl_begin
405
+ puts '<dl>'
406
+ end
407
+
408
+ def dt(line)
409
+ puts "<dt>#{line}</dt>"
410
+ end
411
+
412
+ def dd(lines)
413
+ puts "<dd>#{lines.join}</dd>"
414
+ end
415
+
416
+ def dl_end
417
+ puts '</dl>'
418
+ end
419
+
420
+ def paragraph(lines)
421
+ if @noindent.nil?
422
+ puts "<p>#{lines.join}</p>"
423
+ else
424
+ puts %Q[<p class="noindent">#{lines.join}</p>]
425
+ @noindent = nil
426
+ end
427
+ end
428
+
429
+ def parasep()
430
+ puts '<br />'
431
+ end
432
+
433
+ def read(lines)
434
+ if ReVIEW.book.param["deprecated-blocklines"].nil?
435
+ blocked_lines = split_paragraph(lines)
436
+ puts %Q[<div class="lead">\n#{blocked_lines.join("\n")}\n</div>]
437
+ else
438
+ puts %Q[<p class="lead">\n#{lines.join("\n")}\n</p>]
439
+ end
440
+ end
441
+
442
+ alias :lead read
443
+
444
+ def list(lines, id, caption)
445
+ puts %Q[<div class="caption-code">]
446
+ begin
447
+ list_header id, caption
448
+ rescue KeyError
449
+ error "no such list: #{id}"
450
+ end
451
+ list_body lines
452
+ puts '</div>'
453
+ end
454
+
455
+ def list_header(id, caption)
456
+ if get_chap.nil?
457
+ puts %Q[<p class="caption">#{I18n.t("list")}#{I18n.t("format_number_header_without_chapter", [@chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}</p>]
458
+ else
459
+ puts %Q[<p class="caption">#{I18n.t("list")}#{I18n.t("format_number_header", [get_chap, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}</p>]
460
+ end
461
+ end
462
+
463
+ def list_body(lines)
464
+ print %Q[<pre class="list">]
465
+ lines.each do |line|
466
+ puts detab(line)
467
+ end
468
+ puts '</pre>'
469
+ end
470
+
471
+ def source(lines, caption)
472
+ puts %Q[<div class="source-code">]
473
+ source_header caption
474
+ source_body lines
475
+ puts '</div>'
476
+ end
477
+
478
+ def source_header(caption)
479
+ puts %Q[<p class="caption">#{compile_inline(caption)}</p>]
480
+ end
481
+
482
+ def source_body(lines)
483
+ print %Q[<pre class="source">]
484
+ lines.each do |line|
485
+ puts detab(line)
486
+ end
487
+ puts '</pre>'
488
+ end
489
+
490
+ def listnum(lines, id, caption)
491
+ puts %Q[<div class="code">]
492
+ begin
493
+ list_header id, caption
494
+ rescue KeyError
495
+ error "no such list: #{id}"
496
+ end
497
+ listnum_body lines
498
+ puts '</div>'
499
+ end
500
+
501
+ def listnum_body(lines)
502
+ print %Q[<pre class="list">]
503
+ lines.each_with_index do |line, i|
504
+ puts detab((i+1).to_s.rjust(2) + ": " + line)
505
+ end
506
+ puts '</pre>'
507
+ end
508
+
509
+ def emlist(lines, caption = nil)
510
+ puts %Q[<div class="emlist-code">]
511
+ puts %Q(<p class="caption">#{caption}</p>) unless caption.nil?
512
+ print %Q[<pre class="emlist">]
513
+ lines.each do |line|
514
+ puts detab(line)
515
+ end
516
+ puts '</pre>'
517
+ puts '</div>'
518
+ end
519
+
520
+ def emlistnum(lines)
521
+ puts %Q[<div class="emlistnum-code">]
522
+ print %Q[<pre class="emlist">]
523
+ lines.each_with_index do |line, i|
524
+ puts detab((i+1).to_s.rjust(2) + ": " + line)
525
+ end
526
+ puts '</pre>'
527
+ puts '</div>'
528
+ end
529
+
530
+ def cmd(lines, caption = nil)
531
+ puts %Q[<div class="cmd-code">]
532
+ puts %Q(<p class="caption">#{caption}</p>) unless caption.nil?
533
+ print %Q[<pre class="cmd">]
534
+ lines.each do |line|
535
+ puts detab(line)
536
+ end
537
+ puts '</pre>'
538
+ puts '</div>'
539
+ end
540
+
541
+ def quotedlist(lines, css_class)
542
+ print %Q[<blockquote><pre class="#{css_class}">]
543
+ lines.each do |line|
544
+ puts detab(line)
545
+ end
546
+ puts '</pre></blockquote>'
547
+ end
548
+ private :quotedlist
549
+
550
+ def quote(lines)
551
+ if ReVIEW.book.param["deprecated-blocklines"].nil?
552
+ blocked_lines = split_paragraph(lines)
553
+ puts "<blockquote>#{blocked_lines.join("\n")}</blockquote>"
554
+ else
555
+ puts "<blockquote><pre>#{lines.join("\n")}</pre></blockquote>"
556
+ end
557
+ end
558
+
559
+ def doorquote(lines, ref)
560
+ if ReVIEW.book.param["deprecated-blocklines"].nil?
561
+ blocked_lines = split_paragraph(lines)
562
+ puts %Q[<blockquote style="text-align:right;">]
563
+ puts "#{blocked_lines.join("\n")}"
564
+ puts %Q[<p>#{ref}より</p>]
565
+ puts %Q[</blockquote>]
566
+ else
567
+ puts <<-QUOTE
568
+ <blockquote style="text-align:right;">
569
+ <pre>#{lines.join("\n")}
570
+
571
+ #{ref}より</pre>
572
+ </blockquote>
573
+ QUOTE
574
+ end
575
+ end
576
+
577
+ def talk(lines)
578
+ puts %Q[<div class="talk">]
579
+ if ReVIEW.book.param["deprecated-blocklines"].nil?
580
+ blocked_lines = split_paragraph(lines)
581
+ puts "#{blocked_lines.join("\n")}"
582
+ else
583
+ print '<pre>'
584
+ puts "#{lines.join("\n")}"
585
+ puts '</pre>'
586
+ end
587
+ puts '</div>'
588
+ end
589
+
590
+ def texequation(lines)
591
+ puts %Q[<div class="equation">]
592
+ if ReVIEW.book.param["mathml"]
593
+ p = MathML::LaTeX::Parser.new
594
+ puts p.parse(unescape_html(lines.join("\n")), true)
595
+ else
596
+ print '<pre>'
597
+ puts "#{lines.join("\n")}"
598
+ puts '</pre>'
599
+ end
600
+ puts '</div>'
601
+ end
602
+
603
+ def handle_metric(str)
604
+ if str =~ /\Ascale=([\d.]+)\Z/
605
+ return "width=\"#{($1.to_f * 100).round}%\""
606
+ else
607
+ k, v = str.split('=', 2)
608
+ return %Q|#{k}=\"#{v.sub(/\A["']/, '').sub(/["']\Z/, '')}\"|
609
+ end
610
+ end
611
+
612
+ def result_metric(array)
613
+ " #{array.join(' ')}"
614
+ end
615
+
616
+ def image_image(id, caption, metric)
617
+ metrics = parse_metric("html", metric)
618
+ puts %Q[<div class="image">]
619
+ puts %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />]
620
+ image_header id, caption
621
+ puts %Q[</div>]
622
+ end
623
+
624
+ def image_dummy(id, caption, lines)
625
+ puts %Q[<div class="image">]
626
+ puts %Q[<pre class="dummyimage">]
627
+ lines.each do |line|
628
+ puts detab(line)
629
+ end
630
+ puts %Q[</pre>]
631
+ image_header id, caption
632
+ puts %Q[</div>]
633
+ end
634
+
635
+ def image_header(id, caption)
636
+ puts %Q[<p class="caption">]
637
+ if get_chap.nil?
638
+ puts %Q[#{I18n.t("image")}#{I18n.t("format_number_header_without_chapter", [@chapter.image(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
639
+ else
640
+ puts %Q[#{I18n.t("image")}#{I18n.t("format_number_header", [get_chap, @chapter.image(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
641
+ end
642
+ puts %Q[</p>]
643
+ end
644
+
645
+ def table(lines, id = nil, caption = nil)
646
+ rows = []
647
+ sepidx = nil
648
+ lines.each_with_index do |line, idx|
649
+ if /\A[\=\-]{12}/ =~ line
650
+ # just ignore
651
+ #error "too many table separator" if sepidx
652
+ sepidx ||= idx
653
+ next
654
+ end
655
+ rows.push line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') }
656
+ end
657
+ rows = adjust_n_cols(rows)
658
+
659
+ puts %Q[<div class="table">]
660
+ begin
661
+ table_header id, caption unless caption.nil?
662
+ rescue KeyError => err
663
+ error "no such table: #{id}"
664
+ end
665
+ table_begin rows.first.size
666
+ return if rows.empty?
667
+ if sepidx
668
+ sepidx.times do
669
+ tr rows.shift.map {|s| th(s) }
670
+ end
671
+ rows.each do |cols|
672
+ tr cols.map {|s| td(s) }
673
+ end
674
+ else
675
+ rows.each do |cols|
676
+ h, *cs = *cols
677
+ tr [th(h)] + cs.map {|s| td(s) }
678
+ end
679
+ end
680
+ table_end
681
+ puts %Q[</div>]
682
+ end
683
+
684
+ def table_header(id, caption)
685
+ if get_chap.nil?
686
+ puts %Q[<p class="caption">#{I18n.t("table")}#{I18n.t("format_number_header_without_chapter", [@chapter.table(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}</p>]
687
+ else
688
+ puts %Q[<p class="caption">#{I18n.t("table")}#{I18n.t("format_number_header", [get_chap, @chapter.table(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}</p>]
689
+ end
690
+ end
691
+
692
+ def table_begin(ncols)
693
+ puts '<table>'
694
+ end
695
+
696
+ def tr(rows)
697
+ puts "<tr>#{rows.join}</tr>"
698
+ end
699
+
700
+ def th(str)
701
+ "<th>#{str}</th>"
702
+ end
703
+
704
+ def td(str)
705
+ "<td>#{str}</td>"
706
+ end
707
+
708
+ def table_end
709
+ puts '</table>'
710
+ end
711
+
712
+ def comment(str)
713
+ if ReVIEW.book.param["draft"]
714
+ puts %Q(<div class="draft-comment">#{escape_html(str)}</div>)
715
+ else
716
+ puts %Q(<!-- #{escape_html(str)} -->)
717
+ end
718
+ end
719
+
720
+ def footnote(id, str)
721
+ puts %Q(<div class="footnote"><p class="footnote">[<a id="fn-#{id}">*#{@chapter.footnote(id).number}</a>] #{compile_inline(str)}</p></div>)
722
+ end
723
+
724
+ def indepimage(id, caption="", metric=nil)
725
+ metrics = parse_metric("html", metric)
726
+ caption = "" if caption.nil?
727
+ puts %Q[<div class="image">]
728
+ begin
729
+ puts %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />]
730
+ rescue
731
+ puts %Q[<pre>missing image: #{id}</pre>]
732
+ end
733
+
734
+ unless caption.empty?
735
+ puts %Q[<p class="caption">]
736
+ puts %Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
737
+ puts %Q[</p>]
738
+ end
739
+ puts %Q[</div>]
740
+ end
741
+
742
+ alias :numberlessimage indepimage
743
+
744
+ def hr
745
+ puts "<hr />"
746
+ end
747
+
748
+ def label(id)
749
+ puts %Q(<a id="#{id}"></a>)
750
+ end
751
+
752
+ def linebreak
753
+ puts "<br />"
754
+ end
755
+
756
+ def pagebreak
757
+ puts %Q(<br class="pagebreak" />)
758
+ end
759
+
760
+ def bpo(lines)
761
+ puts "<bpo>"
762
+ lines.each do |line|
763
+ puts detab(line)
764
+ end
765
+ puts "</bpo>"
766
+ end
767
+
768
+ def noindent
769
+ @noindent = true
770
+ end
771
+
772
+ def inline_labelref(idref)
773
+ %Q[<a target='#{escape_html(idref)}'>「●● #{escape_html(idref)}」</a>]
774
+ end
775
+
776
+ alias inline_ref inline_labelref
777
+
778
+ def inline_chapref(id)
779
+ if ReVIEW.book.param["chapterlink"]
780
+ %Q(<a href="./#{id}.html">#{@chapter.env.chapter_index.display_string(id)}</a>)
781
+ else
782
+ @chapter.env.chapter_index.display_string(id)
783
+ end
784
+ rescue KeyError
785
+ error "unknown chapter: #{id}"
786
+ nofunc_text("[UnknownChapter:#{id}]")
787
+ end
788
+
789
+ def inline_chap(id)
790
+ if ReVIEW.book.param["chapterlink"]
791
+ %Q(<a href="./#{id}.html">#{@chapter.env.chapter_index.number(id)}</a>)
792
+ else
793
+ @chapter.env.chapter_index.number(id)
794
+ end
795
+ rescue KeyError
796
+ error "unknown chapter: #{id}"
797
+ nofunc_text("[UnknownChapter:#{id}]")
798
+ end
799
+
800
+ def inline_title(id)
801
+ if ReVIEW.book.param["chapterlink"]
802
+ %Q(<a href="./#{id}.html">#{compile_inline(@chapter.env.chapter_index.title(id))}</a>)
803
+ else
804
+ @chapter.env.chapter_index.title(id)
805
+ end
806
+ rescue KeyError
807
+ error "unknown chapter: #{id}"
808
+ nofunc_text("[UnknownChapter:#{id}]")
809
+ end
810
+
811
+
812
+ def inline_fn(id)
813
+ %Q(<a href="#fn-#{id}">*#{@chapter.footnote(id).number}</a>)
814
+ end
815
+
816
+ def compile_ruby(base, ruby)
817
+ %Q[<ruby><rb>#{escape_html(base)}</rb><rp>#{I18n.t("ruby_prefix")}</rp><rt>#{ruby}</rt><rp>#{I18n.t("ruby_postfix")}</rp></ruby>]
818
+ end
819
+
820
+ def compile_kw(word, alt)
821
+ %Q[<b class="kw">] +
822
+ if alt
823
+ then escape_html(word + " (#{alt.strip})")
824
+ else escape_html(word)
825
+ end +
826
+ "</b><!-- IDX:#{escape_html(word)} -->"
827
+ end
828
+
829
+ def inline_i(str)
830
+ %Q(<i>#{escape_html(str)}</i>)
831
+ end
832
+
833
+ def inline_b(str)
834
+ %Q(<b>#{escape_html(str)}</b>)
835
+ end
836
+
837
+ def inline_ami(str)
838
+ %Q(<span class="ami">#{escape_html(str)}</span>)
839
+ end
840
+
841
+ def inline_bou(str)
842
+ %Q(<span class="bou">#{escape_html(str)}</span>)
843
+ end
844
+
845
+ def inline_tti(str)
846
+ %Q(<tt><i>#{escape_html(str)}</i></tt>)
847
+ end
848
+
849
+ def inline_ttb(str)
850
+ %Q(<tt><b>#{escape_html(str)}</b></tt>)
851
+ end
852
+
853
+ def inline_dtp(str)
854
+ "<?dtp #{str} ?>"
855
+ end
856
+
857
+ def inline_code(str)
858
+ %Q(<tt class="inline-code">#{escape_html(str)}</tt>)
859
+ end
860
+
861
+ def inline_idx(str)
862
+ %Q(#{escape_html(str)}<!-- IDX:#{escape_html(str)} -->)
863
+ end
864
+
865
+ def inline_hidx(str)
866
+ %Q(<!-- IDX:#{escape_html(str)} -->)
867
+ end
868
+
869
+ def inline_br(str)
870
+ %Q(<br />)
871
+ end
872
+
873
+ def inline_m(str)
874
+ if ReVIEW.book.param["mathml"]
875
+ p = MathML::LaTeX::Parser.new
876
+ %Q[<span class="equation">#{p.parse(str, nil)}</span>]
877
+ else
878
+ %Q[<span class="equation">#{escape_html(str)}</span>]
879
+ end
880
+ end
881
+
882
+ def text(str)
883
+ str
884
+ end
885
+
886
+ def bibpaper(lines, id, caption)
887
+ puts %Q[<div class="bibpaper">]
888
+ bibpaper_header id, caption
889
+ unless lines.empty?
890
+ bibpaper_bibpaper id, caption, lines
891
+ end
892
+ puts "</div>"
893
+ end
894
+
895
+ def bibpaper_header(id, caption)
896
+ print %Q(<a id="bib-#{id}">)
897
+ print "[#{@chapter.bibpaper(id).number}] #{compile_inline(caption)}"
898
+ puts %Q(</a>)
899
+ end
900
+
901
+ def bibpaper_bibpaper(id, caption, lines)
902
+ print %Q(<p>)
903
+ lines.each do |line|
904
+ puts detab(line)
905
+ end
906
+ puts %Q(</p>)
907
+ end
908
+
909
+ def inline_bib(id)
910
+ %Q(<a href=".#{@book.bib_file.gsub(/re\Z/, "html")}#bib-#{id}">[#{@chapter.bibpaper(id).number}]</a>)
911
+ end
912
+
913
+ def inline_hd_chap(chap, id)
914
+ n = chap.headline_index.number(id)
915
+ if chap.number and ReVIEW.book.param["secnolevel"] >= n.split('.').size
916
+ str = "「#{n} #{compile_inline(chap.headline(id).caption)}」"
917
+ else
918
+ str = "「#{compile_inline(chap.headline(id).caption)}」"
919
+ end
920
+ if ReVIEW.book.param["chapterlink"]
921
+ anchor = "h"+n.gsub(/\./, "-")
922
+ %Q(<a href="#{chap.id}.html\##{anchor}">#{str}</a>)
923
+ else
924
+ str
925
+ end
926
+ end
927
+
928
+ def inline_list(id)
929
+ chapter, id = extract_chapter_id(id)
930
+ if get_chap(chapter).nil?
931
+ "#{I18n.t("list")}#{I18n.t("format_number_without_header", [chapter.list(id).number])}"
932
+ else
933
+ "#{I18n.t("list")}#{I18n.t("format_number", [get_chap(chapter), chapter.list(id).number])}"
934
+ end
935
+ rescue KeyError
936
+ error "unknown list: #{id}"
937
+ nofunc_text("[UnknownList:#{id}]")
938
+ end
939
+
940
+ def inline_table(id)
941
+ chapter, id = extract_chapter_id(id)
942
+ if get_chap(chapter).nil?
943
+ "#{I18n.t("table")}#{I18n.t("format_number_without_chapter", [chapter.table(id).number])}"
944
+ else
945
+ "#{I18n.t("table")}#{I18n.t("format_number", [get_chap(chapter), chapter.table(id).number])}"
946
+ end
947
+ rescue KeyError
948
+ error "unknown table: #{id}"
949
+ nofunc_text("[UnknownTable:#{id}]")
950
+ end
951
+
952
+ def inline_img(id)
953
+ chapter, id = extract_chapter_id(id)
954
+ if get_chap(chapter).nil?
955
+ "#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [chapter.image(id).number])}"
956
+ else
957
+ "#{I18n.t("image")}#{I18n.t("format_number", [get_chap(chapter), chapter.image(id).number])}"
958
+ end
959
+ rescue KeyError
960
+ error "unknown image: #{id}"
961
+ nofunc_text("[UnknownImage:#{id}]")
962
+ end
963
+
964
+ def inline_asis(str, tag)
965
+ %Q(<#{tag}>#{escape_html(str)}</#{tag}>)
966
+ end
967
+
968
+ def inline_abbr(str)
969
+ inline_asis(str, "abbr")
970
+ end
971
+
972
+ def inline_acronym(str)
973
+ inline_asis(str, "acronym")
974
+ end
975
+
976
+ def inline_cite(str)
977
+ inline_asis(str, "cite")
978
+ end
979
+
980
+ def inline_dfn(str)
981
+ inline_asis(str, "dfn")
982
+ end
983
+
984
+ def inline_em(str)
985
+ inline_asis(str, "em")
986
+ end
987
+
988
+ def inline_kbd(str)
989
+ inline_asis(str, "kbd")
990
+ end
991
+
992
+ def inline_samp(str)
993
+ inline_asis(str, "samp")
994
+ end
995
+
996
+ def inline_strong(str)
997
+ inline_asis(str, "strong")
998
+ end
999
+
1000
+ def inline_var(str)
1001
+ inline_asis(str, "var")
1002
+ end
1003
+
1004
+ def inline_big(str)
1005
+ inline_asis(str, "big")
1006
+ end
1007
+
1008
+ def inline_small(str)
1009
+ inline_asis(str, "small")
1010
+ end
1011
+
1012
+ def inline_sub(str)
1013
+ inline_asis(str, "sub")
1014
+ end
1015
+
1016
+ def inline_sup(str)
1017
+ inline_asis(str, "sup")
1018
+ end
1019
+
1020
+ def inline_tt(str)
1021
+ inline_asis(str, "tt")
1022
+ end
1023
+
1024
+ def inline_del(str)
1025
+ inline_asis(str, "del")
1026
+ end
1027
+
1028
+ def inline_ins(str)
1029
+ inline_asis(str, "ins")
1030
+ end
1031
+
1032
+ def inline_u(str)
1033
+ %Q(<u>#{escape_html(str)}</u>)
1034
+ end
1035
+
1036
+ def inline_recipe(str)
1037
+ %Q(<span class="recipe">「#{escape_html(str)}」</span>)
1038
+ end
1039
+
1040
+ def inline_icon(id)
1041
+ begin
1042
+ %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="[#{id}]" />]
1043
+ rescue
1044
+ %Q[<pre>missing image: #{id}</pre>]
1045
+ end
1046
+ end
1047
+
1048
+ def inline_uchar(str)
1049
+ %Q(&#x#{str};)
1050
+ end
1051
+
1052
+ def inline_comment(str)
1053
+ if ReVIEW.book.param["draft"]
1054
+ %Q(<span class="draft-comment">#{escape_html(str)}</span>)
1055
+ else
1056
+ %Q(<!-- #{escape_html(str)} -->)
1057
+ end
1058
+ end
1059
+
1060
+ def inline_raw(str)
1061
+ super(str)
1062
+ end
1063
+
1064
+ def nofunc_text(str)
1065
+ escape_html(str)
1066
+ end
1067
+
1068
+ def compile_href(url, label)
1069
+ %Q(<a href="#{escape_html(url)}" class="link">#{label.nil? ? escape_html(url) : escape_html(label)}</a>)
1070
+ end
1071
+
1072
+ def flushright(lines)
1073
+ if ReVIEW.book.param["deprecated-blocklines"].nil?
1074
+ puts split_paragraph(lines).join("\n").gsub("<p>", "<p class=\"flushright\">")
1075
+ else
1076
+ puts %Q[<div style="text-align:right;">]
1077
+ print %Q[<pre class="flushright">]
1078
+ lines.each {|line| puts detab(line) }
1079
+ puts '</pre>'
1080
+ puts '</div>'
1081
+ end
1082
+ end
1083
+
1084
+ def centering(lines)
1085
+ puts split_paragraph(lines).join("\n").gsub("<p>", "<p class=\"center\">")
1086
+ end
1087
+
1088
+ def image_ext
1089
+ "png"
1090
+ end
1091
+
1092
+ def olnum(num)
1093
+ @ol_num = num.to_i
1094
+ end
1095
+ end
1096
+
1097
+ end # module ReVIEW