Skip to content

Instantly share code, notes, and snippets.

@tarleb
Last active August 16, 2020 20:30
Show Gist options
  • Save tarleb/1a78c3aacf917f362805ee1404689dbe to your computer and use it in GitHub Desktop.
Save tarleb/1a78c3aacf917f362805ee1404689dbe to your computer and use it in GitHub Desktop.
No-id org headers
-- Licensed, at your choice, under the MIT or GPL-2-or-later license
local header_ids = {}
local function collect_id (header)
if header.identifier and header.identifier ~= "" then
header_ids[header.identifier] = header.content
header.identifier = ""
return header
end
end
local function raw_inlines (s)
return pandoc.List{pandoc.RawInline('org', s)}
end
local function modify_link (link)
-- only modify internal links
if link.target:sub(1,1) ~= '#' then
return
end
local target_id = link.target:sub(2)
local header_content = header_ids[target_id]
if header_content then
return raw_inlines '[[*'
.. header_content
.. raw_inlines ']['
.. link.content
.. raw_inlines ']]'
end
end
return {
{Header = collect_id},
{Link = modify_link},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment