diff --git a/doc/config.yml.sample b/doc/config.yml.sample index 3c54ac0ff..f5d7b31c0 100644 --- a/doc/config.yml.sample +++ b/doc/config.yml.sample @@ -188,6 +188,14 @@ toc: true # 省略した場合はnull (挿入しない)。別途unicode-eaw gemファイルが必要 # join_lines_by_lang: null +# 図・表・コードリスト・数式のキャプション位置。 +# 値はtop(上)またはbottom(下)でデフォルトは以下のとおり +# caption_position: +# image: bottom +# table: top +# list: top +# equation: top + # review-toc向けのヒント情報 # (文字幅を考慮した行数計測には、別途unicode-eaw gemファイルが必要) # ページあたりの行数文字数を用紙サイズで指定する(A5 or B5) diff --git a/lib/review/builder.rb b/lib/review/builder.rb index 2d5e8805b..89e68367f 100644 --- a/lib/review/builder.rb +++ b/lib/review/builder.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2002-2019 Minero Aoki, Kenshi Muto +# Copyright (c) 2002-2020 Minero Aoki, Kenshi Muto # # This program is free software. # You can distribute or modify this program under the terms of @@ -142,25 +142,28 @@ def line_num def list(lines, id, caption, lang = nil) begin - list_header(id, caption, lang) + list_header(id, caption, lang) if caption_top?('list') + list_body(id, lines, lang) + list_header(id, caption, lang) unless caption_top?('list') rescue KeyError error "no such list: #{id}" end - list_body(id, lines, lang) end def listnum(lines, id, caption, lang = nil) begin - list_header(id, caption, lang) + list_header(id, caption, lang) if caption_top?('list') + listnum_body(lines, lang) + list_header(id, caption, lang) unless caption_top?('list') rescue KeyError error "no such list: #{id}" end - listnum_body(lines, lang) end def source(lines, caption = nil, lang = nil) - source_header(caption) + source_header(caption) if caption_top?('list') source_body(lines, lang) + source_header(caption) unless caption_top?('list') end def image(lines, id, caption, metric = nil) @@ -175,15 +178,18 @@ def image(lines, id, caption, metric = nil) def table(lines, id = nil, caption = nil) sepidx, rows = parse_table_rows(lines) begin - if caption.present? + if caption_top?('table') && caption.present? + table_header(id, caption) + end + table_begin(rows.first.size) + table_rows(sepidx, rows) + table_end + if !caption_top?('table') && caption.present? table_header(id, caption) end rescue KeyError error "no such table: #{id}" end - table_begin(rows.first.size) - table_rows(sepidx, rows) - table_end end def table_row_separator_regexp @@ -680,5 +686,12 @@ def detab(str, num = nil) def escape(str) str end + + def caption_top?(type) + unless %w[top bottom].include?(@book.config['caption_position'][type]) + warn("invalid caption_position/#{type} parameter. 'top' is assumed") + end + @book.config['caption_position'][type] != 'bottom' + end end end # module ReVIEW diff --git a/lib/review/configure.rb b/lib/review/configure.rb index 4428bfff7..d124c3431 100644 --- a/lib/review/configure.rb +++ b/lib/review/configure.rb @@ -106,6 +106,12 @@ def self.values 'lineheight' => 10 * 1.2, 'pdfcrop_pixelize_cmd' => 'pdftocairo -%t -r 90 -f %p -l %p -singlefile %i %O', 'dvipng_cmd' => 'dvipng -T tight -z 9 -p %p -l %p -o %o %i' + }, + 'caption_position' => { + 'list' => 'top', + 'image' => 'bottom', + 'table' => 'top', + 'equation' => 'top' } ] conf.maker = nil diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb index 6ab59d335..42704b410 100644 --- a/lib/review/htmlbuilder.rb +++ b/lib/review/htmlbuilder.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2008-2019 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, +# Copyright (c) 2008-2020 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, # KADO Masanori # 2002-2007 Minero Aoki # @@ -286,15 +286,25 @@ def shoot(lines, caption = nil) end def box(lines, caption = nil) - puts %Q(
) + captionstr = nil if caption.present? - puts %Q(

#{compile_inline(caption)}

) + captionstr = %Q(

#{compile_inline(caption)}

) + end + puts %Q(
) + + if caption_top?('list') && caption.present? + puts captionstr end + print %Q(
)
       lines.each do |line|
         puts detab(line)
       end
       puts '
' + + if !caption_top?('list') && caption.present? + puts captionstr + end puts '
' end @@ -444,7 +454,7 @@ def listnum_body(lines, lang) def emlist(lines, caption = nil, lang = nil) puts %Q(
) - if caption.present? + if caption_top?('list') && caption.present? puts %Q(

#{compile_inline(caption)}

) end class_names = ['emlist'] @@ -455,12 +465,15 @@ def emlist(lines, caption = nil, lang = nil) lexer = lang puts highlight(body: body, lexer: lexer, format: 'html') puts '' + if !caption_top?('list') && caption.present? + puts %Q(

#{compile_inline(caption)}

) + end puts '
' end def emlistnum(lines, caption = nil, lang = nil) puts %Q(
) - if caption.present? + if caption_top?('list') && caption.present? puts %Q(

#{compile_inline(caption)}

) end @@ -482,19 +495,29 @@ def emlistnum(lines, caption = nil, lang = nil) puts '' end + if !caption_top?('list') && caption.present? + puts %Q(

#{compile_inline(caption)}

) + end + puts '
' end def cmd(lines, caption = nil) puts %Q(
) - if caption.present? + if caption_top?('list') && caption.present? puts %Q(

#{compile_inline(caption)}

) end + print %Q(
)
       body = lines.inject('') { |i, j| i + detab(j) + "\n" }
       lexer = 'shell-session'
       puts highlight(body: body, lexer: lexer, format: 'html')
       puts '
' + + if !caption_top?('list') && caption.present? + puts %Q(

#{compile_inline(caption)}

) + end + puts '
' end @@ -530,12 +553,13 @@ def talk(lines) def texequation(lines, id = nil, caption = '') if id puts %Q(
) - texequation_header(id, caption) + texequation_header(id, caption) if caption_top?('equation') end texequation_body(lines) if id + texequation_header(id, caption) unless caption_top?('equation') puts '
' end end @@ -603,20 +627,22 @@ def result_metric(array) def image_image(id, caption, metric) metrics = parse_metric('html', metric) puts %Q(
) + image_header(id, caption) if caption_top?('image') puts %Q(#{escape(compile_inline(caption))}) - image_header(id, caption) + image_header(id, caption) unless caption_top?('image') puts '
' end def image_dummy(id, caption, lines) warn "image not bound: #{id}" puts %Q(
) + image_header(id, caption) if caption_top?('image') puts %Q(
)
       lines.each do |line|
         puts detab(line)
       end
       puts '
