Skip to content

Commit

Permalink
Merge pull request #871 from kmuto/hd
Browse files Browse the repository at this point in the history
空見出しやブロック内見出し誤認によるHeadlineIndexの奇妙なエラー挙動の修正
  • Loading branch information
kmuto authored Nov 11, 2017
2 parents 6445819 + 1db8bdb commit ba5e437
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
15 changes: 13 additions & 2 deletions lib/review/book/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,28 @@ def self.parse(src, chap)
indexs = []
headlines = []
inside_column = false
inside_block = nil
src.each do |line|
if line =~ %r{\A//[a-z]+.*\{\Z}
inside_block = true
next
elsif line =~ %r{\A//\}}
inside_block = nil
next
elsif inside_block
next
end

m = HEADLINE_PATTERN.match(line)
next if m.nil? || m[1].size > 10 # Ignore too deep index
next if m[4].strip.empty? # no title
index = m[1].size - 2

# column
if m[2] == 'column'
inside_column = true
next
end
if m[2] == '/column'
elsif m[2] == '/column'
inside_column = false
next
end
Expand Down
4 changes: 3 additions & 1 deletion lib/review/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,17 @@ def compile_headline(line)
index = level - 1
if tag
if tag !~ %r{\A/}
warn 'headline is empty.' if caption.empty?
close_current_tagged_section(level)
open_tagged_section(tag, level, label, caption)
else
open_tag = tag[1..-1]
prev_tag_info = @tagged_section.pop
raise CompileError, "#{open_tag} is not opened." unless prev_tag_info.first == open_tag
error "#{open_tag} is not opened." if prev_tag_info.nil? || prev_tag_info.first != open_tag
close_tagged_section(*prev_tag_info)
end
else
warn 'headline is empty.' if caption.empty?
@headline_indexs = @headline_indexs[0..index] if @headline_indexs.size > (index + 1)
@headline_indexs[index] = 0 if @headline_indexs[index].nil?
@headline_indexs[index] += 1
Expand Down
13 changes: 12 additions & 1 deletion test/test_htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ def test_column_3
===[/column_dummy]
EOS
assert_raise(ReVIEW::CompileError) do
assert_raise(ReVIEW::ApplicationError) do
column_helper(review)
end
end
Expand Down Expand Up @@ -1583,6 +1583,17 @@ def test_inline_hd_for_part
assert_equal '「1.1 part1-1」', hd
end

def test_inline_hd_with_block
io1 = StringIO.new("= test1\n=={foo} foo\n//emlist{\n======\nbar\n======\n}\n//}\n=={bar} bar")
chap1 = Book::Chapter.new(@book, 1, '-', nil, io1)
location = Location.new(nil, nil)
@builder.bind(@compiler, chap1, location)
hd = @builder.inline_hd('foo')
assert_equal '「1.1 foo」', hd
hd = @builder.inline_hd('bar')
assert_equal '「1.2 bar」', hd
end

def test_table
actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
assert_equal %Q(<div class="table">\n<table>\n<tr><th>aaa</th><th>bbb</th></tr>\n<tr><td>ccc</td><td>ddd&lt;&gt;&amp;</td></tr>\n</table>\n</div>\n),
Expand Down
2 changes: 1 addition & 1 deletion test/test_idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def test_column_3
===[/column_dummy]
EOS
assert_raise(ReVIEW::CompileError) do
assert_raise(ReVIEW::ApplicationError) do
column_helper(review)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def test_column_3
===[/column_dummy]
EOS
assert_raise(ReVIEW::CompileError) do
assert_raise(ReVIEW::ApplicationError) do
column_helper(review)
end
end
Expand Down

0 comments on commit ba5e437

Please sign in to comment.