Custom directives and dynamic content
======================================
Guidedog publishes the same document tree to an interactive HTML website and a typeset PDF book.
Web readers benefit from interactive calculators, search filters, and embedded widgets. Book readers
benefit from balanced columns, callout cards, and vector typography.
This tutorial builds a project that demonstrates both without duplicating prose. We declare a custom
semantic directive in ``conf.toml``, add an interactive calculator for web readers, and design a
print-quality callout block for the PDF book.
.. graphviz::
:class: graphviz-adaptive
:caption: Format-gated evaluation and custom directives across HTML and PDF pipelines.
:alt: One source document evaluates object types for both outputs, sending raw HTML to the web and raw Typst to the PDF book.
digraph dynamic_directives {
graph [rankdir=TB, bgcolor="transparent", pad="0.22", nodesep="0.32", ranksep="0.38"];
node [shape=box, style="rounded,filled", fillcolor="#edf5f2", color="#216553",
fontname="Helvetica", fontcolor="#16382f", fontsize=12, margin="0.18,0.1"];
edge [color="#216553", fontname="Helvetica", fontcolor="#16382f", fontsize=10, arrowsize=0.7];
source [class="gd-input", shape=note, fillcolor="#fbfaf3",
label=<Source document
RST with directives & format guards>];
conf [class="gd-input", shape=note, fillcolor="#fbfaf3",
label=<conf.toml
[[object_types]] declarations>];
parser [label=<Guidedoc Parser
Resolve AST & cross-references>];
obj_node [label=<Custom object node
Index target & signature>];
only_html [class="gd-plugin", style="rounded,dashed,filled", fillcolor="#fff9e6", color="#ca8a04", fontcolor="#854d0e",
label=<.. only:: html
Active for web builder>];
only_typst [class="gd-plugin", style="rounded,dashed,filled", fillcolor="#fff9e6", color="#ca8a04", fontcolor="#854d0e",
label=<.. only:: pdf
Active for book builder>];
html_out [class="gd-output", fillcolor="#eef4fa",
label=<HTML Website
Interactive widget & DOM script>];
typst_out [class="gd-output", fillcolor="#eef4fa",
label=<Typst PDF Book
Typeset vector block & index>];
source -> parser;
conf -> parser;
parser -> obj_node;
parser -> only_html;
parser -> only_typst;
obj_node -> html_out [label="<dl class=\"metric\">"];
obj_node -> typst_out [label="Typst description"];
only_html -> html_out [label="raw HTML markup"];
only_typst -> typst_out [label="native Typst function"];
}
1. Create the project
---------------------
Start in a clean directory and run:
.. code-block:: sh
guidedog quickstart telemetry -q -p "Cluster Telemetry" -a "Operations Team" -v 1.0
Move into the new directory:
.. code-block:: sh
cd telemetry
2. Declare custom domain directives in conf.toml
------------------------------------------------
A project often needs structured entities that standard domains (such as Python or C++) do not cover.
Rather than requiring a Python runtime or custom extension compiler, Guidedog lets us declare custom
directives and roles in ``conf.toml``.
Open ``conf.toml`` and append the declaration for a ``metric`` directive:
.. code-block:: toml
[[object_types]]
directive = "metric"
role = "metric"
index = "pair: %s; cluster telemetry"
name = "first-word"
display = "Metric: %s"
This single declaration establishes a complete syntax contract:
* ``.. metric:: p99_latency (milliseconds)`` describes the metric.
* ``:metric:`p99_latency``` links to the definition from any document.
* The index table automatically generates a pair index entry (``p99_latency; cluster telemetry``).
* In HTML, Guidedog generates a semantic definition list with CSS anchor hooks.
* In PDF, Guidedog typesets a description and an index entry linking to its page.
3. Author the document with format guards
-----------------------------------------
Replace the contents of ``index.rst`` with the following document:
.. code-block:: rst
Cluster Telemetry
=================
We monitor service level indicators across all ingress gateways.
Refer to :metric:`p99_latency` for service level objectives.
.. metric:: p99_latency (milliseconds)
The 99th percentile response duration measured over a 60-second sliding window.
Interactive estimator
---------------------
.. only:: html
.. raw:: html