' - image_header(id, caption) + image_header(id, caption) unless caption_top?('image') puts '
' end @@ -679,15 +705,19 @@ def imgtable(lines, id, caption = nil, metric = nil) puts %Q(
) begin - if caption.present? + if caption_top?('table') && caption.present? + table_header(id, caption) + end + + imgtable_image(id, caption, metric) + + if !caption_top?('table') && caption.present? table_header(id, caption) end rescue KeyError error "no such table: #{id}" end - imgtable_image(id, caption, metric) - puts '
' end @@ -724,7 +754,19 @@ def footnote(id, str) def indepimage(lines, id, caption = '', metric = nil) metrics = parse_metric('html', metric) caption = '' unless caption.present? + caption_str = nil + if caption.present? + caption_str = <<-EOS +

+#{I18n.t('numberless_image')}#{I18n.t('caption_prefix')}#{compile_inline(caption)} +

+EOS + end + puts %Q(
) + if caption_top?('image') && caption.present? + puts caption_str + end begin puts %Q(#{escape(compile_inline(caption))}) rescue @@ -738,10 +780,8 @@ def indepimage(lines, id, caption = '', metric = nil) end end - if caption.present? - puts %Q(

) - puts %Q(#{I18n.t('numberless_image')}#{I18n.t('caption_prefix')}#{compile_inline(caption)}) - puts '

' + if !caption_top?('image') && caption.present? + puts caption_str end puts '
' end diff --git a/lib/review/idgxmlbuilder.rb b/lib/review/idgxmlbuilder.rb index b4c86d63c..7777325fb 100644 --- a/lib/review/idgxmlbuilder.rb +++ b/lib/review/idgxmlbuilder.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2008-2019 Minero Aoki, Kenshi Muto +# Copyright (c) 2008-2020 Minero Aoki, Kenshi Muto # 2002-2007 Minero Aoki # # This program is free software. @@ -351,7 +351,9 @@ def cmd(lines, caption = nil) def quotedlist(lines, css_class, caption) print %Q() - puts "#{compile_inline(caption)}" if caption.present? + if caption_top?('list') && caption.present? + puts "#{compile_inline(caption)}" + end print '
'
       no = 1
       lines.each do |line|
@@ -366,7 +368,11 @@ def quotedlist(lines, css_class, caption)
         print '' if @book.config['listinfo']
         no += 1
       end
-      puts '
' + puts '' + if !caption_top?('list') && caption.present? + puts "#{compile_inline(caption)}" + end + puts '' end private :quotedlist @@ -410,20 +416,22 @@ def result_metric(array) def image_image(id, caption, metric = nil) metrics = parse_metric('idgxml', metric) puts '' + image_header(id, caption) if caption_top?('image') puts %Q() - image_header(id, caption) + image_header(id, caption) unless caption_top?('image') puts '' end def image_dummy(id, caption, lines) puts '' + image_header(id, caption) if caption_top?('image') print %Q(
)
       lines.each do |line|
         print detab(line)
         print "\n"
       end
       print '
