From 18b1def96f7441d92ddbf7f870baaced68b4e014 Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Fri, 8 Dec 2017 10:34:07 -0500 Subject: [PATCH] Support html and md backend tagged export snippets and export blocks Now export snippets and export blocks tagged with "md", "markdown" or "html" get exported by ox-hugo as well. Fixes https://github.com/kaushalmodi/ox-hugo/issues/107 --- ox-hugo.el | 32 +++++++--- test/site/content-org/all-posts.org | 59 +++++++++++++++++-- test/site/content/posts/export_block_html.md | 8 +++ test/site/content/posts/export_block_hugo.md | 7 +++ .../content/posts/export_block_markdown.md | 10 ++++ .../site/content/posts/export_snippet_html.md | 7 +++ .../site/content/posts/export_snippet_hugo.md | 13 ++++ .../content/posts/export_snippet_markdown.md | 14 +++++ .../posts/export_snippets_and_blocks.md | 14 ----- 9 files changed, 137 insertions(+), 27 deletions(-) create mode 100644 test/site/content/posts/export_block_html.md create mode 100644 test/site/content/posts/export_block_hugo.md create mode 100644 test/site/content/posts/export_block_markdown.md create mode 100644 test/site/content/posts/export_snippet_html.md create mode 100644 test/site/content/posts/export_snippet_hugo.md create mode 100644 test/site/content/posts/export_snippet_markdown.md delete mode 100644 test/site/content/posts/export_snippets_and_blocks.md diff --git a/ox-hugo.el b/ox-hugo.el index 8681bdc..f53573b 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -1000,12 +1000,22 @@ 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))) +backend. + +Export snippets with backend tags \"markdown:\" and \"md:\" are +also handled. Exporting of export snippets with backend tag +\"html:\" uses the HTML exporter." + (cond + ((member (org-export-snippet-backend export-snippet) '(hugo markdown md)) + ;; ox-md.el does not support export snippets, so let's handle + ;; Markdown export snippets here as well. + (org-element-property :value export-snippet)) + ;; Also include HTML export snippets. + (t + (org-export-with-backend 'html export-snippet nil nil)))) ;;;; Export Block -(defun org-hugo-export-block (export-block _contents info) +(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. @@ -1016,9 +1026,17 @@ Example: #+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))) +backend. + +If the backend tag is \"markdown\"/\"md\" or \"html\", exporting +of those blocks falls back to the respective exporters." + (cond + ((string= (org-element-property :type export-block) "HUGO") + (org-remove-indentation (org-element-property :value export-block))) + ;; Also include Markdown and HTML export blocks. + ;; ox-md handles HTML export blocks too. + (t + (org-export-with-backend 'md export-block nil nil)))) ;;;; Headline (defun org-hugo-headline (headline contents info) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 651ab5c..a0d3876 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -2657,15 +2657,62 @@ 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: +* Export snippets and blocks +** Export snippet :export_snippet: +*** Export snippet Hugo :hugo: :PROPERTIES: -:EXPORT_FILE_NAME: export_snippets_and_blocks +:EXPORT_FILE_NAME: export_snippet_hugo +:END: +@@hugo:This will get exported **only for** Hugo exports, `verbatim`.@@ + +@@newlines +are not +allowed@@ + +If you want newlines, use *Export Blocks* instead. +*** Export snippet Markdown :markdown: +:PROPERTIES: +:EXPORT_FILE_NAME: export_snippet_markdown +:END: +@@md:This Markdown **Export Snippet** will also get exported for Hugo exports, `verbatim`.@@ + +@@markdown:_This one too_@@ +- NOTE :: =ox-md.el= does not support *Export Snippets* as of writing + this <2017-12-08 Fri>. So even the =@@md:foo@@= and + =@@markdown:foo@@= snippets are handled by =ox-hugo= + directly. +*** Export snippet HTML :html: +:PROPERTIES: +:EXPORT_FILE_NAME: export_snippet_html +:END: +@@html:This HTML Export Snippet will also get exported for Hugo exports, verbatim.@@ +** Export block :export_block: +*** Export block Hugo :hugo: +:PROPERTIES: +:EXPORT_FILE_NAME: export_block_hugo :END: -** Export snippet -@@hugo:This will get exported only for Hugo exports, `verbatim`.@@ -** Export block #+BEGIN_EXPORT hugo -and **this too**.. `verbatim`. +This will get exported **only for** Hugo exports, `verbatim`. +#+END_EXPORT +*** Export block Markdown :markdown: +:PROPERTIES: +:EXPORT_FILE_NAME: export_block_markdown +:END: +#+BEGIN_EXPORT markdown +This Markdown **Export Block** will also get exported for Hugo exports, +`verbatim` .. +#+END_EXPORT + +#+BEGIN_EXPORT md +and **this too**. +#+END_EXPORT +*** Export block HTML :html: +:PROPERTIES: +:EXPORT_FILE_NAME: export_block_html +:END: +#+BEGIN_EXPORT html +This HTML Export Block will also get exported for Hugo exports, +verbatim. #+END_EXPORT * Miscellaneous Front Matter :front_matter: ** Hugo Aliases :aliases: diff --git a/test/site/content/posts/export_block_html.md b/test/site/content/posts/export_block_html.md new file mode 100644 index 0000000..69b53e0 --- /dev/null +++ b/test/site/content/posts/export_block_html.md @@ -0,0 +1,8 @@ ++++ +title = "Export block HTML" +tags = ["export-block", "html"] +draft = false ++++ + +This HTML Export Block will also get exported for Hugo exports, +verbatim. diff --git a/test/site/content/posts/export_block_hugo.md b/test/site/content/posts/export_block_hugo.md new file mode 100644 index 0000000..46f6337 --- /dev/null +++ b/test/site/content/posts/export_block_hugo.md @@ -0,0 +1,7 @@ ++++ +title = "Export block Hugo" +tags = ["export-block", "hugo"] +draft = false ++++ + +This will get exported **only for** Hugo exports, `verbatim`. diff --git a/test/site/content/posts/export_block_markdown.md b/test/site/content/posts/export_block_markdown.md new file mode 100644 index 0000000..ef404f7 --- /dev/null +++ b/test/site/content/posts/export_block_markdown.md @@ -0,0 +1,10 @@ ++++ +title = "Export block Markdown" +tags = ["export-block", "markdown"] +draft = false ++++ + +This Markdown **Export Block** will also get exported for Hugo exports, +`verbatim` .. + +and **this too**. diff --git a/test/site/content/posts/export_snippet_html.md b/test/site/content/posts/export_snippet_html.md new file mode 100644 index 0000000..c25d90b --- /dev/null +++ b/test/site/content/posts/export_snippet_html.md @@ -0,0 +1,7 @@ ++++ +title = "Export snippet HTML" +tags = ["export-snippet", "html"] +draft = false ++++ + +This HTML Export Snippet will also get exported for Hugo exports, verbatim. diff --git a/test/site/content/posts/export_snippet_hugo.md b/test/site/content/posts/export_snippet_hugo.md new file mode 100644 index 0000000..c3af7fb --- /dev/null +++ b/test/site/content/posts/export_snippet_hugo.md @@ -0,0 +1,13 @@ ++++ +title = "Export snippet Hugo" +tags = ["export-snippet", "hugo"] +draft = false ++++ + +This will get exported **only for** Hugo exports, `verbatim`. + +@@newlines +are not +allowed@@ + +If you want newlines, use **Export Blocks** instead. diff --git a/test/site/content/posts/export_snippet_markdown.md b/test/site/content/posts/export_snippet_markdown.md new file mode 100644 index 0000000..7ce141b --- /dev/null +++ b/test/site/content/posts/export_snippet_markdown.md @@ -0,0 +1,14 @@ ++++ +title = "Export snippet Markdown" +tags = ["export-snippet", "markdown"] +draft = false ++++ + +This Markdown **Export Snippet** will also get exported for Hugo exports, `verbatim`. + +_This one too_ + +- **NOTE:** `ox-md.el` does not support **Export Snippets** as of writing + this <2017-12-08 Fri>. So even the `@@md:foo@@` and + `@@markdown:foo@@` snippets are handled by `ox-hugo` + directly. diff --git a/test/site/content/posts/export_snippets_and_blocks.md b/test/site/content/posts/export_snippets_and_blocks.md deleted file mode 100644 index 0aea496..0000000 --- a/test/site/content/posts/export_snippets_and_blocks.md +++ /dev/null @@ -1,14 +0,0 @@ -+++ -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`.