# Consensus on script to include asciidoc diagrams in hugo posts

**URL:** <https://discourse.gohugo.io/t/consensus-on-script-to-include-asciidoc-diagrams-in-hugo-posts/27970>\
**Category:** support\
**Tags:** asciidoc\
**Created:** [September 2, 2020, 3:27pm UTC](https://discourse.gohugo.io/t/consensus-on-script-to-include-asciidoc-diagrams-in-hugo-posts/27970 "2020-09-02T15:27:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![00krishna](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/00krishna/32/14017_2.png) [@00krishna](https://discourse.gohugo.io/u/00krishna)\
**Post date:** [September 2, 2020, 3:27pm UTC](https://discourse.gohugo.io/t/consensus-on-script-to-include-asciidoc-diagrams-in-hugo-posts/27970/1 "2020-09-02T15:27:50Z")

</div>

I am still new to Hugo, so still trying to get a feel for everything. One challenge I ran into has to do with including diagrams in my posts. So I write my posts in Asciidoc, and there are some nice tools like `asciidoctor-diagrams` that allow me to include graphviz, mermaid, or planetuml diagrams in the final pdf or html pages.

It seems that Hugo does not currently support running `asciidoctor-diagrams` when calling the `asciidoctor` tool to compile posts. So various people have posted about scripts they developed to get around this limitation. I include a few examples of these scripts below. BUT, my question is really whether there is a consensus on the best way to do this now? I was not sure what the latest thinking or approach was. Each of these scripts do similar things but in slightly different ways. So I figured I would ask.

Once [post](https://zipproth.de/cheat-sheets/hugo-asciidoctor/) had a script like this:

```auto
#!/bin/bash
if [-f /usr/local/bin/asciidoctor]; then
  ad="/usr/local/bin/asciidoctor"
else
  ad="/usr/bin/asciidoctor"
fi

$ad -v -B . -r asciidoctor-diagram -a icons=font -a docinfo=shared -a nofooter -a sectanchors -a experimental=true -a figure-caption! -a source-highlighter=highlightjs -a toc-title! -a stem=mathjax - | sed -E -e "s/img src=\"([^/]+)\"/img src=\"\/diagram\/\1\"/"

mkdir -p static/diagram

if ls *.svg >/dev/null 2>&1; then
  mv -f *.svg static/diagram
fi

if ls *.png >/dev/null 2>&1; then
  mv -f *.png static/diagram
fi

```

Another [post](https://dburet.gitlab.io/blog/2020-01-18-hugo-adoc-plant/) looked like this using `safe` mode:

```auto
#!/bin/bash

ARGS=$(echo "$@" | sed -e 's/--safe//')

/usr/bin/asciidoctor_real -r asciidoctor-html5s -r asciidoctor-diagram -b html5s $ARGS

```

And there was also a pull request on this topic as well.

gohugo PR #7281

But I don’t really know which approaches work, is there any consensus around the best approach, etc.

@muenchhausen if you have any thoughts, please chime in since the pull request was created by you.

---

<div class="post-metadata">

**Author:** ![muenchhausen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/muenchhausen/32/7814_2.png) [@muenchhausen](https://discourse.gohugo.io/u/muenchhausen)\
**Post date:** [September 2, 2020, 5:44pm UTC](https://discourse.gohugo.io/t/consensus-on-script-to-include-asciidoc-diagrams-in-hugo-posts/27970/2 "2020-09-02T17:44:05Z")

</div>

Since Hugo release 0.74.0, you do not need any hack on `asciidoctor` cli any longer. This should be obsolete (hopefully). You can configure all necessary extensions in Hugo `config.toml` excplicitly. You find this documented in [Hugo external-helper-asciidoctor](https://gohugo.io/content-management/formats/#external-helper-asciidoctor). Please make sure that `workingFolderCurrent = true` is set. A sample project in progress can be found [here](https://github.com/muenchhausen/hugo_asciidoc_ddd).

---

<div class="post-metadata">

**Author:** ![00krishna](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/00krishna/32/14017_2.png) [@00krishna](https://discourse.gohugo.io/u/00krishna)\
**Post date:** [September 2, 2020, 8:33pm UTC](https://discourse.gohugo.io/t/consensus-on-script-to-include-asciidoc-diagrams-in-hugo-posts/27970/3 "2020-09-02T20:33:08Z")

</div>

@muenchhausen Okay excellent. Yes, I am so glad that this is working now and I don’t need to mess around with the scripts. I ended up having to upgrade Hugo to the current version, but this started working after that. Thanks so much for your help.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [September 4, 2020, 8:33pm UTC](https://discourse.gohugo.io/t/consensus-on-script-to-include-asciidoc-diagrams-in-hugo-posts/27970/4 "2020-09-04T20:33:08Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
