aboutsummaryrefslogtreecommitdiff
path: root/doc/custom-writers.md
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2021-12-29 15:00:59 +0200
committerIgor Pashev <pashev.igor@gmail.com>2021-12-29 15:00:59 +0200
commitb4361712899fd0183fea5513180cb383979616de (patch)
tree688ab7ee2ab3a8cd32b4e37b506099aec95388f7 /doc/custom-writers.md
parent726ad97faebe59e024d68d293e663c02bbe423c8 (diff)
parentd960282b105a6469c760b4308a3b81da723b7256 (diff)
downloadpandoc-b4361712899fd0183fea5513180cb383979616de.tar.gz
Merge https://github.com/jgm/pandoc
Diffstat (limited to 'doc/custom-writers.md')
-rw-r--r--doc/custom-writers.md52
1 files changed, 52 insertions, 0 deletions
diff --git a/doc/custom-writers.md b/doc/custom-writers.md
new file mode 100644
index 000000000..6df603288
--- /dev/null
+++ b/doc/custom-writers.md
@@ -0,0 +1,52 @@
+---
+author:
+- John MacFarlane
+date: 'November 21, 2021'
+title: Creating Custom Pandoc Writers in Lua
+---
+
+# Introduction
+
+If you need to render a format not already handled by pandoc,
+or you want to change how pandoc renders a format,
+you can create a custom writer using the [Lua] language.
+Pandoc has a built-in Lua interpreter, so you needn't
+install any additional software to do this.
+
+[Lua]: https://www.lua.org
+
+A custom writer is a Lua file that defines functions for
+rendering each element of a pandoc AST.
+
+For example,
+
+``` lua
+function Para(s)
+ return "<paragraph>" .. s .. "</paragraph>"
+end
+```
+
+The best way to go about creating a custom writer is to modify
+the example that comes with pandoc. To get the example, you
+can do
+
+```
+pandoc --print-default-data-file sample.lua > sample.lua
+```
+
+# A custom HTML writer
+
+`sample.lua` is a full-features HTML writer, with explanatory
+comments. To use it, just use the path to the custom writer as
+the writer name:
+
+```
+pandoc -t sample.lua myfile.md
+```
+
+`sample.lua` defines all the functions needed by any custom
+writer, so you can design your own custom writer by modifying
+the functions in `sample.lua` according to your needs.
+
+``` {.lua include="sample.lua"}
+```