Skip to content

Add a new section about new output_format_dependency() #395

@cderv

Description

@cderv

Idea from @atusy in rstudio/rmarkdown#2508 following the example shared in

---
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 },
}
```

```{r}
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))
}
```

# awesome section {#awesome} 

see `r ref("brilliant")`

# brilliant section {#brilliant}

see `r ref("awesome")`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions