Skip to content

Fix global vars in lua scripts #114

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions inst/lua/blocks-to-inlines.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
local sep = {}

function Meta(meta)
sep = meta.sep_blocks and (
meta.sep_blocks.t and meta.sep_blocks or {pandoc.Str(meta.sep_blocks)}
) or {pandoc.LineBreak(), pandoc.LineBreak()}
sep = meta.sep_blocks and (meta.sep_blocks.t and meta.sep_blocks or { pandoc.Str(meta.sep_blocks) })
or { pandoc.LineBreak(), pandoc.LineBreak() }
end

function Div(div)
div.content = {pandoc.Para(pandoc.utils.blocks_to_inlines(div.content, sep))}
return div
div.content = { pandoc.Para(pandoc.utils.blocks_to_inlines(div.content, sep)) }
return div
end

return {{Meta = Meta}, {Div = Div}}
return { { Meta = Meta }, { Div = Div } }
12 changes: 6 additions & 6 deletions inst/lua/cite.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
cite = {}
local cite = {}

function Cite(elem)
table.insert(cite, elem)
table.insert(cite, pandoc.Space())
table.insert(cite, elem)
table.insert(cite, pandoc.Space())
end

function Pandoc(doc)
table.remove(cite)
doc.blocks = {pandoc.Para(cite)}
return doc
table.remove(cite)
doc.blocks = { pandoc.Para(cite) }
return doc
end
18 changes: 9 additions & 9 deletions inst/lua/inline-code.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function Code(elem)
if elem.attributes['font.family'] == nil then
elem.attributes['font.family'] = 'monospace'
end
if elem.attributes['shading.color'] == nil then
elem.attributes['shading.color'] = '#f8f8f8'
end
local span = pandoc.Span(elem.text)
span.attr = elem.attr
return span
if elem.attributes["font.family"] == nil then
elem.attributes["font.family"] = "monospace"
end
if elem.attributes["shading.color"] == nil then
elem.attributes["shading.color"] = "#f8f8f8"
end
local span = pandoc.Span(elem.text)
span.attr = elem.attr
return span
end
60 changes: 28 additions & 32 deletions inst/lua/math.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,45 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

https://github.com/atusy/lua-filters/blob/master/lua/math.lua
]]
is_pandoc_2_10 = (PANDOC_VERSION[1] >= 2) and (PANDOC_VERSION[2] >= 10)
local is_pandoc_2_10 = (PANDOC_VERSION[1] >= 2) and (PANDOC_VERSION[2] >= 10)

local L = {}

if pandoc.system.os ~= "mingw32" then
function math2html(text)
return pandoc.pipe(cmd, {"-t", "html", "-f", "markdown"}, text)
end
function L.math2html(cmd, text)
return pandoc.pipe(cmd, { "-t", "html", "-f", "markdown" }, text)
end
else
if is_pandoc_2_10 then
with_temporary_directory = pandoc.system.with_temporary_directory
else
with_temporary_directory = function(ignored, callback)
return callback(temporary_directory)
end
end

math2html = function(text)
local function callback(directory)
local path = directory .. "\\math-rendered-by-lua-filter.html"
pandoc.pipe(cmd, {"-t", "html", "-f", "markdown", "-o", path}, text)
return io.open(path):read("a")
end

return with_temporary_directory("write_html_math", callback)
end
if is_pandoc_2_10 then
L.with_temporary_directory = pandoc.system.with_temporary_directory
else
function L.with_temporary_directory(_, callback)
return callback(L.temporary_directory)
end
end

function L.math2html(cmd, text)
local function callback(directory)
local path = directory .. "\\math-rendered-by-lua-filter.html"
pandoc.pipe(cmd, { "-t", "html", "-f", "markdown", "-o", path }, text)
return io.open(path):read("a")
end

return L.with_temporary_directory("write_html_math", callback)
end
end

function Meta(elem)
cmd = elem["pandoc-path"] and (
pandoc.utils.stringify(elem["pandoc-path"])
) or "pandoc"
L.cmd = elem["pandoc-path"] and (pandoc.utils.stringify(elem["pandoc-path"])) or "pandoc"

temporary_directory = elem["temporary-directory"] and (
pandoc.utils.stringify(elem["temporary-directory"])
) or "."
L.temporary_directory = elem["temporary-directory"] and (pandoc.utils.stringify(elem["temporary-directory"])) or "."
end

function Math(elem)
return pandoc.read(
math2html("$" .. elem.text:gsub("[\n\r]", "") .. "$"), "html"
).blocks[1].content[1].content
return pandoc.read(L.math2html(L.cmd, "$" .. elem.text:gsub("[\n\r]", "") .. "$"), "html").blocks[1].content[1].content
end

return {
{Meta = Meta},
{Math = Math}
{ Meta = Meta },
{ Math = Math },
}
12 changes: 6 additions & 6 deletions inst/lua/smart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ https://github.com/atusy/lua-filters/blob/master/lua/smart.lua
]]

local quotes = {
SingleQuote = {pandoc.Str("‘"), pandoc.Str("’")},
DoubleQuote = {pandoc.Str("“"), pandoc.Str("”")}
SingleQuote = { pandoc.Str("‘"), pandoc.Str("’") },
DoubleQuote = { pandoc.Str("“"), pandoc.Str("”") },
}

function Quoted(elem)
local q = quotes[elem.quotetype]
table.insert(elem.content, 1, q[1])
table.insert(elem.content, q[2])
return elem.content
local q = quotes[elem.quotetype]
table.insert(elem.content, 1, q[1])
table.insert(elem.content, q[2])
return elem.content
end