' - image_header(id, caption) + image_header(id, caption) unless caption_top?('image') puts '' warn "image not bound: #{id}" end @@ -439,13 +447,15 @@ def image_header(id, caption) def texequation(lines, id = nil, caption = '') @texblockequation += 1 + caption_str = nil if id puts '' if get_chap.nil? - puts %Q(#{I18n.t('equation')}#{I18n.t('format_number_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}) + caption_str = %Q(#{I18n.t('equation')}#{I18n.t('format_number_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}) else - puts %Q(#{I18n.t('equation')}#{I18n.t('format_number', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}) + caption_str = %Q(#{I18n.t('equation')}#{I18n.t('format_number', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}) end + puts caption_str if caption_top?('equation') end puts %Q() @@ -455,6 +465,7 @@ def texequation(lines, id = nil, caption = '') puts '' if id + puts caption_str unless caption_top?('equation') puts '' end end @@ -470,19 +481,26 @@ def table(lines, id = nil, caption = nil) puts '' begin - table_header(id, caption) if caption.present? + if caption_top?('table') && caption.present? + table_header(id, caption) + end + + if @tablewidth.nil? + print '' + else + print %Q() + end + @table_id = id + table_rows(sepidx, rows) + puts '' + + if !caption_top?('table') && caption.present? + table_header(id, caption) + end rescue KeyError error "no such table: #{id}" end - - if @tablewidth.nil? - print '' - else - print %Q() - end - @table_id = id - table_rows(sepidx, rows) - puts '
' + puts '' @tsize = nil end @@ -596,8 +614,13 @@ def imgtable(lines, id, caption = nil, metric = nil) if @chapter.image_bound?(id) metrics = parse_metric('idgxml', metric) puts '' - table_header(id, caption) if caption.present? + if caption_top?('table') && caption.present? + table_header(id, caption) + end puts %Q() + if !caption_top?('table') && caption.present? + table_header(id, caption) + end puts '
' else warn "image not bound: #{id}" if @strict @@ -1003,6 +1026,7 @@ def expert(lines) end def syntaxblock(type, lines, caption) + captionstr = nil if caption.present? titleopentag = %Q(caption aid:pstyle="#{type}-title") titleclosetag = 'caption' @@ -1010,9 +1034,13 @@ def syntaxblock(type, lines, caption) titleopentag = %Q(floattitle type="insn") titleclosetag = 'floattitle' end - puts %Q(<#{type}><#{titleopentag}>#{compile_inline(caption)}) + captionstr = %Q(<#{titleopentag}>#{compile_inline(caption)}) + end + print "<#{type}>" + if caption_top?('list') + puts captionstr else - puts "<#{type}>" + puts '' end no = 1 @@ -1028,6 +1056,9 @@ def syntaxblock(type, lines, caption) print '' if @book.config['listinfo'] no += 1 end + unless caption_top?('list') + print captionstr + end puts "" end @@ -1042,12 +1073,17 @@ def box(lines, caption = nil) def indepimage(_lines, id, caption = nil, metric = nil) metrics = parse_metric('idgxml', metric) puts '' + if caption_top?('image') + puts %Q(#{compile_inline(caption)}) if caption.present? + end begin puts %Q() rescue warn %Q(image not bound: #{id}) end - puts %Q(#{compile_inline(caption)}) if caption.present? + unless caption_top?('image') + puts %Q(#{compile_inline(caption)}) if caption.present? + end puts '' end @@ -1148,8 +1184,13 @@ def inline_title(id) def source(lines, caption = nil, lang = nil) puts '' - source_header(caption) + if caption_top?('list') + source_header(caption) + end source_body(lines, lang) + unless caption_top?('list') + source_header(caption) + end puts '' end diff --git a/lib/review/latexbuilder.rb b/lib/review/latexbuilder.rb index 9f96456b2..10d14793a 100644 --- a/lib/review/latexbuilder.rb +++ b/lib/review/latexbuilder.rb @@ -403,18 +403,19 @@ def cmd(lines, caption = nil, lang = nil) def common_code_block(id, lines, command, caption, _lang) @doc_status[:caption] = true + captionstr = nil unless @book.config.check_version('2', exception: false) puts '\\begin{reviewlistblock}' end if caption.present? if command =~ /emlist/ || command =~ /cmd/ || command =~ /source/ - puts macro(command + 'caption', compile_inline(caption)) + captionstr = macro(command + 'caption', compile_inline(caption)) else begin if get_chap.nil? - puts macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}") + captionstr = macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}") else - puts macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}") + captionstr = macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}") end rescue KeyError error "no such list: #{id}" @@ -422,6 +423,11 @@ def common_code_block(id, lines, command, caption, _lang) end end @doc_status[:caption] = nil + + if caption_top?('list') && captionstr + puts captionstr + end + body = '' lines.each_with_index do |line, idx| body.concat(yield(line, idx)) @@ -429,6 +435,11 @@ def common_code_block(id, lines, command, caption, _lang) puts macro('begin', command) print body puts macro('end', command) + + if !caption_top?('list') && captionstr + puts captionstr + end + unless @book.config.check_version('2', exception: false) puts '\\end{reviewlistblock}' end @@ -501,10 +512,24 @@ def result_metric(array) end def image_image(id, caption, metric) + captionstr = nil + @doc_status[:caption] = true + if @book.config.check_version('2', exception: false) + captionstr = macro('caption', compile_inline(caption)) + "\n" if caption.present? + else + captionstr = macro('reviewimagecaption', compile_inline(caption)) + "\n" if caption.present? + end + captionstr << macro('label', image_label(id)) + @doc_status[:caption] = nil + metrics = parse_metric('latex', metric) # image is always bound here puts "\\begin{reviewimage}%%#{id}" + if caption_top?('image') && captionstr + puts captionstr + end + command = 'reviewincludegraphics' if @book.config.check_version('2', exception: false) command = 'includegraphics' @@ -515,15 +540,11 @@ def image_image(id, caption, metric) else puts "\\#{command}[width=\\maxwidth]{#{@chapter.image(id).path}}" end - @doc_status[:caption] = true - if @book.config.check_version('2', exception: false) - puts macro('caption', compile_inline(caption)) if caption.present? - else - puts macro('reviewimagecaption', compile_inline(caption)) if caption.present? + if !caption_top?('image') && captionstr + puts captionstr end - @doc_status[:caption] = nil - puts macro('label', image_label(id)) + puts '\end{reviewimage}' end @@ -588,9 +609,21 @@ def column_label(id, chapter = @chapter) def indepimage(lines, id, caption = nil, metric = nil) metrics = parse_metric('latex', metric) + captionstr = nil + if caption.present? + @doc_status[:caption] = true + captionstr = macro('reviewindepimagecaption', + %Q(#{I18n.t('numberless_image')}#{I18n.t('caption_prefix')}#{compile_inline(caption)})) + @doc_status[:caption] = nil + end + if @chapter.image(id).path puts "\\begin{reviewimage}%%#{id}" + if caption_top?('image') && captionstr + puts captionstr + end + command = 'reviewincludegraphics' if @book.config.check_version('2', exception: false) command = 'includegraphics' @@ -610,12 +643,9 @@ def indepimage(lines, id, caption = nil, metric = nil) end end - @doc_status[:caption] = true - if caption.present? - puts macro('reviewindepimagecaption', - %Q(#{I18n.t('numberless_image')}#{I18n.t('caption_prefix')}#{compile_inline(caption)})) + if !caption_top?('image') && captionstr + puts captionstr end - @doc_status[:caption] = nil if @chapter.image(id).path puts '\end{reviewimage}' @@ -637,7 +667,9 @@ def table(lines, id = nil, caption = nil) sepidx, rows = parse_table_rows(lines) begin - table_header(id, caption) if caption.present? + if caption_top?('table') && caption.present? + table_header(id, caption) + end rescue KeyError error "no such table: #{id}" end @@ -645,6 +677,9 @@ def table(lines, id = nil, caption = nil) table_rows(sepidx, rows) table_end if caption.present? + unless caption_top?('table') + table_header(id, caption) + end puts '\end{table}' end blank @@ -807,12 +842,16 @@ def imgtable(lines, id, caption = nil, metric = nil) return end + captionstr = nil begin if caption.present? puts "\\begin{table}[h]%%#{id}" @doc_status[:caption] = true - puts macro('reviewimgtablecaption', compile_inline(caption)) + captionstr = macro('reviewimgtablecaption', compile_inline(caption)) @doc_status[:caption] = nil + if caption_top?('table') + puts captionstr + end end puts macro('label', table_label(id)) rescue ReVIEW::KeyError @@ -821,6 +860,9 @@ def imgtable(lines, id, caption = nil, metric = nil) imgtable_image(id, caption, metric) if caption.present? + unless caption_top?('table') + puts captionstr + end puts '\end{table}' end blank @@ -860,22 +902,31 @@ def flushright(lines) def texequation(lines, id = nil, caption = '') blank + captionstr = nil if id puts macro('begin', 'reviewequationblock') if get_chap.nil? - puts macro('reviewequationcaption', "#{I18n.t('equation')}#{I18n.t('format_number_header_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}") + captionstr = macro('reviewequationcaption', "#{I18n.t('equation')}#{I18n.t('format_number_header_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}") else - puts macro('reviewequationcaption', "#{I18n.t('equation')}#{I18n.t('format_number_header', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}") + captionstr = macro('reviewequationcaption', "#{I18n.t('equation')}#{I18n.t('format_number_header', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}") end end + if caption_top?('equation') && captionstr + puts captionstr + end + puts macro('begin', 'equation*') lines.each do |line| puts line end puts macro('end', 'equation*') + if !caption_top?('equation') && captionstr + puts captionstr + end + if id puts macro('end', 'reviewequationblock') end diff --git a/lib/review/plaintextbuilder.rb b/lib/review/plaintextbuilder.rb index b899e1d78..ed537e1db 100644 --- a/lib/review/plaintextbuilder.rb +++ b/lib/review/plaintextbuilder.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2019 Kenshi Muto +# Copyright (c) 2018-2020 Kenshi Muto # # This program is free software. # You can distribute or modify this program under the terms of @@ -140,13 +140,19 @@ def read(lines) def list(lines, id, caption, lang = nil) blank begin - list_header(id, caption, lang) + if caption_top?('list') + list_header(id, caption, lang) + blank + end + list_body(id, lines, lang) + unless caption_top?('list') + blank + list_header(id, caption, lang) + end rescue KeyError error "no such list: #{id}" end blank - list_body(id, lines, lang) - blank end def list_header(id, caption, _lang) @@ -165,8 +171,13 @@ def list_body(_id, lines, _lang) def base_block(_type, lines, caption = nil) blank - puts compile_inline(caption) if caption.present? + if caption_top?('list') && caption.present? + puts compile_inline(caption) + end puts lines.join("\n") + if !caption_top?('list') && caption.present? + puts compile_inline(caption) + end blank end @@ -183,23 +194,34 @@ def emlist(lines, caption = nil, _lang = nil) def emlistnum(lines, caption = nil, _lang = nil) blank - puts compile_inline(caption) if caption.present? + if caption_top?('list') + puts compile_inline(caption) if caption.present? + end lines.each_with_index do |line, i| puts((i + 1).to_s.rjust(2) + ": #{line}") end + unless caption_top?('list') + puts compile_inline(caption) if caption.present? + end blank end def listnum(lines, id, caption, lang = nil) blank begin - list_header(id, caption, lang) + if caption_top?('list') + list_header(id, caption, lang) + blank + end + listnum_body(lines, lang) + unless caption_top?('list') + blank + list_header(id, caption, lang) + end rescue KeyError error "no such list: #{id}" end blank - listnum_body(lines, lang) - blank end def listnum_body(lines, _lang) @@ -228,8 +250,9 @@ def image(_lines, id, caption, _metric = nil) def texequation(lines, id = nil, caption = '') blank - texequation_header(id, caption) + texequation_header(id, caption) if caption_top?('equation') puts lines.join("\n") + texequation_header(id, caption) unless caption_top?('equation') blank end @@ -251,6 +274,10 @@ def table(lines, id = nil, caption = nil, noblank = nil) end def table_header(id, caption) + unless caption_top?('table') + blank + end + if id.nil? puts compile_inline(caption) elsif get_chap @@ -258,7 +285,10 @@ def table_header(id, caption) else puts "#{I18n.t('table')}#{I18n.t('format_number_without_chapter', [@chapter.table(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}" end - blank + + if caption_top?('table') + blank + end end def table_begin(_ncols) diff --git a/lib/review/topbuilder.rb b/lib/review/topbuilder.rb index d60bf059b..ad65c0eb5 100644 --- a/lib/review/topbuilder.rb +++ b/lib/review/topbuilder.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2008-2019 Minero Aoki, Kenshi Muto +# Copyright (c) 2008-2020 Minero Aoki, Kenshi Muto # 2002-2006 Minero Aoki # # This program is free software. @@ -95,12 +95,18 @@ def list(lines, id, caption, lang = nil) blank puts "◆→開始:#{@titles['list']}←◆" begin - list_header(id, caption, lang) + if caption_top?('list') + list_header(id, caption, lang) + blank + end + list_body(id, lines, lang) + unless caption_top?('list') + blank + list_header(id, caption, lang) + end rescue KeyError error "no such list: #{id}" end - blank - list_body(id, lines, lang) puts "◆→終了:#{@titles['list']}←◆" blank end @@ -122,8 +128,13 @@ def list_body(_id, lines, _lang) def base_block(type, lines, caption = nil) blank puts "◆→開始:#{@titles[type]}←◆" - puts "■#{compile_inline(caption)}" if caption.present? + if caption_top?('list') && caption.present? + puts "■#{compile_inline(caption)}" + end puts lines.join("\n") + if !caption_top?('list') && caption.present? + puts "■#{compile_inline(caption)}" + end puts "◆→終了:#{@titles[type]}←◆" blank end @@ -140,10 +151,15 @@ def base_parablock(type, lines, caption = nil) def emlistnum(lines, caption = nil, _lang = nil) blank puts "◆→開始:#{@titles['emlist']}←◆" - puts "■#{compile_inline(caption)}" if caption.present? + if caption_top?('list') && caption.present? + puts "■#{compile_inline(caption)}" + end lines.each_with_index do |line, i| puts((i + 1).to_s.rjust(2) + ": #{line}") end + if !caption_top?('list') && caption.present? + puts "■#{compile_inline(caption)}" + end puts "◆→終了:#{@titles['emlist']}←◆" blank end @@ -152,12 +168,18 @@ def listnum(lines, id, caption, lang = nil) blank puts "◆→開始:#{@titles['list']}←◆" begin - list_header(id, caption, lang) + if caption_top?('list') && caption.present? + list_header(id, caption, lang) + blank + end + listnum_body(lines, lang) + if !caption_top?('list') && caption.present? + blank + list_header(id, caption, lang) + end rescue KeyError error "no such list: #{id}" end - blank - listnum_body(lines, lang) puts "◆→終了:#{@titles['list']}←◆" blank end @@ -173,8 +195,10 @@ def image(lines, id, caption, metric = nil) metrics = " #{metrics}" if metrics.present? blank puts "◆→開始:#{@titles['image']}←◆" - image_header(id, caption) - blank + if caption_top?('image') + image_header(id, caption) + blank + end if @chapter.image_bound?(id) puts "◆→#{@chapter.image(id).path}#{metrics}←◆" else @@ -183,6 +207,10 @@ def image(lines, id, caption, metric = nil) puts line end end + unless caption_top?('image') + blank + image_header(id, caption) + end puts "◆→終了:#{@titles['image']}←◆" blank end @@ -198,7 +226,7 @@ def image_header(id, caption) def texequation(lines, id = nil, caption = '') blank puts "◆→開始:#{@titles['texequation']}←◆" - texequation_header(id, caption) + texequation_header(id, caption) if caption_top?('equation') if @book.config['imgmath'] fontsize = @book.config['imgmath_options']['fontsize'].to_f @@ -214,6 +242,7 @@ def texequation(lines, id = nil, caption = '') puts lines.join("\n") end + texequation_header(id, caption) unless caption_top?('equation') puts "◆→終了:#{@titles['texequation']}←◆" blank end @@ -419,13 +448,18 @@ def indepimage(_lines, id, caption = nil, metric = nil) metrics = parse_metric('top', metric) metrics = " #{metrics}" if metrics.present? blank + if caption_top?('image') && caption.present? + puts "図 #{compile_inline(caption)}" + end begin puts "◆→画像 #{@chapter.image(id).path.sub(%r{\A\./}, '')}#{metrics}←◆" rescue warn "image not bound: #{id}" puts "◆→画像 #{id}←◆" end - puts "図 #{compile_inline(caption)}" if caption.present? + if !caption_top?('image') && caption.present? + puts "図 #{compile_inline(caption)}" + end blank end diff --git a/test/test_htmlbuilder.rb b/test/test_htmlbuilder.rb index 57987fe93..91813358d 100644 --- a/test/test_htmlbuilder.rb +++ b/test/test_htmlbuilder.rb @@ -546,6 +546,18 @@ def @chapter.image(_id) 図1.1: sample photo

