diff --git a/README.md b/README.md index 777c7eb..b529430 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/pandoc2review.rb b/lib/pandoc2review.rb index ccd3074..650071f 100644 --- a/lib/pandoc2review.rb +++ b/lib/pandoc2review.rb @@ -29,6 +29,10 @@ def main end end + if @stripemptydev + args += ['-M', "stripemptydev:true"] + end + if @heading args += ["--shift-heading-level-by=#{@heading}"] end @@ -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 @@ -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
without any id or class") do + @stripemptydev = true + end opts.parse!(ARGV) if ARGV.size != 1 diff --git a/lua/filters.lua b/lua/filters.lua index c849d7b..2af172f 100644 --- a/lua/filters.lua +++ b/lua/filters.lua @@ -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 diff --git a/lua/review.lua b/lua/review.lua index 345125d..d29e44f 100755 --- a/lua/review.lua +++ b/lua/review.lua @@ -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 diff --git a/pandoc2review.gemspec b/pandoc2review.gemspec index 2710449..44b557e 100644 --- a/pandoc2review.gemspec +++ b/pandoc2review.gemspec @@ -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 = ["kmuto@kmuto.jp"] spec.license = "GPL-2.0" diff --git a/test/test_helper.rb b/test/test_helper.rb index 5dbd598..36e3196 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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 diff --git a/test/test_reviewlua.rb b/test/test_reviewlua.rb index 2fb3201..ff81f61 100644 --- a/test/test_reviewlua.rb +++ b/test/test_reviewlua.rb @@ -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][テスト]{ + +-------------- +@{table align=center}a\t@{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][テスト]{ + +-------------- +@{table align=center}a\t@{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