review 0.6.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. data/ChangeLog +441 -0
  2. data/README.rdoc +25 -0
  3. data/Rakefile +13 -1
  4. data/VERSION +1 -1
  5. data/bin/review-check +1 -1
  6. data/bin/review-compile +19 -10
  7. data/bin/review-epubmaker +114 -17
  8. data/bin/review-index +8 -1
  9. data/bin/review-pdfmaker +378 -0
  10. data/bin/review-preproc +2 -3
  11. data/bin/review-vol +1 -2
  12. data/debian/README.Debian +12 -0
  13. data/debian/README.source +5 -0
  14. data/debian/changelog +5 -0
  15. data/debian/compat +1 -0
  16. data/debian/control +22 -0
  17. data/debian/copyright +60 -0
  18. data/debian/docs +5 -0
  19. data/debian/manpage.1.ex +59 -0
  20. data/debian/patches/path.diff +91 -0
  21. data/debian/patches/series +1 -0
  22. data/debian/review.install +13 -0
  23. data/debian/review.links +4 -0
  24. data/debian/rules +13 -0
  25. data/debian/source/format +1 -0
  26. data/doc/format.rdoc +477 -0
  27. data/doc/format.re +19 -0
  28. data/doc/format_idg.rdoc +180 -0
  29. data/doc/ruby-uuid/README +11 -0
  30. data/doc/ruby-uuid/README.ja +34 -0
  31. data/doc/sample.css +17 -0
  32. data/doc/sample.yaml +8 -4
  33. data/lib/lineinput.rb +1 -1
  34. data/lib/review/book.rb +43 -36
  35. data/lib/review/builder.rb +78 -33
  36. data/lib/review/compiler.rb +45 -48
  37. data/lib/review/epubbuilder.rb +1 -675
  38. data/lib/review/exception.rb +1 -1
  39. data/lib/review/htmlbuilder.rb +627 -49
  40. data/lib/review/htmlutils.rb +5 -0
  41. data/lib/review/idgxmlbuilder.rb +239 -250
  42. data/lib/review/index.rb +84 -7
  43. data/lib/review/latexbuilder.rb +261 -42
  44. data/lib/review/latexutils.rb +15 -6
  45. data/lib/review/preprocessor.rb +40 -6
  46. data/lib/review/textutils.rb +22 -0
  47. data/lib/review/topbuilder.rb +4 -1
  48. data/lib/uuid.rb +312 -0
  49. data/review.gemspec +44 -12
  50. data/test/CHAPS +2 -0
  51. data/test/bib.re +13 -0
  52. data/test/test.re +43 -0
  53. data/test/test_book.rb +1191 -0
  54. data/test/test_builder.rb +147 -0
  55. data/test/test_htmlbuilder.rb +191 -10
  56. data/test/test_htmlutils.rb +24 -0
  57. data/test/test_idgxmlbuilder.rb +310 -0
  58. data/test/test_index.rb +15 -0
  59. data/test/test_latexbuilder.rb +217 -6
  60. data/test/test_lineinput.rb +198 -0
  61. data/test/test_textutils.rb +68 -0
  62. data/test/test_uuid.rb +156 -0
  63. metadata +43 -10
  64. data/doc/format.txt +0 -434
  65. data/doc/format_idg.txt +0 -194
  66. data/doc/format_sjis.txt +0 -313
  67. data/setup.rb +0 -1587
  68. data/test/test_epubbuilder.rb +0 -73
@@ -1,4 +1,4 @@
1
- #
1
+ # encoding: utf-8
2
2
  #
3
3
  # Copyright (c) 2002-2009 Minero Aoki
4
4
  #
@@ -16,6 +16,13 @@ module ReVIEW
16
16
 
17
17
  class Builder
18
18
 
19
+ def pre_paragraph
20
+ nil
21
+ end
22
+ def post_paragraph
23
+ nil
24
+ end
25
+
19
26
  def initialize(strict = false, *args)
20
27
  @strict = strict
21
28
  builder_init(*args)
@@ -25,10 +32,6 @@ module ReVIEW
25
32
  end
26
33
  private :builder_init
27
34
 
28
- def setParameter(param)
29
- @param = param
30
- end
31
-
32
35
  def bind(compiler, chapter, location)
33
36
  @compiler = compiler
34
37
  @chapter = chapter
@@ -46,28 +49,30 @@ module ReVIEW
46
49
  @output.string
47
50
  end
48
51
 
49
- def print(*s)
50
- if @param["outencoding"] =~ /^EUC$/i
51
- @output.print(NKF.nkf("-W, -e", *s))
52
- elsif @param["outencoding"] =~ /^SJIS$/i
53
- @output.print(NKF.nkf("-W, -s", *s))
54
- elsif @param["outencoding"] =~ /^JIS$/i
55
- @output.print(NKF.nkf("-W, -j", *s))
52
+ alias :raw_result result
53
+
54
+ def convert_outencoding(*s)
55
+ if ReVIEW.book.param["outencoding"] =~ /^EUC$/i
56
+ NKF.nkf("-W, -e", *s)
57
+ elsif ReVIEW.book.param["outencoding"] =~ /^SJIS$/i
58
+ NKF.nkf("-W, -s", *s)
59
+ elsif ReVIEW.book.param["outencoding"] =~ /^JIS$/i
60
+ NKF.nkf("-W, -j", *s)
56
61
  else