+EOS + assert_equal expected, actual + + @config['caption_position']['image'] = 'top' + actual = compile_block("//image[sampleimg][sample photo]{\n//}\n") + expected = <<-EOS +
+

+図1.1: sample photo +

+sample photo +
EOS assert_equal expected, actual end @@ -622,6 +634,18 @@ def @chapter.image(_id) 図: sample photo

+EOS + assert_equal expected, actual + + @config['caption_position']['image'] = 'top' + actual = compile_block("//indepimage[sampleimg][sample photo]\n") + expected = <<-EOS +
+

+図: sample photo +

+sample photo +
EOS assert_equal expected, actual end @@ -806,6 +830,20 @@ def @chapter.list(_id) test2 +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//list[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") + expected = <<-EOS +
+
test1
+test1.5
+
+test2
+
+

リスト1.1: this is test<&>_

+
EOS assert_equal expected, actual end @@ -1023,6 +1061,29 @@ def foo(a1, a2=:test) 4: end +EOS + + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block(<<-EOS) +//listnum[samplelist][this is @{test}<&>_][ruby]{ +def foo(a1, a2=:test) + (1..3).times{|i| a.include?(:foo)} + return true +end +//} +EOS + + expected = <<-EOS +
+
 1: def foo(a1, a2=:test)
