<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us"><generator uri="https://gohugo.io/" version="0.101.0">Hugo</generator><title type="html">diagrams on A Scripter's Notes</title><subtitle type="html">Emacs, scripting and anything text oriented.</subtitle><link href="https://scripter.co/tags/diagrams/" rel="alternate" type="text/html" title="HTML"/><link href="https://scripter.co/tags/diagrams/index.xml" rel="alternate" type="application/rss+xml" title="RSS"/><link href="https://scripter.co/tags/diagrams/atom.xml" rel="self" type="application/atom+xml" title="Atom"/><link href="https://scripter.co/tags/diagrams/jf2feed.json" rel="alternate" type="application/jf2feed+json" title="jf2feed"/><updated>2026-04-22T08:24:57-04:00</updated><author><name>Kaushal Modi</name><email>kaushal.modi@gmail.com</email></author><id>https://scripter.co/tags/diagrams/</id><entry><title type="html">Hugo: Use goat code blocks for ASCII diagrams</title><link href="https://scripter.co/hugo-use-goat-code-blocks-for-ascii-diagrams/?utm_source=atom_feed" rel="alternate" type="text/html"/><link href="https://scripter.co/using-emacs-advice-to-silence-messages-from-functions/?utm_source=atom_feed" rel="related" type="text/html" title="Using Emacs advice to silence messages from functions"/><link href="https://scripter.co/binding-nim-to-c-plus-plus-std-list/?utm_source=atom_feed" rel="related" type="text/html" title="Binding Nim to C++ std::list"/><link href="https://scripter.co/quick-intro-to-emacs-lisp-regression-testing/?utm_source=atom_feed" rel="related" type="text/html" title="Quick Intro to Emacs Lisp Regression Testing"/><link href="https://scripter.co/titleref-referencing-hugo-posts-by-their-titles/?utm_source=atom_feed" rel="related" type="text/html" title="titleref: Referencing Hugo posts by their titles"/><link href="https://scripter.co/hugo-modules-getting-started/?utm_source=atom_feed" rel="related" type="text/html" title="Hugo Modules: Getting Started"/><id>https://scripter.co/hugo-use-goat-code-blocks-for-ascii-diagrams/</id><author><name>Kaushal Modi</name></author><published>2022-04-07T23:44:00-04:00</published><updated>2022-04-07T23:44:00-04:00</updated><content type="html"><![CDATA[<blockquote>Use <code>goat</code> code blocks if you have ASCII diagrams with a mix of text
and box drawing characters.</blockquote><div class="ox-hugo-toc toc">
<div class="heading">Table of Contents</div>
<ul>
<li><a href="#references">References</a></li>
</ul>
</div>
<!--endtoc-->
<p><a href="https://github.com/gohugoio/hugo/releases/tag/v0.93.0">Hugo <strong>v0.93.0</strong></a> added some serious features like <a href="https://gohugo.io/templates/render-hooks/#render-hooks-for-code-blocks">Code Block Render
Hooks</a> and native rendering of ASCII diagrams to SVG using a <a href="https://github.com/blampe/goat">GoAT</a>
<span class="sidenote-number"><small class="sidenote">
Go ASCII Tool
</small></span>
library.</p>
<div class="note">
<p>To use this feature, you put ASCII diagrams in a code block with
language set to <code>goat</code> .. .. That&rsquo;s it!</p>
</div>
<p>I realized I needed to use this new GoAT rendering feature because if
I had an ASCII diagram with a mix of text and box drawing characters
like ┌ │ ─ ┐, the positional relationship between the text and those
characters wasn&rsquo;t always guaranteed to remain as I intended. The
reason is that based on the user&rsquo;s font setup, the box drawing
characters and the regular text characters could be rendered using
different fonts.</p>
<p>This problem is best shown with this example that I was documenting in
the <a href="https://ox-hugo.scripter.co/doc/hugo-section/"><code>ox-hugo</code> manual</a> <a href="https://github.com/kaushalmodi/ox-hugo/commit/88ae5c8c65a4f0d401b450338cf8bb36c47684fc">today</a>.</p>
<p><a id="code-snippet--ascii-diagram-in-text-src-block"></a></p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-org" data-lang="org"><span class="line"><span class="cl"><span class="c">#+begin_src </span><span class="cs">text</span><span class="c">
</span></span></span><span class="line"><span class="cl"><span class="c"></span>&lt;HUGO_BASE_DIR&gt;/content/&lt;HUGO_SECTION&gt;/&lt;concatenated values of EXPORT_HUGO_SECTION_FRAG&gt;/
</span></span><span class="line"><span class="cl">                        └─────────────────────  section path  ─────────────────────────┘
</span></span><span class="line"><span class="cl"><span class="c">#+end_src</span>
</span></span></code></pre></div><div class="src-block-caption">
  <span class="src-block-number"><a href="#code-snippet--ascii-diagram-in-text-src-block">Code Snippet 1</a>:</span>
  Mix of text and box characters in a plain <code>text</code> code block
