Skip to content

Commit

Permalink
Merge pull request #55 from kmuto/captionemptydiv
Browse files Browse the repository at this point in the history
handle empty div
  • Loading branch information
kmuto authored Feb 25, 2021
2 parents 9876c61 + 8180381 commit 72870af
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ GNU General Public License Version 2
- [@takahashim](https://github.com/takahashim)

## Changelog
### 1.4.0
- Fix an error when empty div block is received.
- Introduce '--strip-emptydev' to strip empty block `//{-//}`, produced by TeX file.

### 1.3.0
- Fix "attempt to index global 'first' (a nil value)" error in a docx file.

Expand Down
10 changes: 9 additions & 1 deletion lib/pandoc2review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def main
end
end

if @stripemptydev
args += ['-M', "stripemptydev:true"]
end

if @heading
args += ["--shift-heading-level-by=#{@heading}"]
end
Expand All @@ -48,9 +52,10 @@ def parse_args
@heading = nil
@disableeaw = nil
@hideraw = nil
@stripemptydev = nil
opts = OptionParser.new
opts.banner = 'Usage: pandoc2review [option] file [file ...]'
opts.version = '1.3'
opts.version = '1.4'

opts.on('--help', 'Prints this message and quit.') do
puts opts.help
Expand All @@ -65,6 +70,9 @@ def parse_args
opts.on('--hideraw', "Hide raw inline/block with no review format specified.") do
@hideraw = true
end
opts.on('--strip-emptydev', "Strip <div> without any id or class") do
@stripemptydev = true
end

opts.parse!(ARGV)
if ARGV.size != 1
Expand Down
1 change: 1 addition & 0 deletions lua/filters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ local function caption_div(div)
local caption = div.attributes.caption

if ((#div.content == 1) and
(div.content[1].content) and
(#div.content[1].content == 1) and
(div.content[1].content[1].tag == "Math") and
(div.identifier)) then
Expand Down
6 changes: 5 additions & 1 deletion lua/review.lua
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,11 @@ function Div(s, attr)
local classes = attr_classes(attr)

if next(classes) == nil then
return "//{\n" .. s .. "\n//}"
if metadata.stripemptydev then
return s
else
return "//{\n" .. s .. "\n//}"
end
end

if classes["review-internal"] then
Expand Down
2 changes: 1 addition & 1 deletion pandoc2review.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = "pandoc2review"
spec.version = "1.3.0"
spec.version = "1.4.0"
spec.authors = ["Kenshi Muto"]
spec.email = ["[email protected]"]
spec.license = "GPL-2.0"
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require 'fileutils'
require 'open3'

def pandoc(src, opts: nil, err: nil)
args = 'pandoc -t lua/review.lua --lua-filter=lua/filters.lua -f markdown-auto_identifiers-smart+east_asian_line_breaks'
def pandoc(src, opts: nil, err: nil, override_args: nil)
args = override_args || 'pandoc -t lua/review.lua --lua-filter=lua/filters.lua -f markdown-auto_identifiers-smart+east_asian_line_breaks'
p2r = Pandoc2ReVIEW.new
if opts
args += ' ' + opts
Expand Down
34 changes: 34 additions & 0 deletions test/test_reviewlua.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,40 @@ def test_block_texequation
assert_equal expected, pandoc(src)
end

def test_latex_block
src = <<-EOB
\\begin{table}
\\caption{テスト}
\\label{tbl:test}
\\begin{tabular}{|c||c|} \\hline
a & b \\hline
\\end{tabular}
\\end{table}
EOB

expected = <<-EOB
//{
//table[table1][テスト]{
--------------
@<dtp>{table align=center}a\t@<dtp>{table align=center}b
//}
//}
EOB

assert_equal expected, pandoc(src, override_args: 'pandoc -t lua/review.lua --lua-filter=lua/filters.lua -f latex')

expected = <<-EOB
//table[table1][テスト]{
--------------
@<dtp>{table align=center}a\t@<dtp>{table align=center}b
//}
EOB

assert_equal expected, pandoc(src, override_args: 'pandoc -t lua/review.lua --lua-filter=lua/filters.lua -f latex', opts: '-M stripemptydev:true')
end

def test_table
src = <<-EOB
Right Left Center Default
Expand Down

0 comments on commit 72870af

Please sign in to comment.