+ 2:   (1..3).times{|i| a.include?(:foo)}
+ 3:   return true
+ 4: end
+
+

リスト1.1: this is test<&>_

+
EOS assert_equal expected, actual @@ -1220,6 +1281,20 @@ def test_source buz +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n") + expected = <<-EOS +
+
foo
+bar
+
+buz
+
+

foo/bar/test.rb

+
EOS assert_equal expected, actual end @@ -1257,6 +1332,18 @@ def test_box bar +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//box[FOO]{\nfoo\nbar\n//}\n") + expected = <<-EOS +
+
foo
+bar
+
+

FOO

+
EOS assert_equal expected, actual end @@ -1301,6 +1388,18 @@ def test_emlist_caption lineB +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n") + expected = <<-EOS +
+
lineA
+lineB
+
+

cap1

+
EOS assert_equal expected, actual end @@ -1341,6 +1440,18 @@ def test_emlistnum_lang 2: lineB +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//emlistnum[cap][text]{\nlineA\nlineB\n//}\n") + expected = <<-EOS +
+
 1: lineA
+ 2: lineB
+
+

cap

+
EOS assert_equal expected, actual end @@ -1413,6 +1524,18 @@ def test_cmd_caption lineB +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n") + expected = <<-EOS +
+
lineA
+lineB
+
+

cap1

+
EOS assert_equal expected, actual end @@ -2074,6 +2197,19 @@ def test_table cccddd<>& +EOS + assert_equal expected, actual + + @config['caption_position']['table'] = 'bottom' + actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") + expected = <<-EOS +
+ + + +
aaabbb
cccddd<>&
+

表1.1: FOO

+
EOS assert_equal expected, actual end @@ -2110,6 +2246,25 @@ def test_emtable cccddd<>& +EOS + assert_equal expected, actual + + @config['caption_position']['table'] = 'bottom' + actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") + expected = <<-EOS +
+ + + +
aaabbb
cccddd<>&
+

foo

+
+
+ + + +
aaabbb
cccddd<>&
+
EOS assert_equal expected, actual end @@ -2127,6 +2282,16 @@ def @chapter.image(_id)

表1.1: test for imgtable

test for imgtable +EOS + assert_equal expected, actual + + @config['caption_position']['table'] = 'bottom' + actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n") + expected = <<-EOS +
+test for imgtable +

表1.1: test for imgtable

+
EOS assert_equal expected, actual end @@ -2383,6 +2548,20 @@ def test_texequation_with_caption +EOS + actual = compile_block(src) + assert_equal expected, actual + + @config['caption_position']['equation'] = 'bottom' + expected = <<-EOS +

式1.1

+
+
+
e=mc^2
+
+
+

式1.1: The Equivalence of Mass and Energy

+
EOS actual = compile_block(src) assert_equal expected, actual diff --git a/test/test_idgxmlbuilder.rb b/test/test_idgxmlbuilder.rb index aebe13651..cac822da6 100644 --- a/test/test_idgxmlbuilder.rb +++ b/test/test_idgxmlbuilder.rb @@ -100,6 +100,27 @@ def test_inline_in_table_without_header_and_cellwidth assert_equal %Q(1\t23\t4<>&
), actual end + def test_table + actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") + expected = <<-EOS.chomp +
aaabbbcccddd<>&
+EOS + assert_equal expected, actual + + actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") + expected = <<-EOS.chomp +
表1.1 FOO
aaabbbcccddd<>&
+EOS + assert_equal expected, actual + + @config['caption_position']['table'] = 'bottom' + actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") + expected = <<-EOS.chomp +
aaabbbcccddd<>&
表1.1 FOO
+EOS + assert_equal expected, actual + end + def test_customize_cellwidth actual = compile_block("//tsize[2,3,5]\n//table{\nA\tB\tC\n//}\n") assert_equal %Q(
ABC
), actual @@ -144,6 +165,10 @@ def test_empty_table def test_emtable actual = compile_block("//emtable[foo]{\nA\n//}\n//emtable{\nA\n//}") assert_equal %Q(
foo
A
A
), actual + + @config['caption_position']['table'] = 'bottom' + actual = compile_block("//emtable[foo]{\nA\n//}\n//emtable{\nA\n//}") + assert_equal %Q(
A
foo
A
), actual end def test_table_row_separator @@ -329,11 +354,19 @@ def test_point_without_caption def test_emlist actual = compile_block("//emlist[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") assert_equal %Q(this is test<&>_
test1\ntest1.5\n\ntest2\n
), actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//emlist[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") + assert_equal %Q(
test1\ntest1.5\n\ntest2\n
this is test<&>_
), actual end def test_emlistnum actual = compile_block("//emlistnum[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") assert_equal %Q(this is test<&>_
 1: test1\n 2: test1.5\n 3: \n 4: test2\n
), actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//emlistnum[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") + assert_equal %Q(
 1: test1\n 2: test1.5\n 3: \n 4: test2\n
