Skip to content
Discussion options

You must be logged in to vote

@tarleb
Here is the resulting lua filter mdHeadersLinks.lua

-- 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

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@tarleb
Comment options

tarleb May 23, 2024
Collaborator

@johnd0e
Comment options

@tarleb
Comment options

tarleb May 24, 2024
Collaborator

@tarleb
Comment options

tarleb May 24, 2024
Collaborator

Comment options

You must be logged in to vote
0 replies
Answer selected by johnd0e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants