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

Add inline include possibility #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 30 additions & 2 deletions include-files/include-files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function transclude (cb)
function ()
return pandoc.walk_block(
pandoc.Div(contents),
{ Header = update_last_level, CodeBlock = transclude }
{ Header = update_last_level, CodeBlock = transclude, Code = inline_transclude }
)
end).content
--- reset to level before recursion
Expand All @@ -109,7 +109,35 @@ function transclude (cb)
return blocks
end

local inline_transclude
function inline_transclude(code)
-- ignore inline code which is not of class "include".
if not code.classes:includes 'include' then
return
end

-- Markdown is used if this is nil.
local format = code.attributes['format']
local document
local content
for line in code.text:gmatch('[^\n]+') do
if line:sub(1,2) ~= '//' then
local fh = io.open(line)
if not fh then
io.stderr:write("Cannot open file " .. line .. " | Skipping includes\n")
else
document = pandoc.read(fh:read '*a', format)
if document ~= nil then
content = document.blocks[1].content
end
fh:close()
end
end
end
return content
end

return {
{ Meta = get_vars },
{ Header = update_last_level, CodeBlock = transclude }
{ Header = update_last_level, CodeBlock = transclude, Code = inline_transclude}
}