57
- @output.print(*s)
62
+ ## for 1.9 compatibility
63
+ if s.size == 1
64
+ return s[0]
65
+ end
66
+ return *s
58
67
  end
59
68
  end
60
69
 
70
+ def print(*s)
71
+ @output.print(convert_outencoding(*s))
72
+ end
73
+
61
74
  def puts(*s)
62
- if @param["outencoding"] =~ /^EUC$/i
63
- @output.puts(NKF.nkf("-W, -e", *s))
64
- elsif @param["outencoding"] =~ /^SJIS$/i
65
- @output.puts(NKF.nkf("-W, -s", *s))
66
- elsif @param["outencoding"] =~ /^JIS$/i
67
- @output.puts(NKF.nkf("-W, -j", *s))
68
- else
69
- @output.puts(*s)
70
- end
75
+ @output.puts(convert_outencoding(*s))
71
76
  end
72
77
 
73
78
  def list(lines, id, caption)
@@ -93,15 +98,9 @@ module ReVIEW
93
98
  source_body lines
94
99
  end
95
100
 
96
- def image(lines, id, caption_or_metric, caption = nil)
97
- if caption
98
- metric = caption_or_metric
99
- else
100
- metric = nil
101
- caption = caption_or_metric
102
- end
101
+ def image(lines, id, caption, metric = nil)
103
102
  if @chapter.image(id).bound?
104
- image_image id, metric, caption
103
+ image_image id, caption, metric
105
104
  else
106
105
  warn "image not bound: #{id}" if @strict
107
106
  image_dummy id, caption, lines
@@ -131,15 +130,15 @@ module ReVIEW
131
130
  table_begin rows.first.size
132
131
  if sepidx
133
132
  sepidx.times do
134
- tr rows.shift.map {|s| th(compile_inline(s)) }
133
+ tr rows.shift.map {|s| th(s) }
135
134
  end
136
135
  rows.each do |cols|
137
- tr cols.map {|s| td(compile_inline(s)) }
136
+ tr cols.map {|s| td(s) }
138
137
  end
139
138
  else
140
139
  rows.each do |cols|
141
140
  h, *cs = *cols
142
- tr [th(compile_inline(h))] + cs.map {|s| td(compile_inline(s)) }
141
+ tr [th(h)] + cs.map {|s| td(s) }
143
142
  end
144
143
  end
145
144
  table_end
@@ -257,10 +256,41 @@ module ReVIEW
257
256
  puts "</div>"
258
257
  end
259
258
 
259
+ def inline_hd(id)
260
+ m = /\A(\w+)\|(.+)/.match(id)
261
+ chapter = @book.chapters.detect{|chap| chap.id == m[1]} if m && m[1]
262
+ return inline_hd_chap(chapter, m[2]) if chapter
263
+ return inline_hd_chap(@chapter, id)
264
+ end
265
+
260
266
  def raw(str)
261
267
  print str.gsub("\\n", "\n")
262
268
  end
263
269
 
270
+ def find_pathes(id)
271
+ if ReVIEW.book.param["subdirmode"].nil?
272
+ re = /\A#{@chapter.name}-#{id}(?i:#{@book.image_types.join('|')})\z/x
273
+ entries().select {|ent| re =~ ent }\
274
+ .sort_by {|ent| @book.image_types.index(File.extname(ent).downcase) }\
275
+ .map {|ent| "#{@book.basedir}/#{ent}" }
276
+ else
277
+ re = /\A#{id}(?i:#{@chapter.name.join('|')})\z/x
278
+ entries().select {|ent| re =~ ent }\
279
+ .sort_by {|ent| @book.image_types.index(File.extname(ent).downcase) }\
280
+ .map {|ent| "#{@book.asedir}/#{@chapter.name}/#{ent}" }
281
+ end
282
+ end
283
+
284
+ def entries
285
+ if ReVIEW.book.param["subdirmode"].nil?
286
+ @entries ||= Dir.entries(@book.basedir + @book.image_dir)
287
+ else
288
+ @entries ||= Dir.entries(File.join(@book.basedir + @book.image_dir, @chapter.name))
289
+ end
290
+ rescue Errno::ENOENT
291
+ @entries = []
292
+ end
293
+
264
294
  def warn(msg)
265
295
  $stderr.puts "#{@location}: warning: #{msg}"
266
296
  end
@@ -269,6 +299,21 @@ module ReVIEW
269
299
  raise ApplicationError, "#{@location}: error: #{msg}"
270
300
  end
271
301
 
