<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>special-block on
A Scripter's Notes</title><link>https://scripter.co/tags/special-block/</link><description>Recent content in special-block
on A Scripter's Notes</description><language>en-us</language><managingEditor>kaushal.modi@gmail.com (Kaushal Modi)</managingEditor><webMaster>kaushal.modi@gmail.com (Kaushal Modi)</webMaster><lastBuildDate>Wed, 22 Apr 2026 08:24:58 -0400</lastBuildDate><generator>Hugo -- gohugo.io</generator><docs>https://validator.w3.org/feed/docs/rss2.html</docs><atom:link href="https://scripter.co/tags/special-block/index.xml" rel="self" type="application/rss+xml"/><item><title>Sidenotes using ox-hugo</title><link>https://scripter.co/sidenotes-using-ox-hugo/</link><description>&lt;blockquote>Adding sidenotes using a Hugo shortcode and ox-hugo.&lt;/blockquote>&lt;div class="ox-hugo-toc toc">
&lt;div class="heading">Table of Contents&lt;/div>
&lt;ul>
&lt;li>&lt;a href="#hugo-shortcode">Hugo shortcode&lt;/a>&lt;/li>
&lt;li>&lt;a href="#org-mode-special-block">Org mode special block&lt;/a>&lt;/li>
&lt;li>&lt;a href="#summary">Summary&lt;/a>
&lt;ul>
&lt;li>&lt;a href="#one-time-configuration">One-time configuration&lt;/a>&lt;/li>
&lt;li>&lt;a href="#org-special-block-sidenote">Org special block: &lt;code>sidenote&lt;/code>&lt;/a>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/div>
&lt;!--endtoc-->
&lt;p>The main focus of my &lt;a href="https://scripter.co/sidenotes-using-only-css/"> previous post &lt;/a> was the CSS for sidenotes. I also
showed the companion HTML wrapper needed for that CSS to work. Here it
is again for convenience:&lt;/p>
&lt;p>&lt;a id="code-snippet--sidenote-html-example">&lt;/a>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-html" data-lang="html">&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">span&lt;/span> &lt;span class="na">class&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;sidenote-number&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">small&lt;/span> &lt;span class="na">class&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;sidenote&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> sidenote content
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">small&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">span&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="src-block-caption">
&lt;span class="src-block-number">&lt;a href="#code-snippet--sidenote-html-example">Code Snippet 1&lt;/a>:&lt;/span>
Sidenote HTML example
&lt;/div>
&lt;h2 id="hugo-shortcode">Hugo shortcode&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#hugo-shortcode">#&lt;/a>&lt;/h2>
&lt;p>Now .. You might be thinking that it&amp;rsquo;s not too practical to type that
thing for each new sidenote. And you are right! That&amp;rsquo;s where we use
the &lt;a href="https://gohugo.io/content-management/shortcodes/">Hugo Shortcode&lt;/a> feature.
&lt;span class="sidenote-number">&lt;small class="sidenote">
&lt;em>Hugo Shortcodes&lt;/em> are like Org Macros that are typically used to
insert some HTML template around the user entered content.
&lt;/small>&lt;/span>
If you look at the &lt;a href="#code-snippet--sidenote-html-example">above snippet&lt;/a>, the outer &lt;code>span&lt;/code> and &lt;code>small&lt;/code> tags
are just HTML boilerplate that the user will need to type mechanically
around each sidenote. So the shortcodes are perfect for solving this
annoyance.&lt;/p>
&lt;p>If we design a &lt;em>paired&lt;/em> shortcode for this, the above HTML example
will change to below:&lt;/p>
&lt;p>&lt;a id="code-snippet--sidenote-shortcode-use">&lt;/a>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-md" data-lang="md">&lt;span class="line">&lt;span class="cl">{{% sidenote %}}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">sidenote content
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">{{% /sidenote %}}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="src-block-caption">
&lt;span class="src-block-number">&lt;a href="#code-snippet--sidenote-shortcode-use">Code Snippet 2&lt;/a>:&lt;/span>
Example use of the &lt;code>sidenote&lt;/code> shortcode
&lt;/div>
&lt;p>As you can see, this shortcode
&lt;span class="sidenote-number">&lt;small class="sidenote">
This is a markdown-rendering shortcode i.e. a shortcode with &lt;code>{{​% .. %}}&lt;/code> instead of &lt;code>{{​&amp;lt; .. &amp;gt;}}&lt;/code>. So the insides of this shortcode
will passed on to the Hugo Markdown renderer.
&lt;/small>&lt;/span>
&lt;em>now&lt;/em> enables the user to
&lt;mark>focus on content writing&lt;/mark> than on writing boilerplate HTML. And the definition of that shortcode
is pretty simple as well:&lt;/p>
&lt;p>&lt;a id="code-snippet--sidenote-shortcode">&lt;/a>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-html" data-lang="html">&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">span&lt;/span> &lt;span class="na">class&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;sidenote-number&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&amp;lt;&lt;/span>&lt;span class="nt">small&lt;/span> &lt;span class="na">class&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;sidenote&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>{{ .Inner }}&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">small&lt;/span>&lt;span class="p">&amp;gt;&amp;lt;/&lt;/span>&lt;span class="nt">span&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="src-block-caption">
&lt;span class="src-block-number">&lt;a href="#code-snippet--sidenote-shortcode">Code Snippet 3&lt;/a>:&lt;/span>
"sidenote.html" Hugo shortcode
&lt;/div>
&lt;p>The only Hugo-templating syntax used here is &lt;code>{{ .Inner }}&lt;/code>. You can
read more about it &lt;a href="https://gohugo.io/templates/shortcode-templates/#inner">here&lt;/a>, but the &lt;em>tl;dr&lt;/em> is that the &lt;code>.Inner&lt;/code> holds
whatever content the user entered &lt;em>inside&lt;/em> the &lt;code>{{​% sidenote %}}&lt;/code> and
&lt;code>{{​% /sidenote %}}&lt;/code> tags.&lt;/p>
&lt;p>Once you save &lt;a href="#code-snippet--sidenote-shortcode">that shortcode snippet&lt;/a> to a &lt;code>layouts/sidenote.html&lt;/code> file
in your Hugo site&amp;rsquo;s directory, you are ready to use it.&lt;/p>
&lt;div class="verse">
&lt;p>        🛑 But wait! 🛑&lt;br />&lt;/p>
&lt;/div>
&lt;h2 id="org-mode-special-block">Org mode special block&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#org-mode-special-block">#&lt;/a>&lt;/h2>
&lt;p>It would be a shame to populate the Org source of this blog with
Hugo-specific shortcodes when I am using &lt;a href="https://ox-hugo.scripter.co/">ox-hugo&lt;/a> 😄.&lt;/p>
&lt;p>So instead, we just use the plain-old Org special blocks and tell
&lt;em>ox-hugo&lt;/em> that this &amp;ldquo;sidenote&amp;rdquo; special block be exported as a
markdown-rendering Hugo shortcode. I do that by just placing this at
the top of my Org file
&lt;span class="sidenote-number">&lt;small class="sidenote">
See the &lt;a href="https://ox-hugo.scripter.co/doc/shortcodes/#hugo-paired-shortcodes">Hugo Paired Shortcodes&lt;/a> section in the &lt;em>ox-hugo&lt;/em> manual to learn
more about this.
&lt;/small>&lt;/span>
:&lt;/p>
&lt;p>&lt;a id="code-snippet--sidenote-hugo-paired-shortcode">&lt;/a>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-org" data-lang="org">&lt;span class="line">&lt;span class="cl">&lt;span class="cs">#+hugo_paired_shortcodes&lt;/span>&lt;span class="c">: %sidenote&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="src-block-caption">
&lt;span class="src-block-number">&lt;a href="#code-snippet--sidenote-hugo-paired-shortcode">Code Snippet 4&lt;/a>:&lt;/span>
&lt;code>#+hugo_paired_shortcodes&lt;/code> keyword for specifying "shortcode" special blocks
&lt;/div>
&lt;p>.. and then writing a &amp;ldquo;sidenote&amp;rdquo; type Org special block:&lt;/p>
&lt;p>&lt;a id="code-snippet--sidenote-special-block-use">&lt;/a>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-org" data-lang="org">&lt;span class="line">&lt;span class="cl">abc
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c">#+begin_sidenote&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">example sidenote content
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c">#+end_sidenote&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">def
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="src-block-caption">
&lt;span class="src-block-number">&lt;a href="#code-snippet--sidenote-special-block-use">Code Snippet 5&lt;/a>:&lt;/span>
Example use of the &lt;code>sidenote&lt;/code> special block
&lt;/div>
&lt;p>Normally, Org mode would insert a paragraph break where any Org block
(like that &lt;em>sidenote&lt;/em> special block) is used. So above would render
as:&lt;/p>
&lt;div style="color:green;" class="green">
&lt;p>abc&lt;/p>
&lt;p>&lt;span class="sidenote-number">&lt;small class="sidenote">
example sidenote content
&lt;/small>&lt;/span>&lt;/p>
&lt;p>def&lt;/p>
&lt;/div>
&lt;p>But I am pretty sure that nobody would render sidenote references in
their main text as above&amp;mdash;instead, below is more &lt;em>normal&lt;/em> 😄.&lt;/p>
&lt;div style="color:green;" class="green">
&lt;p>abc
&lt;span class="sidenote-number">&lt;small class="sidenote">
example sidenote content
&lt;/small>&lt;/span>
def&lt;/p>
&lt;/div>
&lt;p>In that &lt;em>normal&lt;/em> example of the sidenote, &lt;em>ox-hugo&lt;/em> trims the whitespace
around the &lt;em>sidenote&lt;/em> block. That is configured by customizing the
&lt;code>org-hugo-special-block-type-properties&lt;/code> variable:&lt;/p>
&lt;p>&lt;a id="code-snippet--sidenote-whitespace-trimming">&lt;/a>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-emacs-lisp" data-lang="emacs-lisp">&lt;span class="line">&lt;span class="cl">&lt;span class="p">(&lt;/span>&lt;span class="nb">with-eval-after-load&lt;/span> &lt;span class="ss">&amp;#39;ox-hugo&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">(&lt;/span>&lt;span class="nv">add-to-list&lt;/span> &lt;span class="ss">&amp;#39;org-hugo-special-block-type-properties&lt;/span> &lt;span class="o">&amp;#39;&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;sidenote&amp;#34;&lt;/span> &lt;span class="o">.&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nb">:trim-pre&lt;/span> &lt;span class="no">t&lt;/span> &lt;span class="nb">:trim-post&lt;/span> &lt;span class="no">t&lt;/span>&lt;span class="p">))))&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="src-block-caption">
&lt;span class="src-block-number">&lt;a href="#code-snippet--sidenote-whitespace-trimming">Code Snippet 6&lt;/a>:&lt;/span>
Whitespace trimming enabled by default for &lt;code>sidenote&lt;/code> special blocks
&lt;/div>
&lt;p>You can read more about this &lt;em>whitespace trimming&lt;/em> feature in the
&lt;a href="https://ox-hugo.scripter.co/doc/org-special-blocks/#whitespace-trimming">ox-hugo manual&lt;/a>.&lt;/p>
&lt;h2 id="summary">Summary&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#summary">#&lt;/a>&lt;/h2>
&lt;h3 id="one-time-configuration">One-time configuration&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#one-time-configuration">#&lt;/a>&lt;/h3>
&lt;ol>
&lt;li>Create and save a &amp;ldquo;sidenote&amp;rdquo; Hugo shortcode as shown &lt;a href="#code-snippet--sidenote-shortcode">here&lt;/a>.&lt;/li>
&lt;li>Configure &lt;em>ox-hugo&lt;/em> to export &amp;ldquo;sidenote&amp;rdquo; special block as a
markdown-rendering shortcode.&lt;/li>
&lt;li>Configure whitespace to be trimmed around those blocks using
&lt;code>org-hugo-special-block-type-properties&lt;/code> customization variable.&lt;/li>
&lt;/ol>
&lt;h3 id="org-special-block-sidenote">Org special block: &lt;code>sidenote&lt;/code>&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#org-special-block-sidenote">#&lt;/a>&lt;/h3>
&lt;p>Now just use the &lt;code>#+begin_sidenote&lt;/code> .. &lt;code>#+end_sidenote&lt;/code> Org special
blocks wherever you need sidenotes.&lt;/p></description><author>Kaushal.Modi@fakeEmailToMakeValidatorHappy.com (Kaushal Modi)</author><category domain="https://scripter.co/categories/emacs">emacs</category><category domain="https://scripter.co/categories/org">org</category><category domain="https://scripter.co/categories/hugo">hugo</category><category domain="https://scripter.co/categories/web">web</category><category domain="https://scripter.co/series/sidenotes">Sidenotes</category><category domain="https://scripter.co/tags/sidenotes">sidenotes</category><category domain="https://scripter.co/tags/100daystooffload">100DaysToOffload</category><category domain="https://scripter.co/tags/ox-hugo">ox-hugo</category><category domain="https://scripter.co/tags/shortcode">shortcode</category><category domain="https://scripter.co/tags/special-block">special-block</category><guid>https://scripter.co/sidenotes-using-ox-hugo/</guid><pubDate>Sat, 05 Feb 2022 18:14:00 -0500</pubDate></item></channel></rss>