Skip to content

Commit

Permalink
Add support for Export Snippets and Export Blocks
Browse files Browse the repository at this point in the history
Now these work:

* Export Snippets

  @@hugo:foo@@

* Export Blocks

  #+BEGIN_EXPORT hugo
  foo
  #+END_EXPORT
  • Loading branch information
kaushalmodi committed Dec 7, 2017
1 parent a4131a2 commit 1149f20
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ox-hugo.el
Expand Up @@ -606,6 +606,8 @@ newer."
(org-hugo-export-as-md a s v)))))
:translate-alist '((code . org-hugo-kbd-tags-maybe)
(example-block . org-hugo-example-block)
(export-block . org-hugo-export-block)
(export-snippet . org-hugo-export-snippet)
(headline . org-hugo-headline)
(inner-template . org-hugo-inner-template)
(keyword . org-hugo-keyword)
Expand Down Expand Up @@ -988,6 +990,36 @@ information."
(format "{{< highlight text %s>}}\n%s{{< /highlight >}}\n" linenos-str text))
(org-blackfriday-example-block example-block nil info))))

;;;; Export Snippet
(defun org-hugo-export-snippet (export-snippet _contents _info)
"Transcode a EXPORT-SNIPPET object from Org to Hugo-compatible Markdown.
CONTENTS is nil. INFO is a plist holding contextual information.
Example:
\"@@hugo:foo@@\"
exports verbatim to \"foo\" only when exported using `hugo'
backend."
(when (eq (org-export-snippet-backend export-snippet) 'hugo)
(org-element-property :value export-snippet)))

;;;; Export Block
(defun org-hugo-export-block (export-block _contents info)
"Transcode a EXPORT-BLOCK element from Org to Hugo-compatible Markdown.
CONTENTS is nil. INFO is a plist holding contextual information.
Example:
#+BEGIN_EXPORT hugo
foo
#+END_EXPORT
exports verbatim to \"foo\" only when exported using `hugo'
backend."
(when (string= (org-element-property :type export-block) "HUGO")
(org-element-property :value export-block)))

;;;; Headline
(defun org-hugo-headline (headline contents info)
"Transcode HEADLINE element into Markdown format.
Expand Down
10 changes: 10 additions & 0 deletions test/site/content-org/all-posts.org
Expand Up @@ -2638,6 +2638,16 @@ The front-matter for this post contains the default Creator string.
:EXPORT_FILE_NAME: custom-creator
:END:
The front-matter for this post contains a custom Creator string.
* Export snippets and blocks :export_snippet:export_block:
:PROPERTIES:
:EXPORT_FILE_NAME: export_snippets_and_blocks
:END:
** Export snippet
@@hugo:This will get exported only for Hugo exports, `verbatim`.@@
** Export block
#+BEGIN_EXPORT hugo
and **this too**.. `verbatim`.
#+END_EXPORT
* Miscellaneous Front Matter :front_matter:
** Hugo Aliases :aliases:
*** Alias without section portion 1
Expand Down
14 changes: 14 additions & 0 deletions test/site/content/posts/export_snippets_and_blocks.md
@@ -0,0 +1,14 @@
+++
title = "Export snippets and blocks"
tags = ["export-snippet", "export-block"]
draft = false
+++

## Export snippet {#export-snippet}

This will get exported only for Hugo exports, `verbatim`.


## Export block {#export-block}

and **this too**.. `verbatim`.

0 comments on commit 1149f20

Please sign in to comment.