this is test<&>_
), actual end def test_emlist_listinfo @@ -385,6 +418,17 @@ def @chapter.list(_id) test2 +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//list[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") + expected = <<-EOS.chomp +
test1
+test1.5
+
+test2
+
リスト1.1 this is test<&>_
EOS assert_equal expected, actual end @@ -400,6 +444,17 @@ def @chapter.list(_id) 3: 4: test2 +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//listnum[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") + expected = <<-EOS.chomp +
 1: test1
+ 2: test1.5
+ 3: 
+ 4: test2
+
リスト1.1 this is test<&>_
EOS assert_equal expected, actual end @@ -415,6 +470,17 @@ def @chapter.list(_id) 102: 103: test2 +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//firstlinenum[100]\n//listnum[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") + expected = <<-EOS.chomp +
100: test1
+101: test1.5
+102: 
+103: test2
+
リスト1.1 this is test<&>_
EOS assert_equal expected, actual end @@ -431,6 +497,17 @@ def @chapter.list(_id) test2 +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//list[samplelist][this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") + expected = <<-EOS.chomp +
test1
+test1.5
+
+test2
+
リスト1.1 this is test<&>_
EOS assert_equal expected, actual end @@ -449,6 +526,15 @@ def test_cmd cap1
lineA
 lineB
 
+EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n") + expected = <<-EOS.chomp +
lineA
+lineB
+
cap1
EOS assert_equal expected, actual end @@ -461,6 +547,17 @@ def test_source buz +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n") + expected = <<-EOS.chomp +
foo
+bar
+
+buz
+
foo/bar/test.rb EOS assert_equal expected, actual end @@ -498,6 +595,17 @@ def test_insn test2 +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//insn[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") + expected = <<-EOS.chomp +test1 +test1.5 + +test2 +this is test<&>_ EOS assert_equal expected, actual end @@ -511,6 +619,17 @@ def test_box test2 +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//box[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") + expected = <<-EOS.chomp +test1 +test1.5 + +test2 +this is test<&>_ EOS assert_equal expected, actual end @@ -524,6 +643,17 @@ def test_box_non_listinfo test2 +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//box[this is @{test}<&>_]{\ntest1\ntest1.5\n\ntest@{2}\n//}\n") + expected = <<-EOS.chomp +test1 +test1.5 + +test2 +this is test<&>_ EOS assert_equal expected, actual end @@ -569,6 +699,10 @@ def @chapter.image(_id) actual = compile_block("//image[sampleimg][sample photo]{\n//}\n") assert_equal %Q(図1.1 sample photo), actual + + @config['caption_position']['image'] = 'top' + actual = compile_block("//image[sampleimg][sample photo]{\n//}\n") + assert_equal %Q(図1.1 sample photo), actual end def test_image_with_metric @@ -602,6 +736,10 @@ def @chapter.image(_id) actual = compile_block("//indepimage[sampleimg][sample photo]\n") assert_equal %Q(sample photo), actual + + @config['caption_position']['image'] = 'top' + actual = compile_block("//indepimage[sampleimg][sample photo]\n") + assert_equal %Q(sample photo), actual end def test_indepimage_without_caption @@ -972,5 +1110,10 @@ def test_texequation_with_caption expected = %Q(

式1.1

