Skip to content

Commit cc4e473

Browse files
author
pedro
committed
v1.1.0 — Add custom type remapping for alerts-normalize (info → note) via frontmatter
### Added - Custom type remapping: allows mapping one alert type to another via frontmatter, e.g.: ```yaml alerts-normalize: out-format: pandoc-format custom-types: - info: note ``` - Improves flexibility when normalizing alerts across different output formats.
1 parent 14a3a7a commit cc4e473

File tree

17 files changed

+254
-93
lines changed

17 files changed

+254
-93
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## [1.1.0] — 2026-03-29
4+
5+
### Added
6+
7+
- **Custom type remapping**: allow mapping one callout type to another via frontmatter, e.g.:
8+
9+
```yaml
10+
alerts-normalize:
11+
out-format: pandoc-format
12+
custom-types:
13+
- info: note
14+
```
15+
16+
This remaps info alerts to note during normalization.
17+
318
## \[1.0.0]
419
520
### Architecture

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors:
44
- family-names: "Barrio"
55
given-names: "Pedro Luis"
66
title: "alerts-normalize.lua"
7-
version: 1.0.0
7+
version: 1.1.0
88
date-released: 2026-03-22
99
url: "https://github.com/plbarrio/alerts-normalize"
1010
license: GPL-3.0-or-later

Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Targets:
44
# test — run all tests
5-
# test-pandoc — plain Pandoc path (11 cases)
5+
# test-pandoc — plain Pandoc path (12 cases)
66
# test-quarto — forced Quarto path via out-format: quarto-format (6 cases)
77
# test-quarto-pandoc — Quarto runner + out-format: pandoc-format (5 cases, requires quarto)
88
# test-roundtrip — round-trip through all readable formats via pandoc-md
@@ -12,6 +12,7 @@ INPUT_DIR = test/input
1212
EXPECTED = test/expected
1313
META_PANDOC = $(INPUT_DIR)/alert-normalize-pandoc-mode.yaml
1414
META_QUARTO = $(INPUT_DIR)/alert-normalize-quarto-mode.yaml
15+
META_TYPE_MAP = $(INPUT_DIR)/alert-normalize-type-map.yaml
1516

1617
# strips pandoc-api-version from JSON output before comparing
1718
STRIP_VER = python3 -c "import sys,json; d=json.load(sys.stdin); d.pop('pandoc-api-version',None); d.pop('meta',None); print(json.dumps(d))"
@@ -24,7 +25,7 @@ STEP = pandoc -f markdown -t markdown --lua-filter=$(FILTER) --metadata alerts-n
2425
test-pandoc-rich test-pandoc-passthrough \
2526
test-pandoc-title test-pandoc-collapse test-pandoc-title-only \
2627
test-pandoc-custom-type test-pandoc-pandoc-md-source \
27-
test-pandoc-quarto-titled \
28+
test-pandoc-quarto-titled test-pandoc-type-map \
2829
test-quarto-basic test-quarto-empty test-quarto-multipara \
2930
test-quarto-rich test-quarto-passthrough test-quarto-titled \
3031
test-quarto-pandoc-basic test-quarto-pandoc-empty \
@@ -43,7 +44,7 @@ test-pandoc: test-pandoc-basic test-pandoc-empty test-pandoc-multipara \
4344
test-pandoc-rich test-pandoc-passthrough \
4445
test-pandoc-title test-pandoc-collapse test-pandoc-title-only \
4546
test-pandoc-custom-type test-pandoc-pandoc-md-source \
46-
test-pandoc-quarto-titled
47+
test-pandoc-quarto-titled test-pandoc-type-map
4748

4849
test-pandoc-basic:
4950
@echo -n "test-pandoc-basic: "
@@ -122,6 +123,13 @@ test-pandoc-quarto-titled:
122123
| $(STRIP_VER) | diff - $(EXPECTED)/alert-normalize-quarto-titled-pandoc.json
123124
@echo "OK"
124125

126+
test-pandoc-type-map:
127+
@echo -n "test-pandoc-type-map: "
128+
@pandoc $(INPUT_DIR)/alert-normalize-type-map.md \
129+
--lua-filter=$(FILTER) --metadata-file=$(META_TYPE_MAP) -t json \
130+
| $(STRIP_VER) | diff - $(EXPECTED)/alert-normalize-type-map-pandoc.json
131+
@echo "OK"
132+
125133
# --- Quarto forced via out-format: quarto-format ---
126134

127135
test-quarto: test-quarto-basic test-quarto-empty test-quarto-multipara \
@@ -307,6 +315,10 @@ generate-pandoc:
307315
pandoc $(INPUT_DIR)/$$f.md --lua-filter=$(FILTER) -t json \
308316
| $(STRIP_VER) > $(EXPECTED)/$$f-pandoc.json && echo "OK"; \
309317
done
318+
@echo -n " alert-normalize-type-map: "
319+
@pandoc $(INPUT_DIR)/alert-normalize-type-map.md --lua-filter=$(FILTER) \
320+
--metadata-file=$(META_TYPE_MAP) -t json \
321+
| $(STRIP_VER) > $(EXPECTED)/alert-normalize-type-map-pandoc.json && echo "OK"
310322

