diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb index d057ac04a..d88462b2b 100644 --- a/lib/review/htmlbuilder.rb +++ b/lib/review/htmlbuilder.rb @@ -540,6 +540,7 @@ def talk(lines) def texequation(lines, id = nil, caption = '') if id + puts %Q(
) texequation_header(id, caption) end @@ -551,7 +552,6 @@ def texequation(lines, id = nil, caption = '') end def texequation_header(id, caption) - puts %Q(
) if get_chap puts %Q(

#{I18n.t('equation')}#{I18n.t('format_number_header', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}

) else diff --git a/lib/review/idgxmlbuilder.rb b/lib/review/idgxmlbuilder.rb index fde37d8b6..cda41921c 100644 --- a/lib/review/idgxmlbuilder.rb +++ b/lib/review/idgxmlbuilder.rb @@ -271,7 +271,6 @@ def inline_list(id) end def list_header(id, caption, _lang) - puts '' return true unless caption.present? if get_chap.nil? puts %Q(#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}) @@ -296,10 +295,21 @@ def codelines_body(lines) end end + def list(lines, id, caption, lang = nil) + puts '' + begin + list_header(id, caption, lang) + rescue KeyError + error "no such list: #{id}" + end + list_body(id, lines, lang) + puts '' + end + def list_body(_id, lines, _lang) print '
'
       codelines_body(lines)
-      puts '
' + print '' end def emlist(lines, caption = nil, _lang = nil) @@ -315,6 +325,17 @@ def emlistnum(lines, caption = nil, _lang = nil) quotedlist(lines2, 'emlistnum', caption) end + def listnum(lines, id, caption, lang = nil) + puts '' + begin + list_header(id, caption, lang) + rescue KeyError + error "no such list: #{id}" + end + listnum_body(lines, lang) + puts '' + end + def listnum_body(lines, _lang) print '
'
       no = 1
@@ -331,7 +352,7 @@ def listnum_body(lines, _lang)
         print '' if @book.config['listinfo']
         no += 1
       end
-      puts '
' + print '' end def cmd(lines, caption = nil) @@ -1134,25 +1155,31 @@ def inline_title(id) error "unknown chapter: #{id}" end - def source_header(caption) + def source(lines, caption, lang = nil) puts '' + source_header(caption) + source_body(lines, lang) + puts '' + end + + def source_header(caption) puts %Q(#{compile_inline(caption)}) if caption.present? end def source_body(lines, _lang) puts '
'
       codelines_body(lines)
-      puts '
' + print '' end def bibpaper(lines, id, caption) + puts %Q() bibpaper_header(id, caption) bibpaper_bibpaper(id, caption, lines) unless lines.empty? puts '' end def bibpaper_header(id, caption) - puts %Q() puts "[#{@chapter.bibpaper(id).number}] #{compile_inline(caption)}" if caption.present? end diff --git a/lib/review/latexbuilder.rb b/lib/review/latexbuilder.rb index e0a6c5555..0b0285e92 100644 --- a/lib/review/latexbuilder.rb +++ b/lib/review/latexbuilder.rb @@ -32,7 +32,6 @@ def builder_init_file @blank_needed = false @latex_tsize = nil @tsize = nil - @table_caption = nil @cellwidth = nil @ol_num = nil @first_line_num = nil @@ -606,6 +605,30 @@ def indepimage(lines, id, caption = nil, metric = nil) alias_method :numberlessimage, :indepimage + def table(lines, id = nil, caption = nil) + if caption.present? + if @book.config.check_version('2', exception: false) + puts "\\begin{table}[h]%%#{id}" + else + puts "\\begin{table}%%#{id}" + end + end + + sepidx, rows = parse_table_rows(lines) + begin + table_header(id, caption) if caption.present? + rescue KeyError + error "no such table: #{id}" + end + table_begin(rows.first.size) + table_rows(sepidx, rows) + table_end + if caption.present? + puts '\end{table}' + end + blank + end + def table_rows(sepidx, rows) if sepidx sepidx.times do @@ -638,25 +661,13 @@ def table_rows(sepidx, rows) def table_header(id, caption) if id.nil? if caption.present? - @table_caption = true @doc_status[:caption] = true - if @book.config.check_version('2', exception: false) - puts "\\begin{table}[h]%%#{id}" - else - puts "\\begin{table}%%#{id}" - end puts macro('reviewtablecaption*', compile_inline(caption)) @doc_status[:caption] = nil end else if caption.present? - @table_caption = true @doc_status[:caption] = true - if @book.config.check_version('2', exception: false) - puts "\\begin{table}[h]%%#{id}" - else - puts "\\begin{table}%%#{id}" - end puts macro('reviewtablecaption', compile_inline(caption)) @doc_status[:caption] = nil end @@ -759,12 +770,9 @@ def tr(rows) def table_end puts macro('end', 'reviewtable') - puts '\end{table}' if @table_caption - @table_caption = nil @tsize = nil @latex_tsize = nil @cellwidth = nil - blank end def emtable(lines, caption = nil) @@ -780,9 +788,8 @@ def imgtable(lines, id, caption = nil, metric = nil) begin if caption.present? - @table_caption = true - @doc_status[:caption] = true puts "\\begin{table}[h]%%#{id}" + @doc_status[:caption] = true puts macro('reviewimgtablecaption', compile_inline(caption)) @doc_status[:caption] = nil end @@ -792,8 +799,9 @@ def imgtable(lines, id, caption = nil, metric = nil) end imgtable_image(id, caption, metric) - puts '\end{table}' if @table_caption - @table_caption = nil + if caption.present? + puts '\end{table}' + end blank end diff --git a/lib/review/markdownbuilder.rb b/lib/review/markdownbuilder.rb index 96998b723..686fda8f1 100644 --- a/lib/review/markdownbuilder.rb +++ b/lib/review/markdownbuilder.rb @@ -65,24 +65,26 @@ def noindent @noindent = true end - def list_header(id, caption, lang) + def list_header(id, caption, _lang) if get_chap.nil? print %Q(リスト#{@chapter.list(id).number} #{compile_inline(caption)}\n\n) else print %Q(リスト#{get_chap}.#{@chapter.list(id).number} #{compile_inline(caption)}\n\n) end - lang ||= '' - puts "```#{lang}" end - def list_body(_id, lines, _lang) + def list_body(_id, lines, lang) + lang ||= '' + puts "```#{lang}" lines.each do |line| puts detab(line) end puts '```' end - def listnum_body(lines, _lang) + def listnum_body(lines, lang) + lang ||= '' + puts "```#{lang}" lines.each_with_index do |line, i| puts((i + 1).to_s.rjust(2) + ": #{detab(line)}") end @@ -136,9 +138,9 @@ def dl_end def emlist(lines, caption = nil, lang = nil) blank - if caption + if caption.present? puts caption - print "\n" + blank end lang ||= '' puts "```#{lang}" @@ -238,7 +240,11 @@ def image_ext 'jpg' end - def cmd(lines) + def cmd(lines, caption = nil) + if caption.present? + puts caption + blank + end puts '```shell-session' lines.each do |line| puts detab(line) diff --git a/lib/review/md2inaobuilder.rb b/lib/review/md2inaobuilder.rb index 5fec4ede7..92a7143dd 100644 --- a/lib/review/md2inaobuilder.rb +++ b/lib/review/md2inaobuilder.rb @@ -11,9 +11,7 @@ def paragraph(lines) puts "\n" end - def list_header(id, caption, lang) - lang ||= '' - puts "```#{lang}" + def list_header(id, caption, _lang) print %Q(●リスト#{@chapter.list(id).number}::#{compile_inline(caption)}\n\n) end diff --git a/lib/review/plaintextbuilder.rb b/lib/review/plaintextbuilder.rb index bfd0a9475..5e565df9b 100644 --- a/lib/review/plaintextbuilder.rb +++ b/lib/review/plaintextbuilder.rb @@ -137,21 +137,30 @@ def read(lines) alias_method :lead, :read - def list_header(id, caption, _lang) + def list(lines, id, caption, lang = nil) + blank + begin + list_header(id, caption, lang) + rescue KeyError + error "no such list: #{id}" + end + blank + list_body(id, lines, lang) blank + end + + def list_header(id, caption, _lang) if get_chap puts %Q(#{I18n.t('list')}#{I18n.t('format_number', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}) else puts %Q(#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}) end - blank end def list_body(_id, lines, _lang) lines.each do |line| puts detab(line) end - blank end def base_block(_type, lines, caption = nil) @@ -181,11 +190,22 @@ def emlistnum(lines, caption = nil, _lang = nil) blank end + def listnum(lines, id, caption, lang = nil) + blank + begin + list_header(id, caption, lang) + rescue KeyError + error "no such list: #{id}" + end + blank + listnum_body(lines, lang) + blank + end + def listnum_body(lines, _lang) lines.each_with_index do |line, i| puts((i + 1).to_s.rjust(2) + ": #{line}") end - blank end def cmd(lines, caption = nil) @@ -207,17 +227,20 @@ def image(_lines, id, caption, _metric = nil) end def texequation(lines, id = nil, caption = '') + blank + texequation_header(id, caption) + puts lines.join("\n") + blank + end + + def texequation_header(id, caption) if id - blank if get_chap puts "#{I18n.t('equation')}#{I18n.t('format_number', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}" else puts "#{I18n.t('equation')}#{I18n.t('format_number_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}" end end - - puts lines.join("\n") - blank end def table(lines, id = nil, caption = nil, noblank = nil) diff --git a/lib/review/topbuilder.rb b/lib/review/topbuilder.rb index d799be126..a8aad9e76 100644 --- a/lib/review/topbuilder.rb +++ b/lib/review/topbuilder.rb @@ -91,23 +91,32 @@ def read(lines) alias_method :lead, :read - def list_header(id, caption, _lang) + def list(lines, id, caption, lang = nil) blank puts "◆→開始:#{@titles['list']}←◆" + begin + list_header(id, caption, lang) + rescue KeyError + error "no such list: #{id}" + end + blank + list_body(id, lines, lang) + puts "◆→終了:#{@titles['list']}←◆" + blank + end + + def list_header(id, caption, _lang) if get_chap puts %Q(#{I18n.t('list')}#{I18n.t('format_number', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}) else puts %Q(#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}) end - blank end def list_body(_id, lines, _lang) lines.each do |line| puts detab(line) end - puts "◆→終了:#{@titles['list']}←◆" - blank end def base_block(type, lines, caption = nil) @@ -139,12 +148,24 @@ def emlistnum(lines, caption = nil, _lang = nil) blank end + def listnum(lines, id, caption, lang = nil) + blank + puts "◆→開始:#{@titles['list']}←◆" + begin + list_header(id, caption, lang) + rescue KeyError + error "no such list: #{id}" + end + blank + listnum_body(lines, lang) + puts "◆→終了:#{@titles['list']}←◆" + blank + end + def listnum_body(lines, _lang) lines.each_with_index do |line, i| puts((i + 1).to_s.rjust(2) + ": #{line}") end - puts "◆→終了:#{@titles['list']}←◆" - blank end def image(lines, id, caption, metric = nil) @@ -152,11 +173,7 @@ def image(lines, id, caption, metric = nil) metrics = " #{metrics}" if metrics.present? blank puts "◆→開始:#{@titles['image']}←◆" - if get_chap - puts "#{I18n.t('image')}#{I18n.t('format_number', [get_chap, @chapter.image(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}" - else - puts "#{I18n.t('image')}#{I18n.t('format_number_without_chapter', [@chapter.image(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}" - end + image_header(id, caption) blank if @chapter.image(id).bound? puts "◆→#{@chapter.image(id).path}#{metrics}←◆" @@ -170,16 +187,18 @@ def image(lines, id, caption, metric = nil) blank end + def image_header(id, caption) + if get_chap + puts "#{I18n.t('image')}#{I18n.t('format_number', [get_chap, @chapter.image(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}" + else + puts "#{I18n.t('image')}#{I18n.t('format_number_without_chapter', [@chapter.image(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}" + end + end + def texequation(lines, id = nil, caption = '') blank puts "◆→開始:#{@titles['texequation']}←◆" - if id - if get_chap - puts "#{I18n.t('equation')}#{I18n.t('format_number', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}" - else - puts "#{I18n.t('equation')}#{I18n.t('format_number_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}" - end - end + texequation_header(id, caption) if @book.config['imgmath'] fontsize = @book.config['imgmath_options']['fontsize'].to_f @@ -199,10 +218,22 @@ def texequation(lines, id = nil, caption = '') blank end + def texequation_header(id, caption) + if id + if get_chap + puts "#{I18n.t('equation')}#{I18n.t('format_number', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}" + else + puts "#{I18n.t('equation')}#{I18n.t('format_number_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}" + end + end + end + def table(lines, id = nil, caption = nil) blank puts "◆→開始:#{@titles['table']}←◆" super(lines, id, caption, true) + puts "◆→終了:#{@titles['table']}←◆" + blank end def th(str) @@ -210,8 +241,6 @@ def th(str) end def table_end - puts "◆→終了:#{@titles['table']}←◆" - blank end def comment(lines, comment = nil) diff --git a/test/test_md2inaobuilder.rb b/test/test_md2inaobuilder.rb index 68ca86224..21c66cc6b 100644 --- a/test/test_md2inaobuilder.rb +++ b/test/test_md2inaobuilder.rb @@ -59,9 +59,9 @@ def test_list EOS assert_equal <<-EOS, actual -``` ●リスト1::caption +``` AAA BBB ```