On this page
The short answerWhere Hugo holds documentation codeWalk through a Hugo exampleWhat the engine seesMake the check repeatableWhere DocsAlive fitsThe sources we checkedFAQThe short answer
Test Hugo documentation examples as reader-facing programs, and check that your test actually finds the forms your theme renders. In engine 0.6.3, DocsAlive treats Hugo as plain Markdown: it can run supported fenced examples, but code inside the highlight shortcode or Docsy code tabs is invisible to its extractor. Limit the scan to the intended content, inspect skipped and unchecked blocks, and separately check the rendered site and any shortcode content.
Hugo gives documentation teams several ways to present code. That flexibility is useful for authors, but it also makes coverage easy to overestimate. A page can show three code samples in a browser while a Markdown fence scanner finds only two. A successful site build establishes that Hugo rendered the page; it does not establish that a reader can run the examples.
This guide walks through a small Hugo site, a check for code hidden in shortcodes, and a practical way to interpret a scan. The sample host used in the configuration is fictional.
Where Hugo holds documentation code
Hugo highlights fenced code blocks by default. A fence can name a language and add options in braces, such as line numbering or highlighted lines. Those options affect presentation; they do not make the code itself valid. A copied highlight marker, a stale line number, or an option left over after editing can make a sample misleading even when the program still runs.
The built-in highlight shortcode is another way to render code. Themes can add their own forms. Docsy has tabpane and tab shortcodes whose tab content can be rendered as code without a Markdown fence. Other themes use tabs whose bodies contain ordinary fenced blocks. These forms may look similar on the published page but expose different source text to a scanner.
Front matter also varies. Hugo accepts YAML, TOML, and JSON front matter. New content can start as a draft, depending on the archetype. A repository can contain the real documentation under content/docs, an old blog under content/blog, and a theme's demonstration site under themes/. Decide which of those readers rely on before treating a scan as representative.
Examples drift for familiar reasons: a package is renamed, a command-line flag changes, or the version installed in CI differs from the version readers use. Tabs can drift independently when only the first variant receives attention. Code inside a shortcode may never reach a fence-based check. Drafts and older sections can preserve broken instructions long after the main documentation is updated.
Classify before running
Use the intended role of a block to choose a check:
| Kind of block | Treatment |
|---|---|
| Runnable example | Execute in page order with documented prerequisites and a known version. |
| Fragment | Mark omitted context and review the surrounding explanation. |
| Credential-gated example | Check the shape and instructions separately; do not insert real secrets into a general docs run. |
| Illustrative configuration | Parse with an appropriate tool and, where useful, validate against the actual application. |
| Output | Treat as an assertion to check with a suitable tool or review; do not assume a nearby fence is compared. |
A complete runnable example can still depend on a file or service that the page has not established. Record those dependencies instead of silently supplying them. For a broader approach to site generators, see testing static-site documentation.
Walk through a Hugo example
Start with the Hugo CLI. This creates a site and a documentation page; the exact generated date depends on when the command runs.
hugo new site example-docs
cd example-docs
hugo new content docs/getting-started.md
cat content/docs/getting-started.md
The generated page in this example has TOML front matter and starts as a draft. Hugo normally excludes drafts from a build unless drafts are requested, but a file scanner can still read the source.
+++
date = '2026-11-12T11:17:08-08:00'
draft = true
title = 'Getting Started'
+++
The following illustrative site configuration sets a title, locale, and highlight options. It configures presentation; it does not test the examples. The host is fictional.
baseURL = 'https://docs.acme-docs-demo.test/'
locale = 'en-us'
title = 'Acme Docs'
[markup.highlight]
lineNos = false
noClasses = true
style = 'monokai'
Now consider the page before the coverage fix. The first two examples are fenced. The Python fence has Hugo brace options, while the final Python sample is inside the highlight shortcode. It renders as code in Hugo, but it is not a Markdown fence.
+++
title = 'Getting started'
draft = false
+++
Check that pip is available:
```bash
python3 -m pip --version
```
Build a request body:
```python {linenos=inline,hl_lines=[3]}
import json
payload = {"name": "ada", "plan": "team"}
print(json.dumps(payload, sort_keys=True))
```
{{< highlight python >}}
import json
print(json.dumps({"legacy": True}))
{{< /highlight >}}
A build can show all three samples while a fence scanner plans only the first two. The following small inventory script looks for highlight shortcodes and Docsy-style code tabs outside fences. It also points out tab groups that need review. It is a focused aid for this example, not a full Hugo parser; inspect unfamiliar nesting and theme syntax separately.
"""Find Hugo shortcodes that hide code from a Markdown fence scanner."""
import pathlib
import re
import sys
OPEN = re.compile(r"\{\{[<%]\s*(highlight|tabpane|tabs|tab)\b([^>%]*)[>%]\}\}")
FENCE = re.compile(r"^\s*(`{3,}|~{3,})")
root = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else "content")
hidden = 0
for page in sorted(root.rglob("*.md")):
in_fence = False
for n, line in enumerate(page.read_text(encoding="utf-8").splitlines(), 1):
if FENCE.match(line):
in_fence = not in_fence
continue
m = None if in_fence else OPEN.search(line)
if not m:
continue
name, args = m.group(1), m.group(2).strip()
if name == "highlight" or (name == "tab" and "lang=" in args):
hidden += 1
print(f"{page}:{n}: code inside {name} shortcode ({args}) is not a fence")
elif name in ("tabs", "tabpane"):
print(f"{page}:{n}: {name} group; fenced tabs inside are tested one by one")
print(f"{hidden} shortcode code block(s) need a fence or another check")
sys.exit(1 if hidden else 0)
Run the inventory against the content directory. A nonzero result asks the maintainer to resolve or explicitly cover hidden code.
python3 scripts/find_shortcode_code.py content
On the page above, it identifies the highlight shortcode and exits with status 1.
content/docs/getting-started.md:21: code inside highlight shortcode (python) is not a fence
1 shortcode code block(s) need a fence or another check
One fix is to replace that shortcode with an ordinary Python fence, provided the theme can present the sample as intended. The code below is the replacement for the hidden sample.
import json
print(json.dumps({"legacy": True}))
Build the site and inspect the rendered code-block count. In this minimal example, Hugo renders three blocks. The scanner planned two before the replacement and three afterward. A count is a useful coverage signal, though equal counts alone do not prove that the right code ran.
hugo --quiet
grep -c "<pre" public/docs/getting-started/index.html
The following command scopes the scan to the documentation section. With this directory layout, the folder rule selects content/docs. Without --execute, this command extracts and plans; add that flag when you intend to run the planned blocks.
docsalive scan . --docs-dir content --include "content/docs/*"
This illustrative GitHub Actions YAML runs the shortcode inventory and builds the site. It is a starting point for the example repository: ensure that the Hugo release and actions fit your own environment and review changes to them. Add a separate execution check if you want runnable fences tested in CI.
name: docs-examples
on:
pull_request:
paths:
- "content/**"
- "hugo.toml"
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.13"
- name: Find code hidden in shortcodes
run: python3 scripts/find_shortcode_code.py content
- name: Build the site with Hugo
run: |
curl -sSL -o hugo.tgz https://github.com/gohugoio/hugo/releases/download/v0.169.0/hugo_extended_0.169.0_linux-amd64.tar.gz
tar xzf hugo.tgz hugo
./hugo --minify
What the engine sees
DocsAlive does not detect Hugo as a framework in engine 0.6.3. It handles the repository as plain Markdown and scans .md, .mdx, and .markdown pages, not Hugo content stored in other formats such as HTML.
Without --docs-dir, it selects a top-level docs/ directory if one exists; otherwise it scans the repository. With --docs-dir X, it selects X/docs if that exists, otherwise X. The --include filter matches paths relative to the repository root. Check the selected pages as well as the number of extracted blocks: selecting a plausible folder is not proof that it contains the published documentation.
At any depth, the scanner skips directories named node_modules, .git, dist, build, .next, site, __pycache__, vendor, _snippets, snippets, changelog, blog, i18n, and versioned_docs. Consequently, content/blog is skipped. If a root scan reaches themes/, Markdown in a theme's example site can be scanned. Drafts are scanned because the engine reads source files rather than Hugo's build output.
Only YAML front matter delimited by --- on the first line is stripped. TOML and JSON front matter are treated as ordinary text; their delimiters do not prevent a later fence from being found. For a fence, the first info-string word supplies the language, so Hugo brace options after it do not change the selected language.
| Block form → what the engine does in 0.6.3 | Practical consequence |
|---|---|
| Supported Python or shell fence with Hugo brace options | Extracts the fence using the first word as its language and plans the supported check. |
| Highlight shortcode containing code | Does not extract the shortcode body as a fenced block. |
| Docsy code tab whose body is not fenced | Does not see that code as a fence. |
| Other theme tabs containing fences | Extracts the fences but does not group those tabs; each variant is planned separately. |
| Unmapped fence label | Reports a pass without running or parsing it. This is a known limitation; a pass is not evidence of a check. |
| Recognized non-executable form or output block | Skips it with a reason. |
Python pycon or python-repl session |
Executes the session and compares its printed output. This is the engine's only printed-output comparison. |
A block introduced as output can be skipped rather than checked. Console lines beginning with a prompt are run, while other console lines are treated as output and not compared. Use a dedicated assertion or a suitable external check for important results.
Triage the findings
A raw failure count is not the same as a count of documentation defects. Inspect the category and evidence, then reproduce the reader's conditions.
| Finding | Likely next action |
|---|---|
| Invalid syntax or an API that changed | Confirm the intended version and correct the published example. |
| Missing install step | Decide whether the page must state the prerequisite; the engine reports a hint. |
| Missing tool | Check whether the documented setup promises that tool and whether the runner has it. |
| Depends on context | Find the earlier definition or fixture; establish whether a reader actually receives it. |
| Needs credentials | Record the gap and use a separate authorized check where appropriate. |
| Timeout or runtime error | Investigate the evidence; these need review rather than automatic blame. |
| Hidden shortcode code or unchecked label | Add another check or change the source form, then verify coverage again. |
For details on categories and reports, see findings. The CLI reference describes scan options and report output.
Make the check repeatable
Choose the package version, fixture, and environment deliberately. A check against a repository checkout answers a different question from one against a published package. Keep documented setup visible, and avoid making a page pass solely because CI installed something the reader was never told to install.
Review each tab as a reader path. If two variants are alternatives, each should be independently understandable and should not depend on a prior tab's state. Since the Hugo theme forms described here are not grouped by the engine, a run may expose missing tools in variants that a particular reader would not select. That is useful information, but it needs interpretation.
Use the following checklist in a pull request or release review:
- Identify the published content directory and the intended version.
- Check scan scope, including drafts, skipped folders, and theme example sites.
- Inventory highlight shortcodes and code-bearing theme tabs.
- Check each fenced tab variant and its prerequisites.
- Run complete examples in page order in a clean environment.
- Review fragments, credentials, fixtures, and missing tools separately.
- Verify important displayed results with an appropriate assertion.
- Build the Hugo site and inspect the rendered examples.
- Review unchecked labels, skipped blocks, and finding categories.
- Repeat the relevant checks when packages, flags, or theme behavior change.
Where DocsAlive fits
DocsAlive can extract and plan examples from a local checkout or Git URL, execute supported blocks in isolated page containers when requested, and report findings with their locations and categories. Page order matters: supported Python blocks later on a page can use state established earlier on that page. A new page starts in a fresh container, so do not rely on one page's state leaking into another.
Use it alongside the Hugo build and a check for shortcode content. A build checks rendering, the shortcode inventory helps expose code the fence extractor misses, and execution checks help find examples that no longer work. None of these alone establishes that the prose is clear or that every displayed variant reflects a real reader journey. See how docs testing works and the framework coverage reference.
For a Git-synced knowledge base with different source forms, see testing GitBook documentation examples. For database snippets, see testing SQL examples.
Zola, another static site generator, renders page content as a Tera template before Markdown; see testing Zola documentation examples for what that means for code examples.
The sources we checked
These sources were read on November 12, 2026. Engine behavior was checked against engine 0.6.3 on the same day.
| Source | What it covers |
|---|---|
| Hugo syntax highlighting | Fences and highlighting options. |
| Hugo highlight shortcode | The alternative shortcode form. |
| Hugo front matter | YAML, TOML, JSON, and draft metadata. |
| Hugo new content | Creating content from archetypes. |
| Docsy shortcodes | Theme tab and code presentation. |
| Hugo v0.169.0 release | The release used in the example. |
| Framework coverage | Supported checks and framework behavior. |
FAQ
Does a Hugo build test the examples?
A build tests whether Hugo can process the source and produce the site. Run or otherwise check the examples separately, and inspect the rendered page for presentation problems.
Are Hugo brace options understood by the scanner?
The engine takes the first word of the fence info string as the language and ignores the subsequent brace options for language selection. Check presentation options in the rendered site.
Does the engine scan draft pages?
Yes. It reads source files, including drafts, rather than relying on Hugo's published build. Limit scope with the documented selection options when that matches your testing goal.
What happens to code inside the highlight shortcode?
It is not a Markdown fence, so the engine does not extract it. Convert it to a suitable fence or cover it with a separate check, and verify the rendered result.
Are all Hugo tab variants tested?
Fences in unrecognized theme tab forms are planned separately, while code that exists only as the body of a Docsy code tab is invisible to the fence extractor. Inspect the actual source form.
Does a passing scan prove every sample works?
No. Review the scope, skips, unsupported forms, and unchecked labels. The site build and human review still matter, as do checks for any behavior outside the engine's coverage.