311323
generate-quarto:
312324
@echo "Generating quarto expected files..."

README.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ Quarto callout — no title needed.
149149

150150
## Configuration
151151

152+
153+
### Simple form
154+
152155
The simplest form works on the command line and in frontmatter:
153156

154157
```sh
@@ -163,30 +166,23 @@ alerts-normalize: github-format
163166
---
164167
```
165168

169+
### Nested form (custom types, remapping)
170+
166171
For additional options, use the nested form in a metadata file or frontmatter:
167172

168173
```yaml
169174
alerts-normalize:
170175
out-format: pandoc-format
171176
custom-types:
172177
- spoiler
173-
- exercise
174-
- theorem
178+
- exercise
179+
- info : note # remap info -> note
175180
```
176181
177-
### `out-format`
178-
179-
Selects the output format. Auto-detected when omitted: `quarto-format` inside
180-
`quarto render`, `pandoc-format` otherwise.
181-
182-
### `custom-types`
182+
* `out-format` — chooses the output format. Auto-detected when omitted: `quarto-format` inside Quarto, `pandoc-format` otherwise.
183183

184-
Extends the built-in callout type whitelist with additional types. The built-in
185-
list covers the core types (`note`, `warning`, `tip`, `caution`, `important`)
186-
and extended types from Obsidian, MkDocs, MyST, Sphinx, and VitePress ecosystems.
184+
* `custom-types` — extends the built-in callout whitelist; supports **remapping** (`source: target`) and new types.
187185

188-
Custom types from GitHub syntax (`> [!WORD]`) are always accepted regardless
189-
of the whitelist — the whitelist only applies to plain classed div detection.
190186

191187
## Output
192188

@@ -241,7 +237,7 @@ Content.
241237
- Inline title capture: `> [!NOTE] My title`
242238
- Collapse support: `[!NOTE]-` collapsed, `[!NOTE]+` expanded
243239
- Extended callout type whitelist — 25 built-in types
244-
- Custom types via `custom-types` frontmatter option
240+
- Custom types via `custom-types` frontmatter option, with remapping
245241
- `pandoc-md` intermediate format for round-trip pipelines
246242
- No silent failures — unrecognised markers pass through unchanged
247243

_extensions/alerts-normalize/_extension.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
title: alerts-normalize
22
author: Pedro Luis Barrio
3-
version: 1.0.0
3+
version: 1.1.0
44
quarto-required: ">=1.4.0"
55
contributes:
66
filters:

_extensions/alerts-normalize/alerts-normalize.lua

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Per-document options (in frontmatter):
2626
custom-types:
2727
- spoiler
2828
- exercise
29+
- info: note # mapping: info renders as note
2930
3031
See copyright notice in file LICENSE.
3132
]]
@@ -231,6 +232,8 @@ end
231232

232233
-- # Normalizers
233234

