git.iko.soy/typeable/pandoc
on master help sign in
doc/org.md: add section on handling of unknown directives
commit29d4753cd92ddb0e890e6741c785c9a2109e5a18 authorAlbert Krewinkel <albert@zeitkraut.de> dateMon 21 Sep 2020, 11:35 (6 years ago) parentacbea6b
1 file changed+47
doc/org.md+47
doc/org.md+47
@@ -102,6 +102,53 @@ Pandoc recognizes some export options not used by Emacs Org.
102102 field is included by default on the title slide of beamer
103103 presentations.
104104
105+Other options
106+-------------
107+
108+Any export option or directive not listed above has no effect when
109+parsing with pandoc. However, the information is retained as a
110+*raw block*. It can be accessed through a
111+[filter](https://pandoc.org/filters.html) and will be included in
112+org output.
113+
114+### Directives as metadata
115+
116+As an example, we will restore an old behavior of pandoc versions
117+prior to 2.10. Unknown keywords were treated as variable
118+definitions, and were added the document's metadata. Typing
119+`#+key: value` in the org-file used to have the same effect as
120+running pandoc with the `--metadata key=value` option.
121+
122+Since pandoc 2.10, each unhandled line starting with `#+` is kept
123+internally as a raw block with format `org`. This block can be
124+inspected and processed by a filter. Below is a [Lua
125+filter](https://pandoc.org/lua-filters.html) which converts these
126+unhandled lines into metadata key-value pairs.
127+
128+``` lua
129+-- intermediate store for variables and their values
130+local variables = {}
131+
132+--- Function called for each raw block element.
133+function RawBlock (raw)
134+ -- Don't do anything unless the block contains *org* markup.
135+ if raw.format ~= 'org' then return nil end
136+
137+ -- extract variable name and value
138+ local name, value = raw.text:match '#%+(%w+):%s*(.+)$'
139+ if name and value then
140+ variables[name] = value
141+ end
142+end
143+
144+-- Add the extracted variables to the document's metadata.
145+function Meta (meta)
146+ for name, value in pairs(variables) do
147+ meta[name] = value
148+ end
149+ return meta
150+end
151+```
105152
106153Citations
107154=========