</div>
<p>Above code block renders to:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">&lt;HUGO_BASE_DIR&gt;/content/&lt;HUGO_SECTION&gt;/&lt;concatenated values of EXPORT_HUGO_SECTION_FRAG&gt;/
</span></span><span class="line"><span class="cl">                        └─────────────────────  section path  ─────────────────────────┘
</span></span></code></pre></div><p>The code block rendered above might look alright on your browser based
on your font setup.</p>
<ul>
<li>The &ldquo;section path&rdquo; box drawing should start at <code>&lt;HUGO_SECTION&gt;/ ..</code>
and end at <code>.. EXPORT_HUGO_SECTION_FRAG&gt;</code>.</li>
</ul>
<p>But it can also look like below with a different font setup:</p>
<p><a id="figure--disproportionate-box-drawing"></a></p>



<figure>
    
        <img src="https://scripter.co/hugo-use-goat-code-blocks-for-ascii-diagrams/ascii-diagram-rendered-in-plain-text-code-block.png" alt="Figure 1: Disproportionate box drawing characters"/> <figcaption>
                <p>
                    <span class="figure-number">Figure 1: </span>Disproportionate box drawing characters
                    
                        
                        </p>
                
            </figcaption></figure>

<p>To fix that, we simply change the code block language to <code>goat</code>
<span class="sidenote-number"><small class="sidenote">
If you author your posts in Markdown, this applies to you too. Just
use the Markdown fenced code block syntax: <code>```goat .. ```</code>.
</small></span>
<a id="code-snippet--ascii-diagram-in-goat-src-block"></a></p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-org" data-lang="org"><span class="line"><span class="cl"><span class="c">#+begin_src </span><span class="cs">goat</span><span class="c">
</span></span></span><span class="line"><span class="cl"><span class="c"></span>&lt;HUGO_BASE_DIR&gt;/content/&lt;HUGO_SECTION&gt;/&lt;concatenated values of EXPORT_HUGO_SECTION_FRAG&gt;/
</span></span><span class="line"><span class="cl">                        └─────────────────────  section path  ─────────────────────────┘
</span></span><span class="line"><span class="cl"><span class="c">#+end_src</span>
</span></span></code></pre></div><div class="src-block-caption">
  <span class="src-block-number"><a href="#code-snippet--ascii-diagram-in-goat-src-block">Code Snippet 2</a>:</span>
  Mix of text and box characters in a <code>goat</code> code block
</div>
<p>Now we will see the below rendering on any browser because you are
looking at the SVG generated from the above code block by that <em>GoAT</em>
library.</p>



<div class="goat svg-container ">
  
    <svg
      xmlns="http://www.w3.org/2000/svg"
      font-family="Menlo,Lucida Console,monospace"
      
        viewBox="0 0 720 41"
      >
      <g transform='translate(8,16)'>
