| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
dofile(os.getenv 'RMARKDOWN_LUA_SHARED') |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
if (not pandocAvailable {2,1}) then |
| 15 |
io.stderr:write("[WARNING] (latex-div.lua) requires at least Pandoc 2.1. Lua Filter skipped.\n") |
| 16 |
return {} |
| 17 |
end |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
text = require 'text' |
| 22 |
|
| 23 |
Div = function (div) |
| 24 |
|
| 25 |
local options = div.attributes['latex'] |
| 26 |
if not options then |
| 27 |
options = div.attributes['data-latex'] |
| 28 |
end |
| 29 |
if not options or #div.attr.classes == 0 then |
| 30 |
return nil |
| 31 |
end |
| 32 |
|
| 33 |
|
| 34 |
if FORMAT ~= 'latex' and FORMAT ~= 'beamer' then |
| 35 |
if div.attributes['latex'] then div.attributes['latex'] = nil end |
| 36 |
if div.attributes['data-latex'] then div.attributes['data-latex'] = nil end |
| 37 |
return div |
| 38 |
end |
| 39 |
|
| 40 |
|
| 41 |
if options == "1" or text.lower(options) == "true" then |
| 42 |
options = "" |
| 43 |
end |
| 44 |
|
| 45 |
|
| 46 |
local env = div.classes[1] |
| 47 |
local beginEnv = '\\begin' .. '{' .. env .. '}' .. options |
| 48 |
local endEnv = '\n\\end{' .. env .. '}' |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
if div.content[1].t == "Para" and div.content[#div.content].t == "Para" then |
| 53 |
table.insert(div.content[1].content, 1, pandoc.RawInline('tex', beginEnv .. "\n")) |
| 54 |
table.insert(div.content[#div.content].content, pandoc.RawInline('tex', "\n" .. endEnv)) |
| 55 |
else |
| 56 |
table.insert(div.content, 1, pandoc.RawBlock('tex', beginEnv)) |
| 57 |
table.insert(div.content, pandoc.RawBlock('tex', endEnv)) |
| 58 |
end |
| 59 |
return div |
| 60 |
end |