---
title: referring sections
output:
html_document:
keep_md: true
---
```{cat, engine.opts=list(file = "example.lua")}
local headers = {}
local function collect_header(header)
headers["#" .. el.identifier] = header
end
local function link_header(link)
if #link.content == 0 and headers[link.target] then
link.content = headers[link.target].content
end
return link
end
return {
{ Header = collect_header },
{ Link = link_header },
}
ref <- function(id) {
dep <- rmarkdown::output_format_dependency(
name = "example",
pandoc = list(lua_filters = "example.lua"),
)
rmarkdown:::attach_output_format_dependency(dep)
return(sprintf("[](#%s)", id))
}
Idea from @atusy in https://github.com/rstudio/rmarkdown/pull/2508 following the example shared in
awesome section {#awesome}
see
r ref("brilliant")
brilliant section {#brilliant}
see
r ref("awesome")