Georgios Pappas Jr 2025-05-11
super-link
is a Pandoc Pandoc Lua
filter that transforms specially
formatted
Span
or
Citation
elements in Markdown into hyperlinks using predefined configurations.
Easily create links for services like Wikipedia, PubMed, DOI, GitHub,
and more with simple markup.
- Convert spans/citations to links with preconfigured services
- Customize link text and URLs via span attributes
- Add new services via document metadata
- Supports both Markdown spans and Pandoc citations
- Automatic URL encoding and template handling
Spans in Pandoc Markdown are inline elements specified as:
[text]{#id .class attribute=value}
.
This filter recognizes specially formatted spans that include:
- Mandatory ID: The span must have an ID of
#l
. This default ID name (l
) can be changed by modifying theIDNAME
variable in the Lua script. - Link Type: The type of link (which corresponds to a key in the
LINKS
configuration table) must be specified in one of two ways:- As a class name: The first class of the span is used as the
link type. Example:
[Albert_Einstein]{#l .wiki}
(uses thewiki
configuration). - As a
type
attribute: An attributetype
specifies the link type. Example:[Albert_Einstein]{#l type=wiki}
(also uses thewiki
configuration).
- As a class name: The first class of the span is used as the
link type. Example:
The text inside the square brackets (e.g., “Albert_Einstein”) is used as the query string, which is typically appended to the base URL defined in the link’s configuration.
The filter includes several predefined link types (keys in the LINKS
table):
wiki
: Wikipedia articlepubmed
: PubMed articledoi
: DOI article/linkgithub
: GitHub repository/usergithubsearch
: GitHub searchgoogle
: Google searchduck
: DuckDuckGo searchyoutube
: YouTube video/channelYOUTUBE
: YouTube search (uses a template, see below)
Markup | Resulting Link Text (approx.) | Resulting URL |
---|---|---|
[11111111]{#l .pubmed} |
pubmed:11111111 |
https://pubmed.ncbi.nlm.nih.gov/11111111 |
[10.1155/2000/562159]{#l .doi} |
DOI:10.1155/2000/562159 |
https://doi.org/10.1155/2000/562159 |
[pandoc-lua-filters]{#l .githubsearch} |
pandoc-lua-filters |
https://github.com/search?q=pandoc-lua-filters |
You can customize the link’s displayed text using attributes on the span:
title
: Overrides the default link text (which is the query).- Markup:
[11111111]{#l .pubmed title="Article to read"}
- Result: A link to
https://pubmed.ncbi.nlm.nih.gov/11111111
with the display text “pubmed:Article to read”.
- Markup:
before
andafter
: Add a prefix or suffix to the link’s display text. These override anybefore
orafter
text defined in the global link configuration.- Markup:
[Pandoc]{#l type=google before="🔍" after=" (search in Google)"}
- Result: A link to
https://www.google.com/search?q=Pandoc
with the display text “🔍Pandoc (search in Google)”.
- Markup:
template
: The template for the URL. This is useful for links that require a specific format. The template can include%url%
and%query%
placeholders (don’t forget the%
..%
).- Markup:
[pandoc-lua-filters]{#l .githubsearch template="https://github.com/search?q=%query%&type=repositories"}
- Result:
https://github.com/search?q=pandoc-lua-filters&type=repositories
- Markup:
Some link configurations (like duck
) might already have before
or
after
text defined. You can override these:
[Pandoc]{#l .duck}
- Result: Uses the default
before
text from theduck
config (e.g., “🦆:Pandoc”).
- Result: Uses the default
[Pandoc]{#l .duck before="Search" after=" (DuckDuckGo)"}
- Result: Overrides defaults, display text becomes “SearchPandoc (DuckDuckGo)”.
The filter can also transform Pandoc’s citation syntax ([@key]
) into
links. The citation components are interpreted as follows:
[prefix @key suffix]
prefix
(Text before@key
): This is used as the query string for the URL (mandatory for the link to be useful).@key
: This is the link type (e.g.,@pubmed
), corresponding to a key in theLINKS
configuration (mandatory).suffix
(Text after@key
): This is used as the title (display text) for the link (optional; if omitted, the query (prefix) is used, potentially withbefore
/after
from config).
- Basic citation link:
- Markup:
[11111111 @pubmed]
- Result: Equivalent to
[11111111]{#l .pubmed}
. Becomes a link tohttps://pubmed.ncbi.nlm.nih.gov/11111111
with text like “pubmed:11111111”.
- Markup:
- Citation link with a custom title:
- Markup:
[11111111 @pubmed Article to read]
- Result: Becomes a link to
https://pubmed.ncbi.nlm.nih.gov/11111111
with the display text “pubmed:Article to read”.
- Markup:
Note
For citations, the Span attributes (title
, before
and after
) are
not supported. The title appears directly in the citation markup,
whereas before
and after
texts are taken from the configuration.
You can add new link configurations or override existing ones directly
in your Markdown/Quarto document’s YAML metadata block. The metadata key
for these configurations is super-link
by default, but this can be
changed by modifying the FILTERNAME
variable in the Lua script.
Each entry under super-link
should be the name of the new (or
overridden) link type, followed by either:
- A simple string (which will be taken as the
url
). - A table defining
url
, and optionallybefore
,after
,encode
, ortemplate
.
---
author: Your Name
title: My Document
super-link:
# New link with Simple URL string
dockerhub: "https://hub.docker.com/search?q="
# New link with more customizations
mynewsite:
url: "https://mynewsite.example.com/search?term="
before: "Search MyNewSite: "
encode: true
# Override existing 'wiki' to not have 'before' text
wiki:
url: "https://pt.wikipedia.org/wiki"
encode: true
# 'before' and 'after' will be empty if not specified here
# Create a new link based on a template
luasearch:
# Template for searching github repos in Lua language
url: " https://github.com/search?q="
template: "%url%%query%&type=repositories&l=Lua",
before: "GitHub Lua repos for: "
encode: true
---
Some text...
This is a link to `[my search term]{#l .mynewsite}`.
And another one: `[ubuntu @dockerhub Ubuntu Docker images]`
This would create several custom links:
dockerhub
a simple URL string to search in DockerHub
mynewsite
configuration for a new link type
wiki
Overrides the Wikipedia link to change the language (pt
)
luasearch
Shows how to use a template to search a query in GitHub, filtering
repositories in Lua language
Save the file super-link.lua
in ~/.pandoc/filters
(default directory
for pandoc filters) or any other directory. Run using one of the
following syntaxes:
pandoc -s test.md -t html -L super-link.lua
pandoc -s test.md -t html --lua-filter=super-link.lua
pandoc -s test.md -t html -L ~/myfilters/super-link.lua
The last alternative refers to the filter installed in a custom location.
quarto install extension gpappasunb/super-link
Add the filter to the document metadata:
---
filters:
- super-link.lua
---
Prof. Georgios Pappas Jr
Computational Genomics group
University of Brasilia (UnB) - Brazil