Markdown source block with Hugo shortcodes
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.
{{< .. >}}
— Shortcodes without Markdown{{% .. %}}
— Shortcodes with Markdown
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.
|
|
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 Variable | Value | |
---|---|---|
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 |
| |
NextPage | Make the author front-matter plural | |
PrevPage | Markup Front-matter | |
NextInSection | Make the author front-matter plural | |
PrevInSection | Markup Front-matter |
Page Params (Debug)
Key | Type | Value |
---|---|---|
description | string | "Test verbatim use of Hugo shortcodes in content." |
draft | bool | false |
iscjklanguage | bool | false |
lastmod | time.Time | 2022-10-28 12:04:47 -0400 -0400 |
tags | []string | "src-block" "shortcode" |
title | string | "Markdown source block with Hugo shortcodes" |
File Object (Debug)
FileInfo Variable | Value |
---|---|
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" |