302
+ def getChap(chapter = @chapter)
303
+ if ReVIEW.book.param["secnolevel"] > 0 && !chapter.number.nil? && !chapter.number.to_s.empty?
304
+ return "#{chapter.number}."
305
+ end
306
+ return ""
307
+ end
308
+
309
+ def extract_chapter_id(chap_ref)
310
+ m = /\A(\w+)\|(.+)/.match(chap_ref)
311
+ if m
312
+ return [@book.chapters.detect{|chap| chap.id == m[1]}, m[2]]
313
+ else
314
+ return [@chapter, chap_ref]
315
+ end
316
+ end
272
317
  end
273
318
 
274
319
  end # module ReVIEW
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  #
2
3
  # Copyright (c) 2002-2007 Minero Aoki
3
4
  # Copyright (c) 2009-2010 Minero Aoki, Kenshi Muto
@@ -27,7 +28,11 @@ module ReVIEW
27
28
  end
28
29
 
29
30
  def string
30
- "#{@filename}:#{@f.lineno}"
31
+ begin
32
+ "#{@filename}:#{@f.lineno}"
33
+ rescue
34
+ "#{@filename}:nil"
35
+ end
31
36
  end
32
37
 
33
38
  alias to_s string
@@ -42,14 +47,8 @@ module ReVIEW
42
47
 
43
48
  attr_reader :strategy
44
49
 
45
- def setParameter(param)
46
- @param = param
47
- @strategy.setParameter(@param)
48
- end
49
-
50
50
  def compile(chap)
51
51
  @chapter = chap
52
- @chapter.setParameter(@param)
53
52
  do_compile
54
53
  @strategy.result
55
54
  end
@@ -141,17 +140,24 @@ module ReVIEW
141
140
  defblock :listnum, 2
142
141
  defblock :emlistnum, 0..1
143
142
  defblock :bibpaper, 2..3, true
143
+ defblock :doorquote, 1
144
+ defblock :talk, 0
145
+ defblock :texequation, 0
146
+
144
147
  defblock :address, 0
145
148
  defblock :blockquote, 0
146
149
  defblock :bpo, 0
147
150
  defblock :flushright, 0
148
151
  defblock :note, 0..1
152
+ defblock :box, 0..1
149
153
 
150
154
  defsingle :footnote, 2
151
155
  defsingle :comment, 1
152
156
  defsingle :noindent, 0
153
157
  defsingle :linebreak, 0
154
158
  defsingle :pagebreak, 0
159
+ defsingle :indepimage, 1..3
160
+ defsingle :numberlessimage, 1..3
155
161
  defsingle :hr, 0
156
162
  defsingle :parasep, 0
157
163
  defsingle :label, 1
@@ -173,6 +179,7 @@ module ReVIEW
173
179
  definline :dtp
174
180
  definline :code
175
181
  definline :bib
182
+ definline :hd
176
183
  definline :href
177
184
  definline :recipe
178
185
 
@@ -194,8 +201,15 @@ module ReVIEW
194
201
  definline :sub
195
202
  definline :tt
196
203
  definline :i
197
-
204
+ definline :tti
205
+ definline :ttb
206
+ definline :u
198
207
  definline :raw
208
+ definline :br
209
+ definline :m
210
+ definline :uchar
211
+ definline :idx
212
+ definline :hidx
199
213
 
200
214
  private
201
215
 
@@ -209,13 +223,9 @@ module ReVIEW
209
223
  compile_headline f.gets
210
224
  when %r<\A\s+\*>
211
225
  compile_ulist f
212
- when %r<\A\s+□>
213
- compile_multichoice f
214
- when %r<\A\s+○>
215
- compile_singlechoice f
216
226
  when %r<\A\s+\d+\.>
217
227
  compile_olist f
218
- when %r<\A:\s>
228
+ when %r<\A\s*:\s>
219
229
  compile_dlist f
220
230
  when %r<\A//\}>
221
231
  error 'block end seen but not opened'
@@ -248,23 +258,34 @@ module ReVIEW
248
258
  end
249
259
 
250
260
  def compile_headline(line)
261
+ @headline_indexs ||= [@chapter.number.to_i - 1]
251
262
  m = /\A(=+)(?:\[(.+?)\])?(?:\{(.+?)\})?(.*)/.match(line)
252
263
  level = m[1].size
253
264
  tag = m[2]
254
265
  label = m[3]
255
266
  caption = m[4].strip
256
- while @tagged_section.last and @tagged_section.last[1] >= level
257
- close_tagged_section(* @tagged_section.pop)
258
- end
267
+ index = level - 1
259
268
  if tag
260
269
  open_tagged_section tag, level, label, caption
261
270
  else
262
- @strategy.headline level, label, @strategy.text(caption)
271
+ if @headline_indexs.size > (index + 1)
272
+ @headline_indexs = @headline_indexs[0..index]
273
+ end
274
+ @headline_indexs[index] = 0 if @headline_indexs[index].nil?
275
+ @headline_indexs[index] += 1
276
+ while @tagged_section.last and @tagged_section.last[1] >= level
277
+ close_tagged_section(* @tagged_section.pop)
278
+ end
279
+ if ReVIEW.book.param["hdnumberingmode"]
280
+ caption = @chapter.on_CHAPS? ? "#{@headline_indexs.join('.')} #{caption}" : caption
281
+ warn "--hdnumberingmode is deprecated. use --level option."
282
+ end
283
+ @strategy.headline level, label, caption
263
284
  end
