diff options
| author | Albert Krewinkel <[email protected]> | 2022-10-12 11:48:21 +0200 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2022-10-12 11:58:18 +0200 |
| commit | 253d2e768a43c8ab3ad8e1c46b2bc4a02acec946 (patch) | |
| tree | 591d2f32798cdcd5d6b841b162bbd6aa654ce4bb /doc | |
| parent | 543cb5d45d3ebc4c5a504be42efd6febb3a9ceaa (diff) | |
Lua: support extensions in custom readers.
Like custom readers, like writers, can define the set of supported
extensions by setting a global. E.g.:
``` lua
reader_extensions = {
smart = true,
citations = false,
}
```
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/custom-readers.md | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/doc/custom-readers.md b/doc/custom-readers.md index 601d879dd..4d2009690 100644 --- a/doc/custom-readers.md +++ b/doc/custom-readers.md @@ -93,6 +93,47 @@ function ByteStringReader (input) end ``` +# Format extensions + +Custom readers can be built such that their behavior is +controllable through format extensions, such as `smart`, +`citations`, or `hard-line-breaks`. Supported extensions are those +that are present as a key in the global `reader_extensions` table. +Fields of extensions that are enabled default have the value +`true`, while those that are supported but disabled have value +`false`. + +Example: A writer with the following global table supports the +extensions `smart` and `citations`, with the former enabled and +the latter disabled by default: + +``` lua +reader_extensions = { + smart = true, + citations = false, +} +``` + +The users control extensions as usual, e.g., `pandoc -f +my-reader.lua+citations`. The extensions are accessible through +the reader options' `extensions` field, e.g.: + +``` lua +function Reader (input, opts) + print( + 'The citations extension is', + opts.extensions:includes 'citations' and 'enabled' or 'disabled' + ) + -- ... +end +``` + +Extensions that are neither enabled nor disabled in the +`reader_extensions` field are treated as unsupported by the +reader. Trying to modify such an extension via the command line +will lead to an error. + + # Example: plain text reader This is a simple example using [lpeg] to parse the input |