<text text-anchor='middle' x='0' y='4' fill='currentColor' style='font-size:1em'>&lt;</text>
<text text-anchor='middle' x='8' y='4' fill='currentColor' style='font-size:1em'>H</text>
<text text-anchor='middle' x='16' y='4' fill='currentColor' style='font-size:1em'>U</text>
<text text-anchor='middle' x='24' y='4' fill='currentColor' style='font-size:1em'>G</text>
<text text-anchor='middle' x='32' y='4' fill='currentColor' style='font-size:1em'>O</text>
<text text-anchor='middle' x='40' y='4' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='48' y='4' fill='currentColor' style='font-size:1em'>B</text>
<text text-anchor='middle' x='56' y='4' fill='currentColor' style='font-size:1em'>A</text>
<text text-anchor='middle' x='64' y='4' fill='currentColor' style='font-size:1em'>S</text>
<text text-anchor='middle' x='72' y='4' fill='currentColor' style='font-size:1em'>E</text>
<text text-anchor='middle' x='80' y='4' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='88' y='4' fill='currentColor' style='font-size:1em'>D</text>
<text text-anchor='middle' x='96' y='4' fill='currentColor' style='font-size:1em'>I</text>
<text text-anchor='middle' x='104' y='4' fill='currentColor' style='font-size:1em'>R</text>
<text text-anchor='middle' x='112' y='4' fill='currentColor' style='font-size:1em'>&gt;</text>
<text text-anchor='middle' x='120' y='4' fill='currentColor' style='font-size:1em'>/</text>
<text text-anchor='middle' x='128' y='4' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='136' y='4' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='144' y='4' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='152' y='4' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='160' y='4' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='168' y='4' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='176' y='4' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='184' y='4' fill='currentColor' style='font-size:1em'>/</text>
<text text-anchor='middle' x='192' y='4' fill='currentColor' style='font-size:1em'>&lt;</text>
<text text-anchor='middle' x='192' y='20' fill='currentColor' style='font-size:1em'>└</text>
<text text-anchor='middle' x='200' y='4' fill='currentColor' style='font-size:1em'>H</text>
<text text-anchor='middle' x='200' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='208' y='4' fill='currentColor' style='font-size:1em'>U</text>
<text text-anchor='middle' x='208' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='216' y='4' fill='currentColor' style='font-size:1em'>G</text>
<text text-anchor='middle' x='216' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='224' y='4' fill='currentColor' style='font-size:1em'>O</text>
<text text-anchor='middle' x='224' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='232' y='4' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='232' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='240' y='4' fill='currentColor' style='font-size:1em'>S</text>
<text text-anchor='middle' x='240' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='248' y='4' fill='currentColor' style='font-size:1em'>E</text>
<text text-anchor='middle' x='248' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='256' y='4' fill='currentColor' style='font-size:1em'>C</text>
<text text-anchor='middle' x='256' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='264' y='4' fill='currentColor' style='font-size:1em'>T</text>
<text text-anchor='middle' x='264' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='272' y='4' fill='currentColor' style='font-size:1em'>I</text>
<text text-anchor='middle' x='272' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='280' y='4' fill='currentColor' style='font-size:1em'>O</text>
<text text-anchor='middle' x='280' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='288' y='4' fill='currentColor' style='font-size:1em'>N</text>
<text text-anchor='middle' x='288' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='296' y='4' fill='currentColor' style='font-size:1em'>&gt;</text>
<text text-anchor='middle' x='296' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='304' y='4' fill='currentColor' style='font-size:1em'>/</text>
<text text-anchor='middle' x='304' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='312' y='4' fill='currentColor' style='font-size:1em'>&lt;</text>
<text text-anchor='middle' x='312' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='320' y='4' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='320' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='328' y='4' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='328' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='336' y='4' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='336' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='344' y='4' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='344' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='352' y='4' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='352' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='360' y='4' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='360' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='368' y='4' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='376' y='4' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='384' y='4' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='384' y='20' fill='currentColor' style='font-size:1em'>s</text>
<text text-anchor='middle' x='392' y='4' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='392' y='20' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='400' y='4' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='400' y='20' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='408' y='4' fill='currentColor' style='font-size:1em'>d</text>
<text text-anchor='middle' x='408' y='20' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='416' y='20' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='424' y='4' fill='currentColor' style='font-size:1em'>v</text>
<text text-anchor='middle' x='424' y='20' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='432' y='4' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='432' y='20' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='440' y='4' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='448' y='4' fill='currentColor' style='font-size:1em'>u</text>
<text text-anchor='middle' x='448' y='20' fill='currentColor' style='font-size:1em'>p</text>
<text text-anchor='middle' x='456' y='4' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='456' y='20' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='464' y='4' fill='currentColor' style='font-size:1em'>s</text>
<text text-anchor='middle' x='464' y='20' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='472' y='20' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='480' y='4' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='488' y='4' fill='currentColor' style='font-size:1em'>f</text>
<text text-anchor='middle' x='496' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='504' y='4' fill='currentColor' style='font-size:1em'>E</text>
<text text-anchor='middle' x='504' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='512' y='4' fill='currentColor' style='font-size:1em'>X</text>
<text text-anchor='middle' x='512' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='520' y='4' fill='currentColor' style='font-size:1em'>P</text>
<text text-anchor='middle' x='520' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='528' y='4' fill='currentColor' style='font-size:1em'>O</text>
<text text-anchor='middle' x='528' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='536' y='4' fill='currentColor' style='font-size:1em'>R</text>
<text text-anchor='middle' x='536' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='544' y='4' fill='currentColor' style='font-size:1em'>T</text>
<text text-anchor='middle' x='544' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='552' y='4' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='552' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='560' y='4' fill='currentColor' style='font-size:1em'>H</text>
<text text-anchor='middle' x='560' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='568' y='4' fill='currentColor' style='font-size:1em'>U</text>
<text text-anchor='middle' x='568' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='576' y='4' fill='currentColor' style='font-size:1em'>G</text>
<text text-anchor='middle' x='576' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='584' y='4' fill='currentColor' style='font-size:1em'>O</text>
<text text-anchor='middle' x='584' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='592' y='4' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='592' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='600' y='4' fill='currentColor' style='font-size:1em'>S</text>
<text text-anchor='middle' x='600' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='608' y='4' fill='currentColor' style='font-size:1em'>E</text>
<text text-anchor='middle' x='608' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='616' y='4' fill='currentColor' style='font-size:1em'>C</text>
<text text-anchor='middle' x='616' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='624' y='4' fill='currentColor' style='font-size:1em'>T</text>
<text text-anchor='middle' x='624' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='632' y='4' fill='currentColor' style='font-size:1em'>I</text>
<text text-anchor='middle' x='632' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='640' y='4' fill='currentColor' style='font-size:1em'>O</text>
<text text-anchor='middle' x='640' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='648' y='4' fill='currentColor' style='font-size:1em'>N</text>
<text text-anchor='middle' x='648' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='656' y='4' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='656' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='664' y='4' fill='currentColor' style='font-size:1em'>F</text>
<text text-anchor='middle' x='664' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='672' y='4' fill='currentColor' style='font-size:1em'>R</text>
<text text-anchor='middle' x='672' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='680' y='4' fill='currentColor' style='font-size:1em'>A</text>
<text text-anchor='middle' x='680' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='688' y='4' fill='currentColor' style='font-size:1em'>G</text>
<text text-anchor='middle' x='688' y='20' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='696' y='4' fill='currentColor' style='font-size:1em'>&gt;</text>
<text text-anchor='middle' x='696' y='20' fill='currentColor' style='font-size:1em'>┘</text>
<text text-anchor='middle' x='704' y='4' fill='currentColor' style='font-size:1em'>/</text>
</g>

    </svg>
  
</div>
<dl>
<dt>Caveat</dt>
<dd>The GoAT library doesn&rsquo;t render the text fonts to my
liking, but it&rsquo;s still better than completely messing up the
positional relationship between the text and the box diagram
characters.</dd>
</dl>
<p>Happy grazing! 🐐</p>

<h2 id="references">References&nbsp;<a class="headline-hash no-text-decoration" href="#references">#</a></h2>


<ul>
<li><a href="https://gohugo.io/content-management/diagrams/">Hugo Documentation &ndash; Diagrams</a></li>
</ul>
]]></content><category scheme="https://scripter.co/categories/hugo" term="hugo" label="hugo"/><category scheme="https://scripter.co/tags/ascii" term="ascii" label="ascii"/><category scheme="https://scripter.co/tags/diagrams" term="diagrams" label="diagrams"/><category scheme="https://scripter.co/tags/100daystooffload" term="100daystooffload" label="100DaysToOffload"/></entry></feed>