264
285
  end
265
286
 
266
287
  def headline(level, label, caption)
267
- @strategy.headline level, label, @strategy.text(caption)
288
+ @strategy.headline level, label, caption
268
289
  end
269
290
 
270
291
  def tagged_section_init
@@ -279,7 +300,7 @@ module ReVIEW
279
300
  return
280
301
  end
281
302
  @tagged_section.push [tag, level]
282
- @strategy.__send__ mid, level, label, @strategy.text(caption)
303
+ @strategy.__send__ mid, level, label, caption
283
304
  end
284
305
 
285
306
  def close_tagged_section(tag, level)
@@ -309,30 +330,6 @@ module ReVIEW
309
330
  @strategy.ul_end
310
331
  end
311
332
 
312
- def compile_multichoice(f)
313
- @strategy.choice_multi_begin
314
- f.while_match(/\A\s+□/) do |line|
315
- buf = [text(line.sub(/□/, '').strip)]
316
- f.while_match(/\A\s+(?!□)\S/) do |cont|
317
- buf.push text(cont.strip)
318
- end
319
- @strategy.ul_item buf
320
- end
321
- @strategy.choice_multi_end
322
- end
323
-
324
- def compile_singlechoice(f)
325
- @strategy.choice_single_begin
326
- f.while_match(/\A\s+○/) do |line|
327
- buf = [text(line.sub(/○/, '').strip)]
328
- f.while_match(/\A\s+(?!○)\S/) do |cont|
329
- buf.push text(cont.strip)
330
- end
331
- @strategy.ul_item buf
332
- end
333
- @strategy.choice_single_end
334
- end
335
-
336
333
  def compile_olist(f)
337
334
  @strategy.ol_begin
338
335
  f.while_match(/\A\s+\d+\./) do |line|
@@ -348,9 +345,9 @@ module ReVIEW
348
345
 
349
346
  def compile_dlist(f)
350
347
  @strategy.dl_begin
351
- while /\A:/ =~ f.peek
352
- @strategy.dt text(f.gets.sub(/:/, '').strip)
353
- @strategy.dd f.break(/\A\S/).map {|line| text(line.strip) }
348
+ while /\A\s*:/ =~ f.peek
349
+ @strategy.dt text(f.gets.sub(/\A\s*:/, '').strip)
350
+ @strategy.dd f.break(/\A(\S|\s*:)/).map {|line| text(line.strip) }
354
351
  f.skip_blank_lines
355
352
  end
356
353
  @strategy.dl_end
@@ -368,7 +365,7 @@ module ReVIEW
368
365
  def read_command(f)
369
366
  line = f.gets
370
367
  name = line.slice(/[a-z]+/).intern
