From ee2f0021f9b59f0bca6eabf4884641da7a09e21d Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 5 Nov 2021 22:10:29 -0700 Subject: Add interface for custom readers written in Lua. (#7671) New module Text.Pandoc.Readers.Custom, exporting readCustom [API change]. Users can now do `-f myreader.lua` and pandoc will treat the script myreader.lua as a custom reader, which parses an input string to a pandoc AST, using the pandoc module defined for Lua filters. A sample custom reader can be found in data/reader.lua. Closes #7669. --- MANUAL.txt | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'MANUAL.txt') diff --git a/MANUAL.txt b/MANUAL.txt index 019d80bf0..7e9f9f85a 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -266,6 +266,7 @@ header when requesting a document from a URL: - `tikiwiki` ([TikiWiki markup]) - `twiki` ([TWiki markup]) - `vimwiki` ([Vimwiki]) + - the path of a custom Lua reader, see [Custom readers and writers] below ::: Extensions can be individually enabled or disabled by @@ -338,7 +339,7 @@ header when requesting a document from a URL: - `tei` ([TEI Simple]) - `xwiki` ([XWiki markup]) - `zimwiki` ([ZimWiki markup]) - - the path of a custom Lua writer, see [Custom writers] below + - the path of a custom Lua writer, see [Custom readers and writers] below ::: Note that `odt`, `docx`, `epub`, and `pdf` output will not be directed @@ -6574,19 +6575,35 @@ With these custom styles, you can use your input document as a reference-doc while creating docx output (see below), and maintain the same styles in your input and output files. -# Custom writers +# Custom readers and writers -Pandoc can be extended with custom writers written in [Lua]. (Pandoc -includes a Lua interpreter, so Lua need not be installed separately.) +Pandoc can be extended with custom readers and writers written +in [Lua]. (Pandoc includes a Lua interpreter, so Lua need not +be installed separately.) -To use a custom writer, simply specify the path to the Lua script -in place of the output format. For example: +To use a custom reader or writer, simply specify the path to the +Lua script in place of the input or output format. For example: pandoc -t data/sample.lua + pandoc -f my_custom_markup_language.lua -t latex -s -Creating a custom writer requires writing a Lua function for each -possible element in a pandoc document. To get a documented example -which you can modify according to your needs, do +A custom reader is a Lua script that defines one function, +Reader, which takes a string as input and returns a Pandoc +AST. See the [Lua filters documentation] for documentation +of the functions that are available for creating pandoc +AST elements. For parsing, the [lpeg] parsing library +is available by default. To see a sample custom reader: + + pandoc --print-default-data-file reader.lua + +Reader options are available via the global variable +`PANDOC_READER_OPTIONS`, as expalined in the [Lua filters +documentation]. + +A custom writer is a Lua script that defines a function +that specifies how to render each element in a Pandoc AST. +To see a documented example which you can modify according +to your needs: pandoc --print-default-data-file sample.lua @@ -6598,6 +6615,7 @@ default template with the name subdirectory of your user data directory (see [Templates]). [Lua]: https://www.lua.org +[lpeg]: http://www.inf.puc-rio.br/~roberto/lpeg/ # Reproducible builds -- cgit v1.2.3