235+
local TypeMap = {} -- optional kind remapping, e.g. info -> note
236+
234237
--- Known callout types for Pandoc/Sphinx plain div detection.
235238
local CalloutTypes = {
236239
-- core (all formats)
@@ -247,6 +250,7 @@ local CalloutTypes = {
247250
}
248251

249252
local function make_div(kind, blocks, title, collapse)
253+
kind = TypeMap[kind] or kind
250254
local attrs = {}
251255
if title and title ~= '' then attrs.title = title end
252256
if collapse == true then attrs.collapse = 'true' end
@@ -347,13 +351,23 @@ local function process_metadata(meta)
347351
-- out-format: pandoc-format
348352
-- custom-types:
349353
-- - spoiler
354+
-- - info: note
350355
local fmt = cfg['out-format']
351356
out_format = fmt and pandoc.utils.stringify(fmt)
352357
or (quarto ~= nil and 'quarto-format' or 'pandoc-format')
353358
local types = cfg['custom-types']
354359
if types then
355360
for _, v in ipairs(types) do
356-
CalloutTypes[pandoc.utils.stringify(v)] = true
361+
if type(v) == 'table' then
362+
-- mapping form: { info: note }
363+
for src, dst in pairs(v) do
364+
CalloutTypes[src] = true
365+
TypeMap[src] = pandoc.utils.stringify(dst)
366+
end
367+
else
368+
-- plain string: spoiler
369+
CalloutTypes[pandoc.utils.stringify(v)] = true
370+
end
357371
end
358372
end
359373
end

examples/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.quarto/
2+
**/*.quarto_ipynb

examples/Makefile

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,19 @@ QOUTDIR = output/quarto
77
# Target lists (Filenames only)
88
HTMLS = $(INPUTS:.md=.html)
99
EPUBS = $(INPUTS:.md=.epub)
10-
PDFS_LATEX = $(INPUTS:.md=-latex.pdf)
11-
PDFS_TYPST = $(INPUTS:.md=-typst.pdf)
1210

1311
.PHONY: all pandoc quarto html epub \
14-
pdf-latex-quarto pdf-typst-quarto html-quarto epub-quarto \
12+
pdf-latex-quarto pdf-typst-quarto \
1513
clean
1614

1715
all: pandoc quarto
1816

1917
# --- Grouped targets ---------------------------------------
2018
pandoc: html epub
2119

22-
quarto: html-quarto epub-quarto
23-
-$(MAKE) pdf-latex-quarto
24-
-$(MAKE) pdf-typst-quarto
25-
2620
# --- Target mapping -----------
27-
html: $(addprefix $(OUTDIR)/,$(HTMLS))
28-
epub: $(addprefix $(OUTDIR)/,$(EPUBS))
29-
30-
html-quarto: $(addprefix $(QOUTDIR)/,$(HTMLS))
31-
epub-quarto: $(addprefix $(QOUTDIR)/,$(EPUBS))
32-
pdf-latex-quarto: $(addprefix $(QOUTDIR)/,$(PDFS_LATEX))
33-
pdf-typst-quarto: $(addprefix $(QOUTDIR)/,$(PDFS_TYPST))
21+
html: $(addprefix $(OUTDIR)/,$(HTMLS))
22+
epub: $(addprefix $(OUTDIR)/,$(EPUBS))
3423

3524
$(OUTDIR) $(QOUTDIR):
3625
mkdir -p $@
@@ -43,18 +32,17 @@ $(OUTDIR)/%.epub: %.md | $(OUTDIR)
4332
-pandoc $(FILTERS) --css=./demo.css -o $@ $<
4433

4534
# --- Quarto rules ------------
46-
$(QOUTDIR)/%-latex.pdf: %.md | $(QOUTDIR)
47-
-quarto render $< --to pdf --pdf-engine=lualatex --output-dir=$(QOUTDIR) --output $(notdir $@)
48-
49-
$(QOUTDIR)/%-typst.pdf: %.md | $(QOUTDIR)
50-
-quarto render $< --to typst --output-dir=$(QOUTDIR) --output $(notdir $@)
35+
quarto: | $(QOUTDIR)
36+
-quarto render demo.md --to html
37+
-quarto render demo.md --to epub
38+
-$(MAKE) pdf-latex-quarto
39+
-$(MAKE) pdf-typst-quarto
5140

52-
$(QOUTDIR)/%.html: %.md | $(QOUTDIR)
53-
-quarto render $< --to html --output-dir=$(QOUTDIR)
41+
pdf-latex-quarto: | $(QOUTDIR)
42+
-quarto render demo.md --to pdf --pdf-engine=lualatex --output demo-latex.pdf
5443

55-
$(QOUTDIR)/%.epub: %.md | $(QOUTDIR)
56-
-quarto render $< --to epub --output-dir=$(QOUTDIR)
44+
pdf-typst-quarto: | $(QOUTDIR)
45+
-quarto render demo.md --to typst --output demo-typst.pdf
5746

5847
clean:
5948
rm -rf output
60-

examples/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ all supported input formats, output formats, and syntax variants.
1111
Pandoc 3.9, Quarto).
1212
- **`demo.css`**: GitHub Primer styles with Octicons (MIT License) embedded as
1313
Data URIs — generates self-contained, portable HTML.
14+
- **`example.qmd`**: Quarto entry point for the extension gallery — wraps `demo.md`.
15+
1416
- **`Makefile`**: Build targets for all output formats.
1517
- **`_quarto.yml`**: Quarto project config declaring the filter at `pre-ast`.
1618

@@ -19,20 +21,26 @@ all supported input formats, output formats, and syntax variants.
1921
### Pandoc (lightweight)
2022

2123
```sh
22-
make html
24+
make pandoc
2325
```
2426

2527
Renders `demo.md` via Pandoc with `demo.css`. Fast, no Quarto required.
2628

2729
### Quarto (native callouts)
2830

2931
```sh
30-
make html-quarto
32+
make quarto
3133
```
3234

3335
Renders via `quarto render` — produces native styled callout boxes with icons,
3436
colours, and collapse behaviour.
3537

38+
Altenatively you can just
39+
40+
```sh
41+
quarto render example.qmd
42+
```
43+
3644
### All formats
3745

3846
```sh

examples/_quarto.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
filters:
22
- at: pre-ast
33
path: ../alerts-normalize.lua
4+
5+
project:
6+
output-dir: output/quarto

0 commit comments

Comments
 (0)