371
- args = parse_args(line.sub(%r<\A//[a-z]+>, '').rstrip.chomp('{'))
368
+ args = parse_args(line.sub(%r<\A//[a-z]+>, '').rstrip.chomp('{'), name)
372
369
  lines = block_open?(line) ? read_block(f) : nil
373
370
  return name, args, lines
374
371
  end
@@ -391,7 +388,7 @@ module ReVIEW
391
388
  buf
392
389
  end
393
390
 
394
- def parse_args(str)
391
+ def parse_args(str, name=nil)
395
392
  return [] if str.empty?
396
393
  unless str[0,1] == '[' and str[-1,1] == ']'
397
394
  error "argument syntax error: #{str.inspect}"
@@ -1,5 +1,5 @@
1
1
  # epubbuilder.rb
2
- # derived from htmlbuider.rb
2
+ # just for compatibility
3
3
  #
4
4
  # Copyright (c) 2010 Kenshi Muto
5
5
  #
@@ -8,685 +8,11 @@
8
8
  # the GNU LGPL, Lesser General Public License version 2.1.
9
9
  #
10
10
 
11
- require 'review/builder'
12
- require 'review/htmlutils'
13
- require 'review/htmllayout'
14
- require 'review/textutils'
15
11
  require 'review/htmlbuilder'
16
12
 
17
13
  module ReVIEW
18
14
 
19
15
  class EPUBBuilder < HTMLBuilder
20
-
21
- [:u, :tti, :idx, :hidx].each {|e|
22
- Compiler.definline(e)
23
- }
24
-
25
- Compiler.defsingle(:indepimage, 1)
26
- Compiler.defblock(:memo, 0..1)
27
- Compiler.defblock(:tip, 0..1)
28
- Compiler.defblock(:info, 0..1)
29
- Compiler.defblock(:planning, 0..1)
30
- Compiler.defblock(:best, 0..1)
31
- Compiler.defblock(:important, 0..1)
32
- Compiler.defblock(:security, 0..1)
33
- Compiler.defblock(:caution, 0..1)
34
- Compiler.defblock(:notice, 0..1)
35
- Compiler.defblock(:point, 0..1)
36
- Compiler.defblock(:shoot, 0..1)
37
-
38
- def builder_init(no_error = false)
39
- @no_error = no_error
40
- @section = 0
41
- @subsection = 0
42
- @subsubsection = 0
43
- @subsubsubsection = 0
44
- end
45
- private :builder_init
46
-
47
- def extname
48
- '.html'
49
- end
50
-
51
- def raw_result
52
- @output.string
53
- end
54
-
55
- def result
56
- layout_file = File.join(@book.basedir, "layouts", "layout.erb")
57
- if File.exists?(layout_file)
58
- messages() +
59
- HTMLLayout.new(@output.string, @chapter.title, layout_file).result
60
- else
61
- # FIXME
62
- header = <<EOT
63
- <?xml version="1.0" encoding="UTF-8"?>
64
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
65
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="ja">
66
- <head>
67
- <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
68
- <meta http-equiv="Content-Style-Type" content="text/css"/>
69
- EOT
70
- unless @param["stylesheet"].nil?
71
- header += <<EOT
72
- <link rel="stylesheet" type="text/css" href="#{@param["stylesheet"]}"/>
73
- EOT
74
- end
75
- header += <<EOT
76
- <meta name="generator" content="ReVIEW EPUB Maker"/>
77
- <title>#{@chapter.title}</title>
78
- </head>
79
- <body>
80
- EOT
81
- footer = <<EOT
82
- </body>
83
- </html>
84
- EOT
85
- header + messages() + @output.string + footer
86
- end
87
- end
88
-
89
- def headline_prefix(level)
90
- anchor = ""
91
- case level
92
- when 1
93
- @section = 0
94
- @subsection = 0
95
- @subsubsection = 0
96
- @subsubsubsection = 0
97
- anchor = "#{@chapter.number}"
98
- if @param["secnolevel"] >= 1
99
- if @chapter.number.to_s =~ /\A\d+$/
100
- prefix = "第#{@chapter.number}章 "
101
- elsif !@chapter.number.nil? && !@chapter.number.to_s.empty?
102
- prefix = "#{@chapter.number} "
103
- end
104
- end
105
- when 2
106
- @section += 1
107
- @subsection = 0
108
- @subsubsection = 0
109
- @subsubsubsection = 0
110
- anchor = "#{@chapter.number}-#{@section}"
111
- if @param["secnolevel"] >= 2
112
- if @chapter.number.to_s =~ /\A\d+$/
113
- prefix = "#{@chapter.number}.#{@section} "
114
- elsif !@chapter.number.nil? && !@chapter.number.to_s.empty?
115
- prefix = "#{@chapter.number}.#{@section} "
116
- end
117
- end
118
- when 3
119
- @subsection += 1
120
- @subsubsection = 0
121
- @subsubsubsection = 0
122
- anchor = "#{@chapter.number}-#{@section}-#{@subsection}"
123
- if @param["secnolevel"] >= 3
124
- if @chapter.number.to_s =~ /\A\d+$/
125
- prefix = "#{@chapter.number}.#{@section}.#{@subsection} "
126
- elsif !@chapter.number.nil? && !@chapter.number.to_s.empty?
127
- prefix = "#{@chapter.number}.#{@section}.#{@subsection} "
128
- end
129
- end
130
- when 4
131
- @subsubsection += 1
132
- @subsubsubsection = 0
133
- anchor = "#{@chapter.number}-#{@section}-#{@subsection}-#{@subsubsection}"
134
- if @param["secnolevel"] >= 4
135
- if @chapter.number.to_s =~ /\A\d+$/
136
- prefix = "#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection} "
137
- elsif !@chapter.number.nil? && !@chapter.number.to_s.empty?
138
- prefix = "#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection} "
139
- end
140
- end
141
- when 5
142
- @subsubsubsection += 1
143
- anchor = "#{@chapter.number}-#{@section}-#{@subsection}-#{@subsubsection}-#{@subsubsubsection}"
144
- if @param["secnolevel"] >= 5
145
- if @chapter.number.to_s =~ /\A\d+$/
146
- prefix = "#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection} "
147
- elsif !@chapter.number.nil? && !@chapter.number.to_s.empty?
148
- prefix = "#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection} "
149
- end
150
- end
151
- end
152
- [prefix, anchor]
153
- end
154
- private :headline_prefix
155
-
156
- def headline(level, label, caption)
157
- prefix, anchor = headline_prefix(level)
158
- puts '' if level > 1
159
- a_id = ""
160
- unless anchor.empty?
161
- a_id = "<a id=\"h#{anchor}\" />"
162
- end
163
- if caption.empty?
164
- puts a_id unless label.nil?
165
- else
166
- if label.nil?
167
- puts "<h#{level}>#{a_id}#{prefix}#{escape_html(caption)}</h#{level}>"
168
- else
169
- puts "<h#{level} id='#{label}'>#{a_id}#{prefix}#{escape_html(caption)}</h#{level}>"
170
- end
171
- end
172
- end
173
-
174
- def column_begin(level, label, caption)
175
- puts "<div class='column'>"
176
- headline(level, label, caption) # FIXME
177
- end
178
-
179
- def column_end(level)
180
- puts '</div>'
181
- end
182
-
183
- def xcolumn_begin(level, label, caption)
184
- puts "<div class='xcolumn'>"
185
- headline(level, label, caption) # FIXME
186
- end
187
-
188
- def xcolumn_end(level)
189
- puts '</div>'
190
- end
191
-
192
- def ref_begin(level, label, caption)
193
- print "<div class='reference'>"
194
- headline(level, label, caption)
195
- end
196
-
197
- def ref_end(level)
198
- puts '</div>'
199
- end
200
-
201
- def sup_begin(level, label, caption)
202
- print "<div class='supplement'>"
203
- headline(level, label, caption)
204
- end
205
-
206
- def sup_end(level)
207
- puts '</div>'
208
- end
209
-
210
- def tsize(str)
211
- # null
212
- end
213
-
214
- def captionblock(type, lines, caption)
215
- puts "<div class=\"#{type}\">"
216
- unless caption.nil?
217
- puts "<p class=\"#{type}-title\">#{escape_html(caption)}</p>"
218
- end
219
- lines.each {|l|
220
- puts "<p>#{l}</p>"
221
- }
222
- puts '</div>'
223
- end
224
-
225
- def memo(lines, caption = nil)
226
- captionblock("memo", lines, caption)
227
- end
228
-
229
- def tip(lines, caption = nil)
230
- captionblock("tip", lines, caption)
231
- end
232
-
233
- def info(lines, caption = nil)
234
- captionblock("info", lines, caption)
235
- end
236
-
237
- def planning(lines, caption = nil)
238
- captionblock("planning", lines, caption)
239
- end
240
-
241
- def best(lines, caption = nil)
242
- captionblock("best", lines, caption)
243
- end
244
-
245
- def important(lines, caption = nil)
246
- captionblock("important", lines, caption)
247
- end
248
-
249
- def security(lines, caption = nil)
250
- captionblock("security", lines, caption)
251
- end
252
-
253
- def caution(lines, caption = nil)
254
- captionblock("caution", lines, caption)
255
- end
256
-
257
- def notice(lines, caption = nil)
258
- captionblock("notice", lines, caption)
259
- end
260
-
261
- def point(lines, caption = nil)
262
- captionblock("point", lines, caption)
263
- end
264
-
265
- def shot(lines, caption = nil)
266
- captionblock("shoot", lines, caption)
267
- end
268
-
269
- def list(lines, id, caption)
270
- puts '<div class="caption-code">'
271
- begin
272
- list_header id, caption
273
- rescue KeyError
274
- error "no such list: #{id}"
275
- end
276
- list_body lines
277
- puts '</div>'
278
- end
279
-
280
- def list_header(id, caption)
281
- puts %Q[<p class="listcaption">リスト#{getChap}#{@chapter.list(id).number}: #{escape_html(caption)}</p>]
282
- end
283
-
284
- def list_body(lines)
285
- puts '<pre class="list">'
286
- lines.each do |line|
287
- puts detab(line)
288
- end
289
- puts '</pre>'
290
- end
291
-
292
- def source(lines, caption)
293
- puts '<div class="caption-code">'
294
- source_header caption
295
- source_body lines
296
- puts '</div>'
297
- end
298
-
299
- def source_header(caption)
300
- puts %Q[<p class="sourcecaption">#{escape_html(caption)}</p>]
301
- end
302
-
303
- def source_body(lines)
304
- puts '<pre class="source">'
305
- lines.each do |line|
306
- puts detab(line)
307
- end
308
- puts '</pre>'
309
- end
310
-
311
- def listnum(lines, id, caption)
312
- puts '<div class="code">'
313
- begin
314
- list_header id, caption
315
- rescue KeyError
316
- error "no such list: #{id}"
317
- end
318
- listnum_body lines
319
- puts '</div>'
320
- end
321
-
322
- def listnum_body(lines)
323
- puts '<pre class="list">'
324
- lines.each_with_index do |line, i|
325
- puts detab((i+1).to_s.rjust(2) + ": " + line)
326
- end
327
- puts '</pre>'
328
- end
329
-
330
- def emlist(lines, caption = nil)
331
- puts '<div class="code">'
332
- puts %Q(<p class="emlistcaption">#{caption}</p>) unless caption.nil?
333
- puts '<pre class="emlist">'
334
- lines.each do |line|
335
- puts detab(line)
336
- end
337
- puts '</pre>'
338
- puts '</div>'
339
- end
340
-
341
- def emlistnum(lines)
342
- puts '<div class="code">'
343
- puts '<pre class="emlist">'
344
- lines.each_with_index do |line, i|
345
- puts detab((i+1).to_s.rjust(2) + ": " + line)
346
- end
347
- puts '</pre>'
348
- puts '</div>'
349
- end
350
-
351
- def cmd(lines)
352
- puts '<div class="code">'
353
- puts '<pre class="cmd">'
354
- lines.each do |line|
355
- puts detab(line)
356
- end
357
- puts '</pre>'
358
- puts '</div>'
359
- end
360
-
361
- def quotedlist(lines, css_class)
362
- puts %Q[<blockquote><pre class="#{css_class}">]
363
- lines.each do |line|
364
- puts detab(line)
365
- end
366
- puts '</pre></blockquote>'
367
- end
368
- private :quotedlist
369
-
370
- def quote(lines)
371
- puts "<blockquote>#{lines.join("\n")}</blockquote>"
372
- end
373
-
374
- def image_image(id, metric, caption)
375
- puts %Q[<div class="image">]
376
- puts %Q[<img src="#{@chapter.image(id).path.sub(/^\.\//, "")}" alt="(#{escape_html(caption)})" />]
377
- image_header id, caption
378
- puts %Q[</div>]
379
- end
380
-
381
- def image_dummy(id, caption, lines)
382
- puts %Q[<div class="image">]
383
- puts %Q[<pre class="dummyimage">]
384
- lines.each do |line|
385
- puts detab(line)
386
- end
387
- puts %Q[</pre>]
388
- image_header id, caption
389
- puts %Q[</div>]
390
- end
391
-
392
- def image_header(id, caption)
393
- puts %Q[<p class="imagecaption">]
394
- puts %Q[図#{getChap}#{@chapter.image(id).number}: #{escape_html(caption)}]
395
- puts %Q[</p>]
396
- end
397
-
398
- def table(lines, id = nil, caption = nil)
399
- rows = []
400
- sepidx = nil
401
- lines.each_with_index do |line, idx|
402
- if /\A[\=\-]{12}/ =~ line
403
- # just ignore
404
- #error "too many table separator" if sepidx
405
- sepidx ||= idx
406
- next
407
- end
408
- rows.push line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') }
409
- end
410
- rows = adjust_n_cols(rows)
411
-
412
- begin
413
- table_header id, caption unless caption.nil?
414
- rescue KeyError => err
415
- error "no such table: #{id}"
416
- end
417
- table_begin rows.first.size
418
- return if rows.empty?
419
- if sepidx
420
- sepidx.times do
421
- tr rows.shift.map {|s| th(compile_inline(s)) }
422
- end
423
- rows.each do |cols|
424
- tr cols.map {|s| td(compile_inline(s)) }
425
- end
426
- else
427
- rows.each do |cols|
428
- h, *cs = *cols
429
- tr [th(compile_inline(h))] + cs.map {|s| td(compile_inline(s)) }
430
- end
431
- end
432
- table_end
433
- end
434
-
435
- def table_header(id, caption)
436
- puts %Q[<p class="tablecaption">表#{getChap}#{@chapter.table(id).number}: #{escape_html(caption)}</p>]
437
- end
438
-
439
- def table_begin(ncols)
440
- puts '<table>'
441
- end
442
-
443
- def tr(rows)
444
- puts "<tr>#{rows.join('')}</tr>"
445
- end
446
-
447
- def th(str)
448
- "<th>#{str}</th>"
449
- end
450
-
451
- def td(str)
452
- "<td>#{str}</td>"
453
- end
454
-
455
- def table_end
456
- puts '</table>'
457
- end
458
-
459
- def comment(str)
460
- puts %Q(<!-- #{escape_html(str)} -->)
461
- end
462
-
463
- def footnote(id, str)
464
- puts %Q(<div class="footnote"><p class="footnote"><a id="fn-#{id}">[*#{@chapter.footnote(id).number}] #{escape_html(str)}</a></p></div>)
465
- end
466
-
467
- def hr
468
- puts "<hr/>"
469
- end
470
-
471
- def label(id)
472
- puts %Q(<a id="#{id}" />)
473
- end
474
-
475
- def linebreak
476
- puts "<br />"
477
- end
478
-
479
- def pagebreak
480
- puts %Q(<br class="pagebreak" />)
481
- end
482
-
483
- def bpo(lines)
484
- puts "<bpo>"
485
- lines.each do |line|
486
- puts detab(line)
487
- end
488
- puts "</bpo>"
489
- end
490
-
491
- def flushright(lines)
492
- puts "<p align='right'>#{lines.join("\n")}</p>"
493
- end
494
-
495
- def note(lines, caption = nil)
496
- puts '<div class="note">'
497
- puts "<p class='notecaption'>#{escape_html(caption)}</p>" unless caption.nil?
498
- puts "#{lines.join("\n")}</div>"
499
- end
500
-
501
- def inline_fn(id)
502
- %Q(<a href="\#fn-#{id}">*#{@chapter.footnote(id).number}</a>)
503
- end
504
-
505
- def compile_ruby(base, ruby)
506
- %Q[<ruby><rb>{escape_html(base)}</rb><rp>(</rp><rt>#{ruby}</rt><rp>)</rp></ruby>]
507
- end
508
-
509
- def compile_kw(word, alt)
510
- '<span class="kw">' +
511
- if alt
512
- #then escape_html(word + sprintf(@locale[:parens], alt.strip))
513
- then escape_html(word + " (#{alt.strip})")
514
- else escape_html(word)
515
- end +
516
- "</span><!-- IDX:#{escape_html(word)} -->"
517
- end
518
-
519
- def compile_href(url, label)
520
- %Q(<a href="#{escape_html(url)}" class="link">#{label.nil? ? escape_html(url) : escape_html(label)}</a>)
521
- end
522
-
523
- def inline_i(str)
524
- %Q(<i>#{escape_html(str)}</i>)
525
- end
526
-
527
- def inline_b(str)
528
- %Q(<b>#{escape_html(str)}</b>)
529
- end
530
-
531
- def inline_ami(str)
532
- %Q(<span class="ami">#{escape_html(str)}</span>)
533
- end
534
-
535
- def inline_tti(str)
536
- %Q(<tt><i>#{escape_html(str)}</i></tt>)
537
- end
538
-
539
- def inline_dtp(arg)
540
- # ignore all
541
- ''
542
- end
543
-
544
- def inline_code(str)
545
- %Q(<span class="inline-code">#{str}</span>)
546
- end
547
-
548
- def inline_idx(str)
549
- %Q(#{escape_html(str)}<!-- IDX:#{escape_html(str)} -->)
550
- end
551
-
552
- def inline_hidx(str)
553
- %Q(<!-- IDX:#{escape_html(str)} -->)
554
- end
555
-
556
- def text(str)
557
- str
558
- end
559
-
560
- def bibpaper_header(id, caption)
561
- puts %Q(<a id="bib-#{id}">)
562
- puts "[#{@chapter.bibpaper(id).number}] #{caption}"
563
- puts %Q(</a>)
564
- end
565
-
566
- def bibpaper_bibpaper(id, caption, lines)
567
- puts %Q(<p>)
568
- lines.each do |line|
569
- puts detab(line)
570
- end
571
- puts %Q(</p>)
572
- end
573
-
574
- def noindent
575
- # dummy
576
- end
577
-
578
- def inline_bib(id)
579
- %Q(<a href=".#{@book.bib_file.gsub(/re$/, "html")}\#bib-#{id}">[#{@chapter.bibpaper(id).number}]</a>)
580
- end
581
-
582
- def nofunc_text(str)
583
- escape_html(str)
584
- end
585
-
586
- def inline_list(id)
587
- "リスト#{getChap}#{@chapter.list(id).number}"
588
- rescue KeyError
589
- error "unknown list: #{id}"
590
- nofunc_text("[UnknownList:#{id}]")
591
- end
592
-
593
- def inline_img(id)
594
- "図#{getChap}#{@chapter.image(id).number}"
595
- rescue KeyError
596
- error "unknown image: #{id}"
597
- nofunc_text("[UnknownImage:#{id}]")
598
- end
599
-
600
- def inline_table(id)
601
- "表#{getChap}#{@chapter.table(id).number}"
602
- rescue KeyError
603
- error "unknown table: #{id}"
604
- nofunc_text("[UnknownTable:#{id}]")
605
- end
606
-
607
- def inline_asis(str, tag)
608
- %Q(<#{tag}>#{escape_html(str)}</#{tag}>)
609
- end
610
-
611
- def inline_abbr(str)
612
- inline_asis(str, "abbr")
613
- end
614
-
615
- def inline_acronym(str)
616
- inline_asis(str, "acronym")
617
- end
618
-
619
- def inline_cite(str)
620
- inline_asis(str, "cite")
621
- end
622
-
623
- def inline_dfn(str)
624
- inline_asis(str, "dfn")
625
- end
626
-
627
- def inline_em(str)
628
- inline_asis(str, "em")
629
- end
630
-
631
- def inline_kbd(str)
632
- inline_asis(str, "kbd")
633
- end
634
-
635
- def inline_samp(str)
636
- inline_asis(str, "samp")
637
- end
638
-
639
- def inline_strong(str)
640
- inline_asis(str, "strong")
641
- end
642
-
643
- def inline_var(str)
644
- inline_asis(str, "var")
645
- end
646
-
647
- def inline_big(str)
648
- inline_asis(str, "big")
649
- end
650
-
651
- def inline_small(str)
652
- inline_asis(str, "small")
653
- end
654
-
655
- def inline_sub(str)
656
- inline_asis(str, "sub")
657
- end
658
-
659
- def inline_sup(str)
660
- inline_asis(str, "sup")
661
- end
662
-
663
- def inline_tt(str)
664
- inline_asis(str, "tt")
665
- end
666
-
667
- def inline_del(str)
668
- inline_asis(str, "del")
669
- end
670
-
671
- def inline_ins(str)
672
- inline_asis(str, "ins")
673
- end
674
-
675
- def inline_u(str)
676
- %Q(<span class="u">#{escape_html(str)}</span>)
677
- end
678
-
679
- def inline_recipe(str)
680
- # FIXME
681
- %Q(<span class="recipe">「#{escape_html(str)}」</span>)
682
- end
683
-
684
- def getChap
685
- if @param["secnolevel"] > 0 && !@chapter.number.nil? && !@chapter.number.to_s.empty?
686
- return "#{@chapter.number}."
687
- end
688
- return ""
689
- end
690
16
  end
691
17
 
692
18
  end # module ReVIEW