From 1d56e6059e65f3c207296e3feb5aa9ae8bcd4e9d Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 21 Nov 2021 10:07:05 -0800 Subject: Add custom-writers.md. --- doc/custom-writers.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 doc/custom-writers.md (limited to 'doc/custom-writers.md') diff --git a/doc/custom-writers.md b/doc/custom-writers.md new file mode 100644 index 000000000..b2258a95f --- /dev/null +++ b/doc/custom-writers.md @@ -0,0 +1,48 @@ +--- +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 "" .. s .. "" +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 +``` + +`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. + -- cgit v1.2.3 From 72075423d08e7cd2052f5325a17d52fc1d7682b3 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 6 Dec 2021 13:04:31 -0800 Subject: custom-writers.md: use filter to include source of example. --- doc/custom-writers.md | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'doc/custom-writers.md') diff --git a/doc/custom-writers.md b/doc/custom-writers.md index b2258a95f..6df603288 100644 --- a/doc/custom-writers.md +++ b/doc/custom-writers.md @@ -34,6 +34,8 @@ 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: @@ -46,3 +48,5 @@ pandoc -t sample.lua myfile.md writer, so you can design your own custom writer by modifying the functions in `sample.lua` according to your needs. +``` {.lua include="sample.lua"} +``` -- cgit v1.2.3