Skip to content

Commit

Permalink
Merge pull request #782 from kmuto/fix-imgtable
Browse files Browse the repository at this point in the history
fix counting of //imgtable
  • Loading branch information
takahashim authored May 26, 2017
2 parents b15193c + deb6c81 commit fe2c801
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/review/book/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 59 additions & 0 deletions test/test_htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(<<EOF)}
= test
tbl1 is @<table>{tbl1}.
img2 is @<img>{img2}.
//image[img1][image 1]{
//}
//imgtable[tbl1][table 1]{
//}
//image[img2][image 2]{
//}
EOF
content = File.read(re1)
actual = compile_block(content)

expected =<<-EOS
<h1><a id="h1"></a><span class="secno">第1章 </span>test</h1>
<p>tbl1 is <span class="tableref">表1.1</span>.</p>
<p>img2 is <span class="imgref">図1.2</span>.</p>
<div id="img1" class="image">
<img src="images/img1.png" alt="image 1" />
<p class="caption">
図1.1: image 1
</p>
</div>
<div id="tbl1" class="imgtable image">
<p class="caption">表1.1: table 1</p>
<img src="images/tbl1.png" alt="table 1" />
</div>
<div id="img2" class="image">
<img src="images/img2.png" alt="image 2" />
<p class="caption">
図1.2: image 2
</p>
</div>
EOS

assert_equal expected, actual
end
end
end

def test_quote
actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
assert_equal %Q|<blockquote><p>foobar</p>\n<p>buz</p></blockquote>\n|, actual
Expand Down

0 comments on commit fe2c801

Please sign in to comment.