|
|
|
|
|
local List = require 'pandoc.List' |
|
local utils = require 'pandoc.utils' |
|
local stringify = utils.stringify |
|
local run_json_filter = utils.run_json_filter |
|
|
|
local pretty_dump = require"pl.pretty".dump |
|
|
|
function isItALink (spc) |
|
return spc and spc.t == 'Link' |
|
end |
|
|
|
|
|
function read_inline (inlines) |
|
for i = #inlines-1,1,-1 do |
|
if isItALink(inlines[i]) then |
|
print(stringify(inlines[i])) |
|
end |
|
end |
|
return inlines |
|
end |
|
|
|
function modify_doc_citation(doc) |
|
|
|
for i,el in pairs(doc.blocks) do |
|
|
|
if (el.t == "Div") then |
|
if el.identifier:match('^refs([_%w]*)$') then |
|
--pretty_dump(el.identifier) |
|
pandoc.walk_block(el, { Inlines = function (e) read_inline(e) end}) |
|
end |
|
end |
|
end |
|
|
|
return doc |
|
end |
|
|
|
function Inlines (inlines) |
|
|
|
for i = #inlines-1,1,-1 do |
|
print(pandoc.utils.stringify(inlines[i])) |
|
end |
|
return inlines |
|
end |
|
|
|
local function run_citeproc(doc, quiet) |
|
if PANDOC_VERSION >= "2.11" then |
|
return run_json_filter( |
|
doc, |
|
'pandoc', |
|
{'--from=json', '--to=json', '--citeproc', quiet and '--quiet' or nil} |
|
) |
|
else |
|
-- doc = run_json_filter(doc, 'pandoc-citeproc') |
|
return run_json_filter( |
|
doc, |
|
'pandoc-citeproc', |
|
{FORMAT, (quiet and supports_quiet_flag) and '-q' or nil} |
|
) |
|
end |
|
end |
|
|
|
local function resolve_doc_citations (doc) |
|
doc = run_citeproc(doc) |
|
return doc |
|
end |
|
|
|
return { |
|
{ Pandoc = resolve_doc_citations }, |
|
{Pandoc = modify_doc_citation} |
|
} |