式1.1 The Equivalence of Mass and Energy
e=mc^2
) actual = compile_block(src) assert_equal expected, actual + + @config['caption_position']['equation'] = 'bottom' + expected = %Q(

式1.1

e=mc^2
式1.1 The Equivalence of Mass and Energy
) + actual = compile_block(src) + assert_equal expected, actual end end diff --git a/test/test_latexbuilder.rb b/test/test_latexbuilder.rb index 4350d2359..d728d438d 100644 --- a/test/test_latexbuilder.rb +++ b/test/test_latexbuilder.rb @@ -432,6 +432,22 @@ def test_cmd_caption buz \\end{reviewcmd} \\end{reviewlistblock} +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//cmd[cap1]{\nfoo\nbar\n\nbuz\n//}\n") + expected = <<-EOS + +\\begin{reviewlistblock} +\\begin{reviewcmd} +foo +bar + +buz +\\end{reviewcmd} +\\reviewcmdcaption{cap1} +\\end{reviewlistblock} EOS assert_equal expected, actual end @@ -507,6 +523,22 @@ def test_emlist_caption buz \\end{reviewemlist} \\end{reviewlistblock} +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//emlist[cap1]{\nfoo\nbar\n\nbuz\n//}\n") + expected = <<-EOS + +\\begin{reviewlistblock} +\\begin{reviewemlist} +foo +bar + +buz +\\end{reviewemlist} +\\reviewemlistcaption{cap1} +\\end{reviewlistblock} EOS assert_equal expected, actual end @@ -573,6 +605,22 @@ def test_emlistnum_caption 4: buz \\end{reviewemlist} \\end{reviewlistblock} +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//emlistnum[cap1]{\nfoo\nbar\n\nbuz\n//}\n") + expected = <<-EOS + +\\begin{reviewlistblock} +\\begin{reviewemlist} + 1: foo + 2: bar + 3: + 4: buz +\\end{reviewemlist} +\\reviewemlistcaption{cap1} +\\end{reviewlistblock} EOS assert_equal expected, actual end @@ -589,6 +637,21 @@ def test_list buz \\end{reviewlist} \\end{reviewlistblock} +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//list[id1][cap1]{\nfoo\nbar\n\nbuz\n//}\n") + expected = <<-EOS +\\begin{reviewlistblock} +\\begin{reviewlist} +foo +bar + +buz +\\end{reviewlist} +\\reviewlistcaption{リスト1.1: cap1} +\\end{reviewlistblock} EOS assert_equal expected, actual end @@ -601,6 +664,16 @@ def test_list_lst \\begin{reviewlistlst}[caption={cap1},language={sql}] SELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%' \\end{reviewlistlst} +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + # XXX: caption_position won't work with highlight + actual = compile_block("//list[id1][cap1][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n") + expected = <<-EOS +\\begin{reviewlistlst}[caption={cap1},language={sql}] +SELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%' +\\end{reviewlistlst} EOS assert_equal expected, actual end @@ -633,6 +706,24 @@ def test_listnum 7: end \\end{reviewlist} \\end{reviewlistblock} +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n") + expected = <<-EOS +\\begin{reviewlistblock} +\\begin{reviewlist} + 1: class Foo + 2: def foo + 3: bar + 4: + 5: buz + 6: end + 7: end +\\end{reviewlist} +\\reviewlistcaption{リスト1.1: ruby} +\\end{reviewlistblock} EOS assert_equal expected, actual end @@ -670,6 +761,22 @@ def foo end end \\end{reviewlistnumlst} +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + # XXX: caption_position won't work with highlight + actual = compile_block("//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n") + expected = <<-EOS +\\begin{reviewlistnumlst}[caption={ruby},language={}] +class Foo + def foo + bar + + buz + end +end +\\end{reviewlistnumlst} EOS assert_equal expected, actual end @@ -704,6 +811,21 @@ def test_source buz \\end{reviewsource} \\end{reviewlistblock} +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n") + expected = <<-EOS +\\begin{reviewlistblock} +\\begin{reviewsource} +foo +bar + +buz +\\end{reviewsource} +\\reviewsourcecaption{foo/bar/test.rb} +\\end{reviewlistblock} EOS assert_equal expected, actual end @@ -732,6 +854,19 @@ def test_source_lst foo bar +buz +\\end{reviewsourcelst} +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + # XXX: caption_position won't work with highlight + actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n") + expected = <<-EOS +\\begin{reviewsourcelst}[title={foo/bar/test.rb},language={}] +foo +bar + buz \\end{reviewsourcelst} EOS @@ -888,6 +1023,18 @@ def @chapter.image(_id) actual = compile_block("//image[sampleimg][sample photo][]{\n//}\n") assert_equal expected, actual + + @book.config['pdfmaker']['use_original_image_size'] = nil + @config['caption_position']['image'] = 'top' + actual = compile_block("//image[sampleimg][sample photo]{\n//}\n") + expected = <<-EOS +\\begin{reviewimage}%%sampleimg +\\reviewimagecaption{sample photo} +\\label{image:chap1:sampleimg} +\\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png} +\\end{reviewimage} +EOS + assert_equal expected, actual end def test_image_with_metric @@ -1008,6 +1155,17 @@ def @chapter.image(_id) actual = compile_block("//indepimage[sampleimg][sample photo][]\n") assert_equal expected, actual + + @book.config['pdfmaker']['use_original_image_size'] = nil + @config['caption_position']['image'] = 'top' + actual = compile_block("//indepimage[sampleimg][sample photo]\n") + expected = <<-EOS +\\begin{reviewimage}%%sampleimg +\\reviewindepimagecaption{図: sample photo} +\\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png} +\\end{reviewimage} +EOS + assert_equal expected, actual end def test_indepimage_without_caption @@ -1134,6 +1292,21 @@ def test_table ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline \\end{reviewtable} \\end{table} +EOS + assert_equal expected, actual + + @config['caption_position']['table'] = 'bottom' + actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") + expected = <<-EOS +\\begin{table}%%foo +\\begin{reviewtable}{|l|l|} +\\hline +\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline +ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline +\\end{reviewtable} +\\reviewtablecaption{FOO} +\\label{table:chap1:foo} +\\end{table} EOS assert_equal expected, actual end @@ -1240,6 +1413,26 @@ def test_emtable \\end{reviewtable} \\end{table} +\\begin{reviewtable}{|l|l|} +\\hline +\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline +ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline +\\end{reviewtable} +EOS + assert_equal expected, actual + + @config['caption_position']['table'] = 'bottom' + actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") + expected = <<-EOS +\\begin{table}%% +\\begin{reviewtable}{|l|l|} +\\hline +\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline +ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline +\\end{reviewtable} +\\reviewtablecaption*{foo} +\\end{table} + \\begin{reviewtable}{|l|l|} \\hline \\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline @@ -1285,6 +1478,21 @@ def @chapter.image(_id) actual = compile_block("//imgtable[sampleimg][test for imgtable][]{\n//}\n") assert_equal expected, actual + + @book.config['pdfmaker']['use_original_image_size'] = nil + @config['caption_position']['table'] = 'bottom' + actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n") + + expected = <<-EOS +\\begin{table}[h]%%sampleimg +\\label{table:chap1:sampleimg} +\\begin{reviewimage}%%sampleimg +\\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png} +\\end{reviewimage} +\\reviewimgtablecaption{test for imgtable} +\\end{table} +EOS + assert_equal expected, actual end def test_imgtable_with_metrics @@ -2039,6 +2247,21 @@ def test_texequation_with_caption e=mc^2 \\end{equation*} \\end{reviewequationblock} +EOS + actual = compile_block(src) + assert_equal expected, actual + + @config['caption_position']['equation'] = 'bottom' + expected = <<-EOS + +\\reviewequationref{1.1} + +\\begin{reviewequationblock} +\\begin{equation*} +e=mc^2 +\\end{equation*} +\\reviewequationcaption{式1.1: The Equivalence of Mass \\reviewit{and} Energy} +\\end{reviewequationblock} EOS actual = compile_block(src) assert_equal expected, actual diff --git a/test/test_plaintextbuilder.rb b/test/test_plaintextbuilder.rb index 03c255dc9..e27497cfa 100644 --- a/test/test_plaintextbuilder.rb +++ b/test/test_plaintextbuilder.rb @@ -249,6 +249,17 @@ def @chapter.list(_id) foo bar +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//list[samplelist][this is @{test}<&>_]{\nfoo\nbar\n//}\n") + expected = <<-EOS +foo +bar + +リスト1.1 this is test<&>_ + EOS assert_equal expected, actual end @@ -264,6 +275,17 @@ def @chapter.list(_id) 1: foo 2: bar +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//listnum[test][this is @{test}<&>_]{\nfoo\nbar\n//}\n") + expected = <<-EOS + 1: foo + 2: bar + +リスト1.1 this is test<&>_ + EOS assert_equal expected, actual end @@ -277,6 +299,18 @@ def test_source buz +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n") + expected = <<-EOS +foo +bar + +buz +foo/bar/test.rb + EOS assert_equal expected, actual end @@ -308,6 +342,16 @@ def test_box foo bar +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//box[FOO]{\nfoo\nbar\n//}\n") + expected = <<-EOS +foo +bar +FOO + EOS assert_equal expected, actual end @@ -327,6 +371,16 @@ def test_cmd lineA lineB +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n") + expected = <<-EOS +lineA +lineB +cap1 + EOS assert_equal expected, actual end @@ -348,6 +402,16 @@ def test_emlist_caption lineA lineB +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n") + expected = <<-EOS +lineA +lineB +cap1 + EOS assert_equal expected, actual end @@ -359,6 +423,16 @@ def test_emlistnum 1: foo 2: bar +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//emlistnum[this is @{test}<&>_]{\nfoo\nbar\n//}\n") + expected = <<-EOS + 1: foo + 2: bar +this is test<&>_ + EOS assert_equal expected, actual end @@ -387,6 +461,16 @@ def test_table aaa\tbbb ccc\tddd<>& +EOS + assert_equal expected, actual + + @config['caption_position']['table'] = 'bottom' + actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") + expected = <<-EOS +aaa\tbbb +ccc\tddd<>& + +表1.1 FOO EOS assert_equal expected, actual end @@ -521,6 +605,10 @@ def @chapter.image(_id) actual = compile_block("//image[sampleimg][sample photo]{\nfoo\n//}\n") assert_equal %Q(図1.1 sample photo\n\n), actual + + @config['caption_position']['image'] = 'top' + actual = compile_block("//image[sampleimg][sample photo]{\nfoo\n//}\n") + assert_equal %Q(図1.1 sample photo\n\n), actual end def test_image_with_metric @@ -649,6 +737,17 @@ def test_texequation_with_caption 式1.1 The Equivalence of Mass and Energy e=mc^2 +EOS + actual = compile_block(src) + assert_equal expected, actual + + @config['caption_position']['equation'] = 'bottom' + expected = <<-EOS +式1.1 + +e=mc^2 +式1.1 The Equivalence of Mass and Energy + EOS actual = compile_block(src) assert_equal expected, actual diff --git a/test/test_topbuilder.rb b/test/test_topbuilder.rb index 3a0332760..97e2ad7ad 100644 --- a/test/test_topbuilder.rb +++ b/test/test_topbuilder.rb @@ -295,6 +295,19 @@ def @chapter.list(_id) 2: bar ◆→終了:リスト←◆ +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//listnum[test][this is @{test}<&>_]{\nfoo\nbar\n//}\n") + expected = <<-EOS +◆→開始:リスト←◆ + 1: foo + 2: bar + +リスト1.1 this is ★test☆<&>_ +◆→終了:リスト←◆ + EOS assert_equal expected, actual end @@ -310,6 +323,20 @@ def test_source buz ◆→終了:ソースコードリスト←◆ +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n") + expected = <<-EOS +◆→開始:ソースコードリスト←◆ +foo +bar + +buz +■foo/bar/test.rb +◆→終了:ソースコードリスト←◆ + EOS assert_equal expected, actual end @@ -347,6 +374,18 @@ def test_box bar ◆→終了:書式←◆ +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//box[FOO]{\nfoo\nbar\n//}\n") + expected = <<-EOS +◆→開始:書式←◆ +foo +bar +■FOO +◆→終了:書式←◆ + EOS assert_equal expected, actual end @@ -370,6 +409,18 @@ def test_cmd lineB ◆→終了:コマンド←◆ +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n") + expected = <<-EOS +◆→開始:コマンド←◆ +lineA +lineB +■cap1 +◆→終了:コマンド←◆ + EOS assert_equal expected, actual end @@ -395,6 +446,18 @@ def test_emlist_caption lineB ◆→終了:インラインリスト←◆ +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n") + expected = <<-EOS +◆→開始:インラインリスト←◆ +lineA +lineB +■cap1 +◆→終了:インラインリスト←◆ + EOS assert_equal expected, actual end @@ -408,6 +471,18 @@ def test_emlistnum 2: bar ◆→終了:インラインリスト←◆ +EOS + assert_equal expected, actual + + @config['caption_position']['list'] = 'bottom' + actual = compile_block("//emlistnum[this is @{test}<&>_]{\nfoo\nbar\n//}\n") + expected = <<-EOS +◆→開始:インラインリスト←◆ + 1: foo + 2: bar +■this is ★test☆<&>_ +◆→終了:インラインリスト←◆ + EOS assert_equal expected, actual end @@ -440,6 +515,19 @@ def test_table ccc\tddd<>& ◆→終了:表←◆ +EOS + assert_equal expected, actual + + @config['caption_position']['table'] = 'bottom' + actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n") + expected = <<-EOS +◆→開始:表←◆ +★aaa☆\t★bbb☆ +ccc\tddd<>& + +表1.1 FOO +◆→終了:表←◆ + EOS assert_equal expected, actual end @@ -657,6 +745,18 @@ def @chapter.image(_id) actual = compile_block("//image[sampleimg][sample photo]{\nfoo\n//}\n") expected = <<-EOS ◆→開始:図←◆ +◆→./images/chap1-sampleimg.png←◆ + +図1.1 sample photo +◆→終了:図←◆ + +EOS + assert_equal expected, actual + + @config['caption_position']['image'] = 'top' + actual = compile_block("//image[sampleimg][sample photo]{\nfoo\n//}\n") + expected = <<-EOS +◆→開始:図←◆ 図1.1 sample photo ◆→./images/chap1-sampleimg.png←◆ @@ -676,9 +776,9 @@ def @chapter.image(_id) actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\nfoo\n//}\n") expected = <<-EOS ◆→開始:図←◆ -図1.1 sample photo - ◆→./images/chap1-sampleimg.png scale=1.2←◆ + +図1.1 sample photo ◆→終了:図←◆ EOS @@ -829,6 +929,20 @@ def test_texequation_with_caption e=mc^2 ◆→終了:TeX式←◆ +EOS + actual = compile_block(src) + assert_equal expected, actual + + @config['caption_position']['equation'] = 'bottom' + + expected = <<-EOS +式1.1 + +◆→開始:TeX式←◆ +e=mc^2 +式1.1 The Equivalence of Mass ▲and☆ Energy +◆→終了:TeX式←◆ + EOS actual = compile_block(src) assert_equal expected, actual