From e058863bc3002a8cf21b523c9cc7322cd8d7ff7d Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Wed, 30 Dec 2020 18:07:48 +0900 Subject: [PATCH 1/3] handling raw as embed --- pandoc2review-lib.rb | 8 +++ review.lua | 32 +++++++++- test/test_reviewlua.rb | 134 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+), 2 deletions(-) diff --git a/pandoc2review-lib.rb b/pandoc2review-lib.rb index 996f7ce..662cd39 100644 --- a/pandoc2review-lib.rb +++ b/pandoc2review-lib.rb @@ -23,6 +23,10 @@ def main if @disableeaw args += ['-M', "softbreak:true"] end + + if @hideraw + args += ['-M', "hideraw:true"] + end end if @heading @@ -43,6 +47,7 @@ def main def parse_args @heading = nil @disableeaw = nil + @hideraw = nil opts = OptionParser.new opts.banner = 'Usage: pandoc2review [option] file [file ...]' opts.version = '1.0' @@ -57,6 +62,9 @@ def parse_args opts.on('--disable-eaw', "Disable compositing a paragraph with Ruby's EAW library.") do @disableeaw = true end + opts.on('--hideraw', "Hide raw inline/block with no review format specified.") do + @hideraw = true + end opts.parse!(ARGV) if ARGV.size != 1 diff --git a/review.lua b/review.lua index 3049f5b..019561c 100755 --- a/review.lua +++ b/review.lua @@ -532,11 +532,39 @@ function Span(s, attr) end function RawInline(format, text) - return text + if (format == "review") then + return text + end + + if (metadata.hideraw) then + return "" + end + + if (format == "tex") then + return format_inline("embed", "|latex|" .. text) + elseif (format == "html") then + return format_inline("embed", "|html|" .. text) + else + return format_inline("embed", text) + end end function RawBlock(format, text) - return text + if (format == "review") then + return text + end + + if (metadata.hideraw) then + return "" + end + + if (format == "tex") then + return "//embed[latex]{\n" .. text .. "\n//}" + elseif (format == "html") then + return "//embed[html]{\n" .. text .. "\n//}" + else + return "//embed{\n" .. text .. "\n//}" + end end try_catch { diff --git a/test/test_reviewlua.rb b/test/test_reviewlua.rb index 1e202a3..088b697 100644 --- a/test/test_reviewlua.rb +++ b/test/test_reviewlua.rb @@ -742,6 +742,140 @@ def test_footnote assert_equal expected, pandoc(src) end + def test_raw + src = <<-EOB + + + +
TABLEHEAD
Cell1Cell2
+EOB + + expected = <<-EOB +//embed[html]{ + +//} + +//embed[html]{ + +//} + +//embed[html]{ + +//} + +//embed[html]{ + +//} + +//embed[html]{ + +//} + +//embed[html]{ + +//} + +//embed[html]{ + +//} + +//embed[html]{ + +//} + +//embed[html]{ + +//} + +//embed[html]{ + +//} + +//embed[html]{ + +//} + +//embed[html]{ +
+//} + +TABLEHEAD + +//embed[html]{ +
+//} + +Cell1 + +//embed[html]{ + +//} + +Cell2 + +//embed[html]{ +
+//} +EOB + # Bit ugly... + assert_equal expected, pandoc(src) + + expected = <<-EOB + + + + + + + + +TABLEHEAD + + + + + + + + + + + + + +Cell1 + + + + + +Cell2 + + + + + +EOB + # bit ugly... + assert_equal expected, pandoc(src, opts: '-M hideraw') + + src = <<-EOB +$$ \\alpha = \\beta\\label{eqone}$$ +Refer equation (\\ref{eqone}). +EOB + + expected = <<-EOB +@$\\displaystyle{} \\alpha = \\beta\\label{eqone}$ Refer equation (@$|latex|\\ref{eqone}$). +EOB + + assert_equal expected, pandoc(src) + + expected = <<-EOB +@$\\displaystyle{} \\alpha = \\beta\\label{eqone}$ Refer equation (). +EOB + assert_equal expected, pandoc(src, opts: '-M hideraw') + end + def test_table src = <<-EOB Right Left Center Default From f76a1a682ef87fbb9001bc57dcc02a7fe710d211 Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Thu, 31 Dec 2020 11:04:23 +0900 Subject: [PATCH 2/3] Update review.lua Co-authored-by: atusy <30277794+atusy@users.noreply.github.com> --- review.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/review.lua b/review.lua index 019561c..949cbf4 100755 --- a/review.lua +++ b/review.lua @@ -542,10 +542,8 @@ function RawInline(format, text) if (format == "tex") then return format_inline("embed", "|latex|" .. text) - elseif (format == "html") then - return format_inline("embed", "|html|" .. text) else - return format_inline("embed", text) + return format_inline("embed", "|" .. format .. "|", text) end end From f4e6b8d1cced3958afd2d10ffce9dfb35872a621 Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Thu, 31 Dec 2020 11:04:30 +0900 Subject: [PATCH 3/3] Update review.lua Co-authored-by: atusy <30277794+atusy@users.noreply.github.com> --- review.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/review.lua b/review.lua index 949cbf4..0b9321a 100755 --- a/review.lua +++ b/review.lua @@ -558,10 +558,8 @@ function RawBlock(format, text) if (format == "tex") then return "//embed[latex]{\n" .. text .. "\n//}" - elseif (format == "html") then - return "//embed[html]{\n" .. text .. "\n//}" else - return "//embed{\n" .. text .. "\n//}" + return "//embed[" .. format .. "]{\n" .. text .. "\n//}" end end