review 4.1.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.rubocop.yml +4 -1
  4. data/NEWS.ja.md +29 -0
  5. data/NEWS.md +29 -0
  6. data/bin/review-index +2 -89
  7. data/bin/review-vol +4 -78
  8. data/doc/config.yml.sample +18 -5
  9. data/doc/config.yml.sample-simple +1 -1
  10. data/doc/pdfmaker.ja.md +42 -0
  11. data/doc/pdfmaker.md +41 -0
  12. data/doc/quickstart.ja.md +8 -5
  13. data/doc/quickstart.md +7 -4
  14. data/lib/review/book/base.rb +2 -4
  15. data/lib/review/book/compilable.rb +1 -5
  16. data/lib/review/book/page_metric.rb +7 -7
  17. data/lib/review/book/part.rb +6 -3
  18. data/lib/review/book/volume.rb +3 -4
  19. data/lib/review/builder.rb +23 -10
  20. data/lib/review/compiler.rb +9 -9
  21. data/lib/review/configure.rb +6 -0
  22. data/lib/review/epubmaker.rb +1 -1
  23. data/lib/review/htmlbuilder.rb +56 -16
  24. data/lib/review/idgxmlbuilder.rb +63 -22
  25. data/lib/review/latexbuilder.rb +70 -19
  26. data/lib/review/makerhelper.rb +18 -1
  27. data/lib/review/pdfmaker.rb +8 -1
  28. data/lib/review/plaintextbuilder.rb +41 -11
  29. data/lib/review/textmaker.rb +1 -1
  30. data/lib/review/textutils.rb +2 -3
  31. data/lib/review/tocprinter.rb +231 -102
  32. data/lib/review/topbuilder.rb +47 -13
  33. data/lib/review/version.rb +1 -1
  34. data/lib/review/volumeprinter.rb +99 -0
  35. data/lib/review/webmaker.rb +1 -1
  36. data/lib/review/webtocprinter.rb +38 -35
  37. data/review.gemspec +1 -1
  38. data/samples/sample-book/src/config.yml +1 -1
  39. data/templates/web/html/layout-html5.html.erb +2 -2
  40. data/test/test_book.rb +1 -1
  41. data/test/test_book_part.rb +3 -3
  42. data/test/test_helper.rb +4 -1
  43. data/test/test_htmlbuilder.rb +179 -0
  44. data/test/test_idgxmlbuilder.rb +143 -0
  45. data/test/test_latexbuilder.rb +223 -0
  46. data/test/test_pdfmaker.rb +17 -0
  47. data/test/test_plaintextbuilder.rb +99 -0
  48. data/test/test_topbuilder.rb +116 -2
  49. data/test/test_webtocprinter.rb +66 -34
  50. metadata +3 -5
  51. data/lib/review/tocparser.rb +0 -275
  52. data/test/test_tocparser.rb +0 -25
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2008-2019 Minero Aoki, Kenshi Muto
1
+ # Copyright (c) 2008-2020 Minero Aoki, Kenshi Muto
2
2
  # 2002-2006 Minero Aoki
3
3
  #
4
4
  # This program is free software.
@@ -95,12 +95,18 @@ module ReVIEW
95
95
  blank
96
96
  puts "◆→開始:#{@titles['list']}←◆"
97
97
  begin
98
- list_header(id, caption, lang)
98
+ if caption_top?('list')
99
+ list_header(id, caption, lang)
100
+ blank
101
+ end
102
+ list_body(id, lines, lang)
103
+ unless caption_top?('list')
104
+ blank
105
+ list_header(id, caption, lang)
106
+ end
99
107
  rescue KeyError
100
108
  error "no such list: #{id}"
101
109
  end
102
- blank
103
- list_body(id, lines, lang)
104
110
  puts "◆→終了:#{@titles['list']}←◆"
105
111
  blank
106
112
  end
@@ -122,8 +128,13 @@ module ReVIEW
122
128
  def base_block(type, lines, caption = nil)
123
129
  blank
124
130
  puts "◆→開始:#{@titles[type]}←◆"
125
- puts "■#{compile_inline(caption)}" if caption.present?
131
+ if caption_top?('list') && caption.present?
132
+ puts "■#{compile_inline(caption)}"
133
+ end
126
134
  puts lines.join("\n")
