From 6cb2e9705bda5494f07ab8f2326085ec67d2ffae Mon Sep 17 00:00:00 2001 From: takahashim Date: Fri, 26 May 2017 22:29:55 +0900 Subject: [PATCH 1/2] fix counting of //imgtable `//imgtable` should not be counted as ImageIndex, but can be refered as images. --- lib/review/book/index.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/review/book/index.rb b/lib/review/book/index.rb index 146b41c5a..05514ffa4 100644 --- a/lib/review/book/index.rb +++ b/lib/review/book/index.rb @@ -151,8 +151,12 @@ def self.parse(src, *args) # ex. ["//image", "id", "", "caption"] elements = line.split(/\[(.*?)\]/) if elements[1].present? - items.push item_class().new(elements[1], seq, elements[3]) - seq += 1 + if line =~ %r{^//imgtable} + items.push item_class().new(elements[1], 0, elements[3]) + else ## %r<^//(image|graph)> + items.push item_class().new(elements[1], seq, elements[3]) + seq += 1 + end if elements[1] == "" warn "warning: no ID of #{item_type()} in #{line}" end From deb6c8152a1743ac28c7c072e40c6147a9af987c Mon Sep 17 00:00:00 2001 From: takahashim Date: Fri, 26 May 2017 23:36:29 +0900 Subject: [PATCH 2/2] add a test --- test/test_htmlbuilder.rb | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/test_htmlbuilder.rb b/test/test_htmlbuilder.rb index d99ad383a..f9b30a25d 100644 --- a/test/test_htmlbuilder.rb +++ b/test/test_htmlbuilder.rb @@ -365,6 +365,65 @@ def @chapter.image(id) assert_equal expected, actual end + def test_inline_imgref3 + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + file1 = File.join(dir, "images", "img1.png") + filet1 = File.join(dir, "images", "tbl1.png") + file2 = File.join(dir, "images", "img2.png") + re1 = File.join(dir, "sample1.re") + cat = File.join(dir, "catalog.yml") + FileUtils.mkdir_p(File.join(dir,"images")) + File.open(file1, "w"){|f| f.write("")} + File.open(filet1, "w"){|f| f.write("")} + File.open(file2, "w"){|f| f.write("")} + File.open(cat, "w"){|f| f.write("CHAPS:\n - sample1.re\n")} + File.open(re1,"w"){|f| f.write(<{tbl1}. + +img2 is @{img2}. + +//image[img1][image 1]{ +//} + +//imgtable[tbl1][table 1]{ +//} + +//image[img2][image 2]{ +//} +EOF + content = File.read(re1) + actual = compile_block(content) + + expected =<<-EOS +

第1章 test

+

tbl1 is 表1.1.

+

img2 is 図1.2.

+
+image 1 +

+図1.1: image 1 +

+
+
+

表1.1: table 1

+table 1 +
+
+image 2 +

+図1.2: image 2 +

+
+EOS + + assert_equal expected, actual + end + end + end + def test_quote actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n") assert_equal %Q|

foobar

\n

buz

\n|, actual