Skip to content

Commit 0a35d0f

Browse files
author
Alex Fenton
committed
Support format-specific snippets; pandoc target for snippets/blocks
Snippets with the @@ syntax should be supported in the same way as blocks already are. Adds 'pandoc as a possible target, allowing passing content only to this backend.
1 parent 9b3a750 commit 0a35d0f

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

README.org

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,17 @@ settings in your init file.
217217
* Feature Support
218218
** Source Code Blocks
219219
=ox-pandoc= supports the export of code blocks, including code blocks
220-
for specific formats (e.g. LaTeX). Code wrapped in =BEGIN_EXPORT
221-
[format]= will be passed to pandoc and included in the final output if
222-
the output is of the appropriate format.
220+
for specific output formats (e.g. LaTeX, HTML). Code wrapped in
221+
=#+BEGIN_EXPORT [format]= will be passed to pandoc as-is. Pandoc knows how
222+
to handle these blocks correctly and will include them in the final
223+
output if they match the target format. The same applies for short
224+
format-specific snippets using Org's =@@format:= syntax.
225+
226+
Blocks and snippets intended only for the pandoc backend can be
227+
specified using =#+BEGIN_EXPORT pandoc= and =@@pandoc:=. The inner
228+
content of these blocks and snippets will be passed to pandoc. This may
229+
be useful for adding extra information for output formats only supported
230+
by pandoc, not by Org's own native converters.
223231

224232
=ox-pandoc= also supports the evaluation of embedded code blocks wrapped
225233
with =BEGIN_SRC [language]=. The various options described by the

ox-pandoc.el

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ version. If nil, no checks are performed and no warnings generated."
247247
(org-export-define-derived-backend 'pandoc 'org
248248
:translate-alist '((entity . org-pandoc-entity)
249249
(export-block . org-pandoc-export-block)
250+
(export-snippet . org-pandoc-export-snippet)
250251
(latex-environment . org-pandoc-latex-environ)
251252
(link . org-pandoc-link)
252253
(paragraph . org-pandoc-paragraph)
@@ -1752,9 +1753,24 @@ contextual information."
17521753
"Transcode a EXPORT-BLOCK element from Org to Pandoc.
17531754
This might be EXPORT_HTML or EXPORT_LATEX, and is simply
17541755
duplicated into the temporary org file that pandoc converts.
1755-
CONTENTS is the contents of the block. INFO is a plist holding
1756-
contextual information."
1757-
(org-pandoc-identity export-block contents info))
1756+
Special: if the block is BEGIN_EXPORT pandoc, pass the value to
1757+
pandoc. CONTENTS is the contents of the block. INFO is a plist
1758+
holding contextual information."
1759+
(if (string= (org-element-property :type export-block) "PANDOC")
1760+
(org-element-property :value export-block)
1761+
(org-pandoc-identity export-block contents info)))
1762+
1763+
(defun org-pandoc-export-snippet (export-snippet contents info)
1764+
"Transcode a @@format:snippet@@ from Org to Pandoc.
1765+
If it is an output format, such as latex or html, the snippet is
1766+
duplicated in full for pandoc to handle as Org's own exporters
1767+
would. If the snippet specifies 'pandoc' as the format, the inner
1768+
content of the snippet is passed to pandoc. CONTENTS is the
1769+
contents of the block. INFO is a plist holding contextual
1770+
information."
1771+
(if (eq (org-export-snippet-backend export-snippet) 'pandoc)
1772+
(org-element-property :value export-snippet)
1773+
(org-pandoc-identity export-snippet contents info)))
17581774

17591775
(defun org-pandoc-identity (blob contents _info)
17601776
"Transcode BLOB element or object back into Org syntax.

0 commit comments

Comments
 (0)