135
+ if !caption_top?('list') && caption.present?
136
+ puts "■#{compile_inline(caption)}"
137
+ end
127
138
  puts "◆→終了:#{@titles[type]}←◆"
128
139
  blank
129
140
  end
@@ -140,10 +151,15 @@ module ReVIEW
140
151
  def emlistnum(lines, caption = nil, _lang = nil)
141
152
  blank
142
153
  puts "◆→開始:#{@titles['emlist']}←◆"
143
- puts "■#{compile_inline(caption)}" if caption.present?
154
+ if caption_top?('list') && caption.present?
155
+ puts "■#{compile_inline(caption)}"
156
+ end
144
157
  lines.each_with_index do |line, i|
145
158
  puts((i + 1).to_s.rjust(2) + ": #{line}")
146
159
  end
160
+ if !caption_top?('list') && caption.present?
161
+ puts "■#{compile_inline(caption)}"
162
+ end
147
163
  puts "◆→終了:#{@titles['emlist']}←◆"
148
164
  blank
149
165
  end
@@ -152,12 +168,18 @@ module ReVIEW
152
168
  blank
153
169
  puts "◆→開始:#{@titles['list']}←◆"
154
170
  begin
155
- list_header(id, caption, lang)
171
+ if caption_top?('list') && caption.present?
172
+ list_header(id, caption, lang)
173
+ blank
174
+ end
175
+ listnum_body(lines, lang)
176
+ if !caption_top?('list') && caption.present?
177
+ blank
178
+ list_header(id, caption, lang)
179
+ end
156
180
  rescue KeyError
157
181
  error "no such list: #{id}"
158
182
  end
159
- blank
160
- listnum_body(lines, lang)
161
183
  puts "◆→終了:#{@titles['list']}←◆"
162
184
  blank
163
185
  end
@@ -173,8 +195,10 @@ module ReVIEW
173
195
  metrics = " #{metrics}" if metrics.present?
174
196
  blank
175
197
  puts "◆→開始:#{@titles['image']}←◆"
176
- image_header(id, caption)
177
- blank
198
+ if caption_top?('image')
199
+ image_header(id, caption)
200
+ blank
201
+ end
178
202
  if @chapter.image_bound?(id)
179
203
  puts "◆→#{@chapter.image(id).path}#{metrics}←◆"
180
204
  else
@@ -183,6 +207,10 @@ module ReVIEW
183
207
  puts line
184
208
  end
185
209
  end
210
+ unless caption_top?('image')
211
+ blank
212
+ image_header(id, caption)
213
+ end
186
214
  puts "◆→終了:#{@titles['image']}←◆"
187
215
  blank
188
216
  end
@@ -198,7 +226,7 @@ module ReVIEW
198
226
  def texequation(lines, id = nil, caption = '')
199
227
  blank
200
228
  puts "◆→開始:#{@titles['texequation']}←◆"
201
- texequation_header(id, caption)
229
+ texequation_header(id, caption) if caption_top?('equation')
202
230
 
203
231
  if @book.config['imgmath']
204
232
  fontsize = @book.config['imgmath_options']['fontsize'].to_f
@@ -214,6 +242,7 @@ module ReVIEW
214
242
  puts lines.join("\n")
215
243
  end
216
244
 
245
+ texequation_header(id, caption) unless caption_top?('equation')
217
246
  puts "◆→終了:#{@titles['texequation']}←◆"
218
247
  blank
219
248
  end
@@ -419,13 +448,18 @@ module ReVIEW
419
448
  metrics = parse_metric('top', metric)
420
449
  metrics = " #{metrics}" if metrics.present?
421
450
  blank
451
+ if caption_top?('image') && caption.present?
452
+ puts "図 #{compile_inline(caption)}"
453
+ end
422
454
  begin
423
455
  puts "◆→画像 #{@chapter.image(id).path.sub(%r{\A\./}, '')}#{metrics}←◆"
424
456
  rescue
425
457
  warn "image not bound: #{id}"
426
458
  puts "◆→画像 #{id}←◆"
427
459
  end
428
- puts "図 #{compile_inline(caption)}" if caption.present?
460
+ if !caption_top?('image') && caption.present?
461
+ puts "図 #{compile_inline(caption)}"
462
+ end
429
463
  blank
