Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handling raw as embed #34

Merged
merged 3 commits into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -532,11 +532,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 @@ -742,6 +742,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