.Kind (page): .Type (posts) / .Layout ()
Bundle: n/a (regular page)
[ categories | tags | search ]
ox-hugo Test Site

This is the test site for the ox-hugo package for Emacs/Org-mode.

It is updated automatically after each commit to the ox-hugo repo. It was last updated on Mar 05, 2024 19:24 UTC.


This page was created/modified in commit 8e2baca "fix: Escape Hugo shortcode markers in emacs-lisp src blocks as well" on 2022-10-28.
Markdown source of this page

Markdown source block with Hugo shortcodes

tags: src-block shortcode


Description/Summary

Test verbatim use of Hugo shortcodes in content.

Content

Shortcodes escaped #

The figure shortcodes in the two Markdown source code blocks below should not be expanded.. they should be visible verbatim.

Code block using code fences #

{{< figure src="https://ox-hugo.scripter.co/test/images/org-mode-unicorn-logo.png" >}}
{{% figure src="https://ox-hugo.scripter.co/test/images/org-mode-unicorn-logo.png" %}}

Code block using code fences with line numbering enabled #

Here, the -n switch is added to the Org source block to enable line numbering.

1
2
{{< figure src="https://ox-hugo.scripter.co/test/images/org-mode-unicorn-logo.png" >}}
{{% figure src="https://ox-hugo.scripter.co/test/images/org-mode-unicorn-logo.png" %}}

Shortcode escaped in Org source blocks #

#+macro: relref @@hugo:[@@ $1 @@hugo:]({{< relref "$2" >}})@@

Shortcode escaped in Emacs-Lisp source blocks #

ox-hugo Issue #680

;; Follow Hugo links
(defun org-hugo-follow (link)
  "Follow Hugo link shortcodes"
  (org-link-open-as-file
   (string-trim "{{% ref test.org %}}" "{{% ref " "%}}")))

;; New link type for Org-Hugo internal links
(org-link-set-parameters
 "hugo"
 :complete (lambda ()
             (concat "{{% ref */"
                     (file-name-nondirectory
                      (read-file-name "File: "))
                     " %}}"))
 :follow #'org-hugo-follow)

Shortcodes not escaped #

The figure shortcode in the below example block should be expanded.. you should be seeing a little unicorn below.

Above a #+begin_example .. #+end_example block is chosen arbitrarily. The Hugo shortcodes will remain unescaped in any source/example block except for Markdown source blocks (annotated with md language).

Below, the same figure shortcode is called with the % syntax.

Note
If you are using Hugo 0.55.0 or newer, you will just see the raw HTML from this shortcode (unrendered HTML) because the behavior of {{% .. %}} shortcodes changed in Hugo v0.55.0.
<figure><img src="https://ox-hugo.scripter.co/test/images/org-mode-unicorn-logo.png"/>
</figure>

It is necessary to set the Hugo site config variable markup.highlight.codeFences to true (default) for syntax highlighting to work for fenced code blocks.


Page (Debug)

Page VariableValue
Name "Markdown source block with Hugo shortcodes"
Title "Markdown source block with Hugo shortcodes"
ResourceType "page"
Kind "page"
Section "posts"
Draft false
Type "posts"
Layout ""
Permalink "https://ox-hugo.scripter.co/test/posts/source-block-md-with-hugo-shortcodes/"
RelPermalink "/posts/source-block-md-with-hugo-shortcodes/"
Data
page.Data{} (type:page.Data)
NextPageMake the author front-matter plural
PrevPageMarkup Front-matter
NextInSectionMake the author front-matter plural
PrevInSectionMarkup Front-matter

Page Params (Debug)

KeyTypeValue
descriptionstring "Test verbatim use of Hugo shortcodes in content."
draftbool false
iscjklanguagebool false
lastmodtime.Time 2022-10-28 12:04:47 -0400 -0400
tags[]string "src-block" "shortcode"
titlestring "Markdown source block with Hugo shortcodes"

File Object (Debug)

FileInfo VariableValue
UniqueID "7920471648f1003dde3ab430a09700c0"
BaseFileName "source-block-md-with-hugo-shortcodes"
TranslationBaseName "source-block-md-with-hugo-shortcodes"
Lang "en"
Section "posts"
LogicalName "source-block-md-with-hugo-shortcodes.md"
Dir "posts/"
Ext "md"
Path "posts/source-block-md-with-hugo-shortcodes.md"

This site is generated using the ox-hugo package for Emacs/Org-mode + hugo-bare-min-theme + Hugo 0.101.0 (commit 466fa43c16709b4483689930a4f9ac8add5c9f66) . This site is powered by Netlify.
[Test Site home | ox-hugo home]