Skip to content

Commit

Permalink
Merge pull request #34 from kmuto/raw
Browse files Browse the repository at this point in the history
handling raw as embed
  • Loading branch information
kmuto authored Dec 31, 2020
2 parents 20bacf8 + f4e6b8d commit 6dbf8d0
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pandoc2review-lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def main
if @disableeaw
args += ['-M', "softbreak:true"]
end

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

if @heading
Expand All @@ -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'
Expand All @@ -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
Expand Down
28 changes: 26 additions & 2 deletions review.lua
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,35 @@ 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)
else
return format_inline("embed", "|" .. format .. "|", 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//}"
else
return "//embed[" .. format .. "]{\n" .. text .. "\n//}"
end
end

try_catch {
Expand Down
134 changes: 134 additions & 0 deletions test/test_reviewlua.rb
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,140 @@ def test_footnote
assert_equal expected, pandoc(src)
end

def test_raw
src = <<-EOB
<table>
<thead><tr><th colspan="2">TABLEHEAD</th></tr></thead>
<tbody><tr><td>Cell1</td><td>Cell2</td></tbody>
</table>
EOB

expected = <<-EOB
//embed[html]{
<table>
//}
//embed[html]{
<thead>
//}
//embed[html]{
<tr>
//}
//embed[html]{
<th colspan="2">
//}
TABLEHEAD
//embed[html]{
</th>
//}
//embed[html]{
</tr>
//}
//embed[html]{
</thead>
//}
//embed[html]{
<tbody>
//}
//embed[html]{
<tr>
//}
//embed[html]{
<td>
//}
Cell1
//embed[html]{
</td>
//}
//embed[html]{
<td>
//}
Cell2
//embed[html]{
</td>
//}
//embed[html]{
</tbody>
//}
//embed[html]{
</table>
//}
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
@<m>$\\displaystyle{} \\alpha = \\beta\\label{eqone}$ Refer equation (@<embed>$|latex|\\ref{eqone}$).
EOB

assert_equal expected, pandoc(src)

expected = <<-EOB
@<m>$\\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
Expand Down

0 comments on commit 6dbf8d0

Please sign in to comment.