-
Consider such source sample: # Header 1 {#first}
[Link to header](#first) As gfm does not support header attributes, this converts to: # Header 1
[Link to header](#first) So the link is obviously broken. Is it possible to achieve it in some way now? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
It would certainly be possible to do with a (Lua) filter. Another good solution would be to rely on pandoc's implicit header references feature. The above example would then be written as # Header 1
[Link to header][Header 1] Ensure that the right identifiers are used with |
Beta Was this translation helpful? Give feedback.
-
Thanks, but I would like to keep my explicitly provided identifiers for other formats, and only use gfm auto identifiers for .md
Hmm, do you mean that I should implement this feature from scratch?
Or there is some simpler way?
Could you explain what is exact effect of "+gfm_auto_identifiers" if --from here? |
Beta Was this translation helpful? Give feedback.
-
@tarleb -- adapted from https://stackoverflow.com/a/72600888/2520247
local temp_doc = pandoc.Pandoc{}
local function make_id (el, via)
local via = via or "html"
table.insert(temp_doc.blocks, pandoc.Header(1, el.content))
local roundtripped_doc = pandoc.read(pandoc.write(temp_doc, via), via)
local blocks = roundtripped_doc.blocks
return blocks[#blocks].identifier
end
local headers = {}
local function Header (el)
if el.identifier=="" then return end
local id = make_id(el, "gfm")
if id~=el.identifier then
headers["#"..el.identifier] = "#"..id
end
end
local function Link (el)
local match = headers[el.target]
if match then
el.target = match
return el
end
end
return {
{ Header=Header },
{ Link=Link },
} |
Beta Was this translation helpful? Give feedback.
@tarleb
Here is the resulting lua filter
mdHeadersLinks.lua