430
464
  end
431
465
 
@@ -1,3 +1,3 @@
1
1
  module ReVIEW
2
- VERSION = '4.1.0'.freeze
2
+ VERSION = '4.2.0'.freeze
3
3
  end
@@ -0,0 +1,99 @@
1
+ #
2
+ # Copyright (c) 2014-2020 Minero Aoki, Kenshi Muto
3
+ # 2003-2014 Minero Aoki
4
+ #
5
+ # This program is free software.
6
+ # You can distribute or modify this program under the terms of
7
+ # the GNU LGPL, Lesser General Public License version 2.1.
8
+ # For details of the GNU LGPL, see the file "COPYING".
9
+ #
10
+ require 'optparse'
11
+ require 'review'
12
+ require 'review/i18n'
13
+ require 'review/plaintextbuilder'
14
+
15
+ include ReVIEW::TextUtils
16
+
17
+ module ReVIEW
18
+ class VolumePrinter
19
+ def self.execute(*args)
20
+ new.execute(*args)
21
+ end
22
+
23
+ def initialize
24
+ @logger = ReVIEW.logger
25
+ @config = ReVIEW::Configure.values
26
+ @yamlfile = 'config.yml'
27
+ end
28
+
29
+ def execute(*args)
30
+ parse_options(args)
31
+ @book = ReVIEW::Book::Base.load
32
+ @book.config = @config
33
+ unless File.readable?(@yamlfile)
34
+ @logger.error("No such fiile or can't open #{@yamlfile}.")
35
+ exit 1
36
+ end
37
+ @book.load_config(@yamlfile)
38
+ I18n.setup(@book.config['language'])
39
+
40
+ begin
41
+ @book.each_part do |part|
42
+ if part.number
43
+ print_chapter_volume(part)
44
+ end
45
+ part.each_chapter do |chap|
46
+ print_chapter_volume(chap)
47
+ end
48
+ end
49
+ rescue ReVIEW::FileNotFound => e
50
+ @logger.error e
51
+ exit 1
52
+ end
53
+ puts '============================='
54
+ print_volume(@book.volume)
55
+ end
56
+
57
+ def parse_options(args)
58
+ opts = OptionParser.new
59
+ opts.version = ReVIEW::VERSION
60
+ opts.on('--yaml=YAML', 'Read configurations from YAML file.') { |yaml| @yamlfile = yaml }
61
+ opts.on('--help', 'Print this message and quit') do
62
+ puts opts.help
63
+ exit 0
64
+ end
65
+ begin
66
+ opts.parse!(args)
67
+ rescue OptionParser::ParseError => e
68
+ @logger.error e.message
69
+ $stderr.puts opts.help
70
+ exit 1
71
+ end
72
+ end
73
+
74
+ def print_chapter_volume(chap)
75
+ builder = ReVIEW::PLAINTEXTBuilder.new
76
+ builder.bind(ReVIEW::Compiler.new(builder), chap, nil)
77
+
78
+ vol = chap.volume
79
+ title = chap.format_number
80
+ unless title.empty?
81
+ title += ' '
82
+ end
83
+ begin
84
+ title += builder.compile_inline(chap.title)
85
+ rescue ReVIEW::ApplicationError => e
86
+ @logger.warn "#{chap.name} : #{e.message.sub(/.+error: /, '')}"
87
+ end
88
+
89
+ printf("%3dKB %6dC %5dL %3dP %s %-s\n",
90
+ vol.kbytes, vol.chars, vol.lines, vol.page,
91
+ "#{chap.name} ".ljust(15, '.'), title)
92
+ end
93
+
94
+ def print_volume(vol)
95
+ # total
96
+ printf("%3dKB %6dC %5dL %3dP\n", vol.kbytes, vol.chars, vol.lines, vol.page)
97
+ end
98
+ end
99
+ end
@@ -118,7 +118,7 @@ module ReVIEW
118
118
  copy_backmatter(@path)
119
119
 
120
120
  math_dir = "./#{@config['imagedir']}/_review_math"
121
- if @config['imgmath'] && File.exist?("#{math_dir}/__IMGMATH_BODY__.tex")
121
+ if @config['imgmath'] && File.exist?("#{math_dir}/__IMGMATH_BODY__.map")
122
122
  make_math_images(math_dir)
123
123
  end
124
124
 
@@ -6,49 +6,52 @@ module ReVIEW
6
6
  include HTMLUtils
7
7
 
8
8
  def self.book_to_string(book)
9
- io = StringIO.new
10
- ReVIEW::WEBTOCPrinter.new(1, {}, io).print_book(book)
11
- io.seek(0)
12
- io.read
9
+ ReVIEW::WEBTOCPrinter.new.print_book(book)
13
10
  end
14
11
 
15
12
  def print_book(book)
16
- @out.puts '<ul class="book-toc">'
17
- @out.puts %Q(<li><a href="index.html">TOP</a></li>\n)
18
- book.each_part do |part|
19
- print_part(part)
20
- end
21
- @out.puts '</ul>'
13
+ @book = book
14
+ @indent = nil
15
+ @upper = 1 # only part and chapter
16
+ print_result(build_result_array)
22
17
  end
23
18
 
24
- def print_part(part)
25
- if part.number
26
- if part.file?
27
- ext = part.book.config['htmlext'] || 'html'
28
- path = File.basename(part.path.sub(/\.re/, '.' + ext))
29
- @out.puts %Q(<li><a href="#{path}">#{h(I18n.t('part_short', part.number) + ' ' + part.title)}</a>\n<ul>\n)
19
+ def print_result(result_array)
20
+ content = <<EOT
21
+ <ul class="book-toc">
22
+ <li><a href="index.html">TOP</a></li>
23
+ EOT
24
+
25
+ path = ''
26
+ result_array.each do |result|
27
+ unless result[:headline]
28
+ result[:headline] = '-'
29
+ end
30
+
31
+ if result[:name]
32
+ path = "#{result[:name]}.#{@book.config['htmlext']}"
33
+ next
34
+ end
35
+
36
+ if result[:part]
37
+ if result[:part] == 'end'
38
+ content << "</ul></li>\n"
39
+ end
40
+ next
41
+ end
42
+
43
+ if path.start_with?('.')
44
+ content << "<li>#{escape(result[:headline])}"
30
45
  else
31
- @out.puts %Q(<li>#{h(I18n.t('part_short', part.number) + ' ' + part.title)}\n<ul>\n)
46
+ content << %Q(<li><a href="#{path}">#{escape(result[:headline])}</a>)
47
+ end
48
+ if result[:level] == 0
49
+ content << "\n<ul>" # part
50
+ else
51
+ content << "</li>\n"
32
52
  end
33
53
  end
34
- part.each_chapter do |chap|
35
- print_chapter(chap)
36
- end
37
- if part.number
38
- @out.puts "</ul>\n</li>\n"
39
- end
40
- end
41
-
42
- def print_chapter(chap)
43
- chap_node = TOCParser.chapter_node(chap)
44
- ext = chap.book.config['htmlext'] || 'html'
45
- path = File.basename(chap.path.sub(/\.re/, '.' + ext))
46
- label = if chap_node.number && chap.on_chaps?
47
- "#{I18n.t('chapter_short', chap.number)} #{chap.title}"
48
- else
49
- chap.title
50
- end
51
- @out.puts %Q(<li><a href="#{path}">#{h(label)}</a></li>\n)
54
+ content << "</ul>\n"
52
55
  end
53
56
  end
54
57
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.summary = 'Re:VIEW: a easy-to-use digital publishing system'
13
13
  gem.description = 'Re:VIEW is a digital publishing system for books and ebooks. It supports InDesign, EPUB and LaTeX.'
14
14
  gem.required_rubygems_version = Gem::Requirement.new('>= 0') if gem.respond_to?(:required_rubygems_version=)
15
- gem.date = '2020-02-29'
15
+ gem.date = '2020-06-29'
16
16
 
17
17
  gem.files = `git ls-files`.split("\n")
18
18
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -35,7 +35,7 @@ colophon: true
35
35
  # font_ext: ["ttf", "woff", "otf"]
36
36
  # catalogfile: catalog.yml
37
37
  # page_metric: A5
38
- # page_metric: [40,80,40,80,2]
38
+ # page_metric: [40,34,29,34]
39
39
  # direction: "ltr"
40
40
 
41
41
  epubmaker:
@@ -8,8 +8,8 @@
8
8
  <link rel="stylesheet" type="text/css" href="<%=h style %>" />
9
9
  <% end %>
10
10
  <% end%>
11
- <% if @next.present? %><link rel="next" title="<%= h(@next_title)%>" href="<%= h(@next.id.to_s+"."+@book.config['htmlext']) %>"><% end %>
12
- <% if @prev.present? %><link rel="prev" title="<%= h(@prev_title)%>" href="<%= h(@prev.id.to_s+"."+@book.config['htmlext']) %>"><% end %>
11
+ <% if @next.present? %><link rel="next" title="<%= h(@next_title)%>" href="<%= h(@next.id.to_s+"."+@book.config['htmlext']) %>" /><% end %>
12
+ <% if @prev.present? %><link rel="prev" title="<%= h(@prev_title)%>" href="<%= h(@prev.id.to_s+"."+@book.config['htmlext']) %>" /><% end %>
13
13
  <meta name="generator" content="Re:VIEW" />
14
14
  <title><%=h @title %> | <%=h @book.config.name_of("booktitle")%></title>
15
15
  </head>
@@ -587,7 +587,7 @@ EOC
587
587
  end
588
588
 
589
589
  def test_page_metric_config_array
590
- mktmpbookdir('config.yml' => "bookname: book\npage_metric: [46, 80, 30, 74, 2]\n") do |dir, _book, _files|
590
+ mktmpbookdir('config.yml' => "bookname: book\npage_metric: [50, 40, 36, 40, 1]\n") do |dir, _book, _files|
591
591
  book = Book::Base.new(dir)
592
592
  config_file = File.join(dir, 'config.yml')
593
593
  book.load_config(config_file)
@@ -46,8 +46,8 @@ class PartTest < Test::Unit::TestCase
46
46
 
47
47
  part = Book::Part.new(book, nil, chs)
48
48
  assert part.volume
49
- assert part.volume.bytes > 0
50
- assert part.volume.chars > 0
51
- assert part.volume.lines > 0
49
+ assert part.volume.bytes == 0
50
+ assert part.volume.chars == 0
51
+ assert part.volume.lines == 0
52
52
  end
53
53
  end
@@ -14,7 +14,10 @@ end
14
14
 
15
15
  def prepare_samplebook(srcdir, bookdir, latextemplatedir, configfile)
16
16
  samplebook_dir = File.expand_path("../samples/#{bookdir}/", File.dirname(__FILE__))
17
- FileUtils.cp_r(Dir.glob(File.join(samplebook_dir, '*')), srcdir)
17
+ files = Dir.glob(File.join(samplebook_dir, '*'))
18
+ # ignore temporary built files
19
+ files.delete_if { |file| file =~ /.*\-(pdf|epub|text)/ || file == 'webroot' }
20
+ FileUtils.cp_r(files, srcdir)
18
21
  if latextemplatedir
19
22
  # copy from review-jsbook or review-jlreq
20
23
  template_dir = File.expand_path("../templates/latex/#{latextemplatedir}/", File.dirname(__FILE__))
@@ -546,6 +546,18 @@ EOS
546
546
  図1.1: sample photo
547
547
  </p>
548
548
  </div>
549
+ EOS
550
+ assert_equal expected, actual
551
+
552
+ @config['caption_position']['image'] = 'top'
553
+ actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
554
+ expected = <<-EOS
555
+ <div id="sampleimg" class="image">
556
+ <p class="caption">
557
+ 図1.1: sample photo
558
+ </p>
559
+ <img src="images/chap1-sampleimg.png" alt="sample photo" />
560
+ </div>
549
561
  EOS
550
562
  assert_equal expected, actual
551
563
  end
@@ -622,6 +634,18 @@ EOS
622
634
  図: sample photo
623
635
  </p>
624
636
  </div>
637
+ EOS
638
+ assert_equal expected, actual
639
+
640
+ @config['caption_position']['image'] = 'top'
641
+ actual = compile_block("//indepimage[sampleimg][sample photo]\n")
642
+ expected = <<-EOS
643
+ <div id="sampleimg" class="image">
644
+ <p class="caption">
645
+ 図: sample photo
646
+ </p>
647
+ <img src="images/chap1-sampleimg.png" alt="sample photo" />
648
+ </div>
625
649
  EOS
626
650
  assert_equal expected, actual
627
651
  end
@@ -806,6 +830,20 @@ test1.5
806
830
  test<i>2</i>
807
831
  </pre>
808
832
  </div>
833
+ EOS
834
+ assert_equal expected, actual
835
+
836
+ @config['caption_position']['list'] = 'bottom'
837
+ actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
838
+ expected = <<-EOS
839
+ <div id="samplelist" class="caption-code">
840
+ <pre class="list">test1
841
+ test1.5
842
+
843
+ test<i>2</i>
844
+ </pre>
845
+ <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
846
+ </div>
809
847
  EOS
810
848
  assert_equal expected, actual
811
849
  end
@@ -1023,6 +1061,29 @@ EOS
1023
1061
  4: end
1024
1062
  </pre>
1025
1063
  </div>
1064
+ EOS
1065
+
1066
+ assert_equal expected, actual
1067
+
1068
+ @config['caption_position']['list'] = 'bottom'
1069
+ actual = compile_block(<<-EOS)
1070
+ //listnum[samplelist][this is @<b>{test}<&>_][ruby]{
1071
+ def foo(a1, a2=:test)
1072
+ (1..3).times{|i| a.include?(:foo)}
1073
+ return true
1074
+ end
1075
+ //}
1076
+ EOS
1077
+
1078
+ expected = <<-EOS
1079
+ <div id="samplelist" class="code">
1080
+ <pre class="list language-ruby"> 1: def foo(a1, a2=:test)
1081
+ 2: (1..3).times{|i| a.include?(:foo)}
1082
+ 3: return true
1083
+ 4: end
1084
+ </pre>
1085
+ <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
1086
+ </div>
1026
1087
  EOS
1027
1088
 
1028
1089
  assert_equal expected, actual
@@ -1220,6 +1281,20 @@ bar
1220
1281
  buz
1221
1282
  </pre>
1222
1283
  </div>
1284
+ EOS
1285
+ assert_equal expected, actual
1286
+
1287
+ @config['caption_position']['list'] = 'bottom'
1288
+ actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
1289
+ expected = <<-EOS
1290
+ <div class="source-code">
1291
+ <pre class="source">foo
1292
+ bar
1293
+
1294
+ buz
1295
+ </pre>
1296
+ <p class="caption">foo/bar/test.rb</p>
1297
+ </div>
1223
1298
  EOS
1224
1299
  assert_equal expected, actual
1225
1300
  end
@@ -1257,6 +1332,18 @@ EOS
1257
1332
  bar
1258
1333
  </pre>
1259
1334
  </div>
1335
+ EOS
1336
+ assert_equal expected, actual
1337
+
1338
+ @config['caption_position']['list'] = 'bottom'
1339
+ actual = compile_block("//box[FOO]{\nfoo\nbar\n//}\n")
1340
+ expected = <<-EOS
1341
+ <div class="syntax">
1342
+ <pre class="syntax">foo
1343
+ bar
1344
+ </pre>
1345
+ <p class="caption">FOO</p>
1346
+ </div>
1260
1347
  EOS
1261
1348
  assert_equal expected, actual
1262
1349
  end
@@ -1301,6 +1388,18 @@ EOS
1301
1388
  lineB
1302
1389
  </pre>
1303
1390
  </div>
1391
+ EOS
1392
+ assert_equal expected, actual
1393
+
1394
+ @config['caption_position']['list'] = 'bottom'
1395
+ actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n")
1396
+ expected = <<-EOS
1397
+ <div class="emlist-code">
1398
+ <pre class="emlist">lineA
1399
+ lineB
1400
+ </pre>
1401
+ <p class="caption">cap1</p>
1402
+ </div>
1304
1403
  EOS
1305
1404
  assert_equal expected, actual
1306
1405
  end
@@ -1341,6 +1440,18 @@ EOS
1341
1440
  2: lineB
1342
1441
  </pre>
1343
1442
  </div>
1443
+ EOS
1444
+ assert_equal expected, actual
1445
+
1446
+ @config['caption_position']['list'] = 'bottom'
1447
+ actual = compile_block("//emlistnum[cap][text]{\nlineA\nlineB\n//}\n")
1448
+ expected = <<-EOS
1449
+ <div class="emlistnum-code">
1450
+ <pre class="emlist language-text"> 1: lineA
1451
+ 2: lineB
1452
+ </pre>
1453
+ <p class="caption">cap</p>
1454
+ </div>
1344
1455
  EOS
1345
1456
  assert_equal expected, actual
1346
1457
  end
@@ -1413,6 +1524,18 @@ EOS
1413
1524
  lineB
1414
1525
  </pre>
1415
1526
  </div>
1527
+ EOS
1528
+ assert_equal expected, actual
1529
+
1530
+ @config['caption_position']['list'] = 'bottom'
1531
+ actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
1532
+ expected = <<-EOS
1533
+ <div class="cmd-code">
1534
+ <pre class="cmd">lineA
1535
+ lineB
1536
+ </pre>
1537
+ <p class="caption">cap1</p>
1538
+ </div>
1416
1539
  EOS
1417
1540
  assert_equal expected, actual
1418
1541
  end
@@ -2074,6 +2197,19 @@ EOS
2074
2197
  <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2075
2198
  </table>
2076
2199
  </div>
2200
+ EOS
2201
+ assert_equal expected, actual
2202
+
2203
+ @config['caption_position']['table'] = 'bottom'
2204
+ actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
2205
+ expected = <<-EOS
2206
+ <div id="foo" class="table">
2207
+ <table>
2208
+ <tr><th>aaa</th><th>bbb</th></tr>
2209
+ <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2210
+ </table>
2211
+ <p class="caption">表1.1: FOO</p>
2212
+ </div>
2077
2213
  EOS
2078
2214
  assert_equal expected, actual
2079
2215
  end
@@ -2110,6 +2246,25 @@ EOS
2110
2246
  <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2111
2247
  </table>
2112
2248
  </div>
2249
+ EOS
2250
+ assert_equal expected, actual
2251
+
2252
+ @config['caption_position']['table'] = 'bottom'
2253
+ actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
2254
+ expected = <<-EOS
2255
+ <div class="table">
2256
+ <table>
2257
+ <tr><th>aaa</th><th>bbb</th></tr>
2258
+ <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2259
+ </table>
2260
+ <p class="caption">foo</p>
2261
+ </div>
2262
+ <div class="table">
2263
+ <table>
2264
+ <tr><th>aaa</th><th>bbb</th></tr>
2265
+ <tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>
2266
+ </table>
2267
+ </div>
2113
2268
  EOS
2114
2269
  assert_equal expected, actual
2115
2270
  end
@@ -2127,6 +2282,16 @@ EOS
2127
2282
  <p class="caption">表1.1: test for imgtable</p>
2128
2283
  <img src="images/chap1-sampleimg.png" alt="test for imgtable" />
2129
2284
  </div>
2285
+ EOS
2286
+ assert_equal expected, actual
2287
+
2288
+ @config['caption_position']['table'] = 'bottom'
2289
+ actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
2290
+ expected = <<-EOS
2291
+ <div id="sampleimg" class="imgtable image">
2292
+ <img src="images/chap1-sampleimg.png" alt="test for imgtable" />
2293
+ <p class="caption">表1.1: test for imgtable</p>
2294
+ </div>
2130
2295
  EOS
2131
2296
  assert_equal expected, actual
2132
2297
  end
@@ -2383,6 +2548,20 @@ EOS
2383
2548
  </pre>
2384
2549
  </div>
2385
2550
  </div>
2551
+ EOS
2552
+ actual = compile_block(src)
2553
+ assert_equal expected, actual
2554
+
2555
+ @config['caption_position']['equation'] = 'bottom'
2556
+ expected = <<-EOS
2557
+ <p><span class="eqref">式1.1</span></p>
2558
+ <div id="emc2" class="caption-equation">
2559
+ <div class="equation">
2560
+ <pre>e=mc^2
2561
+ </pre>
2562
+ </div>
2563
+ <p class="caption">式1.1: The Equivalence of Mass <i>and</i> Energy</p>
2564
+ </div>
2386
2565
  EOS
2387
2566
  actual = compile_block(src)
2388
2567
  assert_equal expected, actual