Skip to content

Commit 1d56e60

Browse files
committed
Add custom-writers.md.
1 parent a9e5145 commit 1d56e60

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

changelog.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Revision history for pandoc
1+
## Revision history for pandoc
22

33
## pandoc 2.16.2 (2021-11-21)
44

@@ -147,13 +147,16 @@
147147
* Require Cabal 2.4. Use wildcards to ensure that all pptx tests are
148148
included (#7677).
149149

150-
* Update bash_completion.tpl (S.P.H.).
150+
* Update `bash_completion.tpl` (S.P.H.).
151151

152152
* Add `data/creole.lua` as sample custom reader.
153153

154-
* Add `doc/custom-readers.md`.
154+
* Add `doc/custom-readers.md` and `doc/custom-writers.md`.
155155

156-
* MANUAL.txt: update table of exit codes and corresponding errors
156+
* `doc/lua-filters.md`: add section on global modules, including lpeg
157+
(Albert Krewinkel).
158+
159+
* `MANUAL.txt`: update table of exit codes and corresponding errors
157160
(Albert Krewinkel).
158161

159162
* Use latest texmath.

doc/custom-writers.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
author:
3+
- John MacFarlane
4+
date: 'November 21, 2021'
5+
title: Creating Custom Pandoc Writers in Lua
6+
---
7+
8+
# Introduction
9+
10+
If you need to render a format not already handled by pandoc,
11+
or you want to change how pandoc renders a format,
12+
you can create a custom writer using the [Lua] language.
13+
Pandoc has a built-in Lua interpreter, so you needn't
14+
install any additional software to do this.
15+
16+
[Lua]: https://www.lua.org
17+
18+
A custom writer is a Lua file that defines functions for
19+
rendering each element of a pandoc AST.
20+
21+
For example,
22+
23+
``` lua
24+
function Para(s)
25+
return "<paragraph>" .. s .. "</paragraph>"
26+
end
27+
```
28+
29+
The best way to go about creating a custom writer is to modify
30+
the example that comes with pandoc. To get the example, you
31+
can do
32+
33+
```
34+
pandoc --print-default-data-file sample.lua > sample.lua
35+
```
36+
37+
`sample.lua` is a full-features HTML writer, with explanatory
38+
comments. To use it, just use the path to the custom writer as
39+
the writer name:
40+
41+
```
42+
pandoc -t sample.lua myfile.md
43+
```
44+
45+
`sample.lua` defines all the functions needed by any custom
46+
writer, so you can design your own custom writer by modifying
47+
the functions in `sample.lua` according to your needs.
48+

0 commit comments

Comments
 (0)