Skip to navigation

Custom detection, written as tests

Each example on this page shows one documented procedure as prose, detected tests, inline tests, and a standalone spec. For what each tab holds, see Navigation and interaction.

Here, the detected variants run with custom fileTypes, and each example’s config sits above its tabs. The prose, inline, and standalone variants are the same as on any other page. For how selectors and regex definitions work, see Selectors and Custom input formats.

Custom definitions match what one format writes, so most examples show only the formats their definitions apply to.

Extend Markdown with your own conventions

This file type uses extends, name, and extensions to build on the Markdown and MDX defaults. Its markup uses the link, strong, text, element, and emphasis selectors with precededBy, excludes, captures, and regex, and element in its string form. Its inlineStatements read statements from comments that start with dd:. The steps are goTo, find, click, type, and wait.

doc-detective.json (fileTypes)
{
"fileTypes": [
{
"name": "markdown-ui",
"extends": "markdown",
"extensions": ["md", "mdx"],
"inlineStatements": {
"in": [{ "comment": {}, "regex": "^dd:\\s*([\\s\\S]*)$" }]
},
"markup": [
{
"name": "goToUrl",
"link": { "url": "^https?://", "precededBy": "\\b[Gg]o to(?: the)?\\s+$", "excludes": "^\\s*$" },
"captures": ["url", "text"],
"actions": ["goTo", { "find": "$2" }]
},
{
"name": "clickOnscreenText",
"strong": { "precededBy": "\\b(?:[Cc]lick|[Ss]elect)\\s+$" },
"actions": ["click"]
},
{
"name": "findOnscreenText",
"strong": { "excludes": "^(?:Note|Tip):?$" },
"actions": ["find"]
},
{
"name": "typeText",
"text": { "excludes": "^\\s*For example\\b" },
"regex": "\\b(?:[Pp]ress|[Ee]nter|[Tt]ype)\\b\\s+\"([^\"]+)\"",
"actions": ["type"]
},
{
"name": "typeKeyboardInput",
"element": { "tag": ["kbd"], "precededBy": "\\b[Ee]nter\\s+$", "excludes": "^(?:Enter|Tab|Esc|Ctrl|Shift|Alt)\\b" },
"captures": ["content"],
"actions": ["type"]
},
{
"name": "waitForUpdate",
"emphasis": { "precededBy": "\\b[Ww]ait\\s+$", "excludes": "^0 ms$" },
"regex": "^(\\d+) ms$",
"actions": ["wait"]
},
{
"name": "findSampleOutput",
"element": "samp",
"actions": ["find"]
}
]
},
"asciidoc",
"html",
"dita",
"rst"
]
}
prose.md
# Echo text back
**Note:** The field echoes each keystroke below it.
**Tip:** For example, type "Hi" to see a short echo.
1. Go to the [Type Echo Test Page](http://localhost:8092/type-echo.html).
2. Click **Type here:**.
3. Enter <kbd>Hello, Doc Detective</kbd>.
4. Wait _500 ms_ for the echo.
5. Check that the page shows <samp>Hello, Doc Detective</samp> below the field.

What detection finds

ProseDefinitionDetected steps
Go to the [Type Echo Test Page](…)goToUrl, replacedgoTo the URL and find the link text, then the default checkLink
**Note:** and **Tip:**findOnscreenText, replacedNone. excludes skips the labels
For example, type "Hi"typeText, replacedNone. text.excludes skips sentences that start with “For example”
Click **Type here:**clickOnscreenText and findOnscreenText, both replacedclick, then find
Enter <kbd>…</kbd>typeKeyboardInputtype the element’s content
Wait _500 ms_waitForUpdatewait 500
<samp>Hello, Doc Detective</samp>findSampleOutputfind the sample output
  • With extends, a definition whose name matches a built-in one replaces it, and the rest of the built-in definitions still run. That’s how goToUrl changes here, and why the link still gets the default checkLink.
  • The replaced clickOnscreenText clicks only after Click or Select. The built-in one also clicks after verbs such as Check and Choose.
  • Each excludes keeps a look-alike from becoming a step. Here, that’s a link with no text, a key name such as <kbd>Tab</kbd>, and a zero wait.
  • "element": "samp" is short for { "tag": ["samp"] }. <samp> marks sample output, so finding it checks what the page shows.
  • captures picks the values for $1, $2, and so on. An action name, such as "goTo", takes $1. An object, such as { "find": "$2" }, is a step template.
  • The dd: prefix is the custom part of the statements. inlineStatements from extends still read plain test comments, so the inline variants need no custom config.
  • In Markdown and MDX, <kbd> and <samp> are HTML tags, so the element selector finds them in both formats.

Run a script split across code blocks

Each file type extends a built-in format and adds one codeBlock definition. It uses language, excludes, and batchMatches to join a tutorial’s code blocks into one runCode step.

doc-detective.json (fileTypes, one entry)
{
"extends": "markdown",
"markup": [
{
"name": "runCode",
"codeBlock": { "language": ["javascript", "js"], "excludes": "^// Don't run" },
"batchMatches": true,
"actions": [{ "runCode": { "language": "javascript", "code": "$1" } }]
}
]
}

The config repeats this entry with extends set to asciidoc, html, rst, and dita, because each entry extends one format.

prose.md
# Print a greeting with Node.js
Define the name to greet:
```javascript
const name = "Doc Detective";
```
Don't declare `name` a second time. A script that does throws a `SyntaxError`:
```javascript
// Don't run: this redeclares name.
const name = "someone else";
```
Print the greeting:
```javascript
console.log(`Hello, ${name}!`);
```
The script prints `Hello, Doc Detective!`.

What detection finds

In every format, detection resolves the three code blocks to one runCode step:

  • batchMatches joins the matching blocks, in document order and separated by newlines, into one $1. The script runs as one program, so the second block can use name from the first.
  • excludes skips the block that starts with // Don't run. Run with the other blocks, it would declare name a second time and fail.
  • The definition’s name, runCode, replaces the built-in runCode definition. The built-in one runs each block as its own step and marks it unsafe.
  • The inline and standalone variants also set stdio, to check what the script prints. A detected step has only what the definition’s template sets.

Mark up controls with attributes

These file types extend HTML and DITA. They use the link, image, element, comment, and text selectors with url, attributes, src, precededBy, excludes, captures, and regex. The HTML type also reads statements from an element’s attribute, with an inlineStatements.in container and value. The steps are checkLink, goTo, click, type, wait, and find.

doc-detective.json (fileTypes, HTML entry)
{
"extends": "html",
"inlineStatements": {
"in": [{ "element": { "tag": ["div"], "attributes": { "data-test": true } }, "value": "attributes.data-test" }]
},
"markup": [
{
"name": "goToUrl",
"link": { "url": "^https?://", "precededBy": "\\b[Gg]o to\\s+$" },
"captures": ["url"],
"actions": ["goTo"]
},
{
"name": "checkHyperlink",
"link": { "url": "^https?://", "attributes": { "data-check": true }, "excludes": "^\\s*$" },
"captures": ["url"],
"actions": ["checkLink"]
},
{
"name": "checkHostedImage",
"image": { "src": "^https?://", "attributes": { "class": "(^|\\s)hosted(\\s|$)" }, "precededBy": "(?:^|>)\\s*$", "excludes": "^\\s*$" },
"captures": ["src"],
"actions": ["checkLink"]
},
{
"name": "clickUiLabel",
"element": { "tag": ["span", "ph"], "attributes": { "class": "(^|\\s)ui(\\s|$)" }, "precededBy": "\\b[Cc]lick\\s+$" },
"actions": ["click"]
},
{
"name": "waitComment",
"comment": { "excludes": "\\bTODO\\b" },
"regex": "^\\s*wait (\\d+)\\s*$",
"actions": ["wait"]
},
{
"name": "findEcho",
"text": {},
"regex": "\\bthe page shows (.+?) below the field",
"actions": [{ "find": { "elementText": "$1", "timeout": 5000 } }]
}
]
}

The DITA entry has the same checkHostedImage, clickUiLabel, waitComment, and findEcho definitions with extends set to dita. It has no inlineStatements, so DITA keeps its built-in <data> statements. DITA has no link nodes, so its links keep the built-in <xref> definitions.

prose.html
<!DOCTYPE html>
<html lang="en">
<head><title>Echo text back</title></head>
<body>
<h1>Echo text back</h1>
<img src="http://localhost:8092/find-image-target.svg" alt="A target icon" class="hosted">
<ol>
<li>Go to <a href="http://localhost:8092/type-echo.html" data-check>the type echo page</a>.</li>
<li>Click <span class="ui">Type here:</span>.</li>
<li>Type "Hello, Doc Detective".</li>
<li>Check that the page shows Hello, Doc Detective below the field.</li>
</ol>
</body>
</html>

What detection finds

ContentDefinitionDetected step
An image with the hosted classcheckHostedImagecheckLink the image’s source
Go to <a data-check>goToUrl and checkHyperlink, replacedgoTo, then checkLink
Go to <xref>Default goToUrl and checkHyperlinkgoTo, then checkLink
Click and a ui labelclickUiLabelclick the label’s text
Type "…"Default typeTexttype
<!-- wait 500 -->waitCommentwait 500
the page shows … below the fieldfindEchofind with elementText and timeout
  • One attributes pattern matches both formats. DITA’s outputclass sets class, and an <image>’s href is its src.
  • The replaced checkHyperlink checks only links an author marks with data-check, and skips links with no text. "data-check": true only requires the attribute.
  • The replaced goToUrl sits before checkHyperlink, so the goTo still comes before the checkLink for the same link. Your definitions run before the built-in ones, in the order you list them.
  • checkHostedImage skips decorative images, whose alt text is empty, and images inside a sentence. Its precededBy matches only when nothing but a tag comes before the image in its block.
  • waitComment skips comments that say TODO, so a note about a wait to add later doesn’t become a step.
  • The wait 500 comment isn’t visible to readers, so the detected variants carry it where the prose has nothing. It’s the detected counterpart of a step statement.
  • In HTML, the hidden <div data-test> elements hold the test and test end statements, for sites whose build strips comments.
  • These formats leave out Markdown, MDX, AsciiDoc, and reStructuredText. Their links and images don’t carry a class attribute in the same way, and AsciiDoc and reStructuredText produce no element nodes.

Define a plain-text format

This file type has no extends. Its name and extensions define a format for .txt files. Its inlineStatements use the regex statement keys testStart, testEnd, ignoreStart, ignoreEnd, and step, each with one pattern as a string. Its includeStatements pattern pulls in a shared file, and its markup uses regex definitions. The steps are checkLink and httpRequest.

doc-detective.json (fileTypes)
{
"fileTypes": [
{
"name": "plain-text",
"extensions": ["txt"],
"inlineStatements": {
"testStart": "(?:^|\\n)[ \\t]*TEST (\\{.*\\})",
"testEnd": "(?:^|\\n)[ \\t]*END TEST",
"ignoreStart": "(?:^|\\n)[ \\t]*IGNORE START",
"ignoreEnd": "(?:^|\\n)[ \\t]*IGNORE END",
"step": "(?:^|\\n)[ \\t]*STEP (\\{.*\\})"
},
"includeStatements": "^[ \\t]*INCLUDE (\\S+)[ \\t]*$",
"markup": [
{
"name": "checkUrl",
"regex": ["\\b[Cc]heck that (https?://\\S+) responds\\b"],
"actions": ["checkLink"]
},
{
"name": "sendRequest",
"regex": ["\\bSend an? (GET|POST|PUT|PATCH|DELETE) request to (https?://\\S+) with the body (\\{.*\\})\\.(?=\\s|$)"],
"actions": [{ "httpRequest": { "method": "$1", "url": "$2", "request": { "body": "$3" } } }]
}
]
},
"markdown",
"asciidoc",
"html",
"dita",
"rst"
]
}
prose.txt
Create a user with the echo API
INCLUDE prerequisites.txt
1. Send a POST request to http://localhost:8092/api/users with the body {"name":"Ada"}.
The API returns the user it created.
To remove a user later, send a request like this one. Don't run it against
data you want to keep.
Send a DELETE request to http://localhost:8092/api/users/1 with the body {"confirm":true}.

What detection finds

  • No parser handles .txt, so this format can’t use selectors. Regex definitions match the file’s raw text.
  • Regex patterns run without flags, so ^ matches only the start of the file. (?:^|\n) matches the start of any line.
  • checkUrl uses the checkLink action name, which takes $1. sendRequest is a step template with three groups. A request body that’s a JSON object becomes an object, not a string.
  • The inline and standalone variants also check the response body. A detected step has only what the definition’s template sets.
  • INCLUDE prerequisites.txt pulls in a shared file from the same folder, which holds one line: Before you start, check that http://localhost:8092/api/users responds. Doc Detective includes it before it detects steps, so checkUrl finds the checkLink there. Includes need resolveIncludes, which is on by default. ^ and $ in includeStatements match at line boundaries.
  • IGNORE START and IGNORE END wrap the DELETE example, so detection skips a request the procedure only describes.
  • The inline variant uses the format’s own TEST, STEP, and END TEST lines, so it needs this config too. The other examples’ inline variants use the built-in statement syntax.

Keep statements in markup your site keeps

Some publishing pipelines strip HTML comments, so statements in comments never reach the published source. This Markdown file type reads statements from other markup instead. Its regex statement keys, testStart, testEnd, ignoreStart, ignoreEnd, and step, each take a list of patterns. Its inlineStatements.in list has one container of each selector kind: comment, codeBlock, link, image, strong, emphasis, text, and element. Its markup runs code blocks with runShell, with codeBlock in its string form and with metaExcludes. The other steps are goTo, find, click, type, wait, and checkLink.

doc-detective.json (fileTypes)
{
"fileTypes": [
{
"name": "markdown-statements",
"extends": "markdown",
"inlineStatements": {
"testStart": ["<!--\\s*dd-test\\s+(\\{[\\s\\S]*?\\})\\s*-->", "<!--\\s*doc-detective-test\\s+(\\{[\\s\\S]*?\\})\\s*-->"],
"testEnd": ["<!--\\s*dd-end\\s*-->", "<!--\\s*doc-detective-end\\s*-->"],
"ignoreStart": ["<!--\\s*dd-skip\\s*-->", "<!--\\s*doc-detective-skip\\s*-->"],
"ignoreEnd": ["<!--\\s*dd-resume\\s*-->", "<!--\\s*doc-detective-resume\\s*-->"],
"step": ["<!--\\s*dd-step\\s+(\\{[\\s\\S]*?\\})\\s*-->", "<!--\\s*doc-detective-step\\s+(\\{[\\s\\S]*?\\})\\s*-->"],
"in": [
"comment",
{ "comment": { "excludes": "^\\s*draft\\b" }, "regex": ["^dd:\\s*([\\s\\S]*)$", "^doc-detective:\\s*([\\s\\S]*)$"] },
{ "codeBlock": "dd" },
{ "codeBlock": { "language": ["doc-detective"], "metaExcludes": "\\bdraft\\b", "excludes": "^\\s*$" } },
{ "link": { "url": "^#dd$", "attributes": { "class": "^dd$" }, "precededBy": "^\\s*$", "excludes": "\\S" }, "value": "title" },
{ "image": { "src": "^#dd$", "attributes": { "class": "^dd$" }, "precededBy": "^\\s*$", "excludes": "^\\s*$" } },
{ "strong": { "precededBy": "\\bTest:\\s*$", "excludes": "^\\s*$" } },
{ "emphasis": { "precededBy": "\\bTest:\\s*$", "excludes": "^\\s*$" } },
{ "text": { "excludes": "^(?!\\s*Test step:)" }, "regex": "^\\s*Test step:\\s*(step\\b[\\s\\S]*)$" },
{ "element": "dd-statement" },
{ "element": { "tag": ["span"], "precededBy": "^\\s*$", "excludes": "\\S" }, "value": "attributes.data-dd" }
]
},
"markup": [
{ "name": "runCode", "codeBlock": "bash", "actions": ["runShell"] },
{
"name": "runShellUnlessNoRun",
"codeBlock": { "language": ["sh", "shell"], "metaExcludes": "\\bno-run\\b" },
"actions": ["runShell"]
},
{ "name": "findOnscreenText", "strong": { "excludes": "^(?:step|test)\\b" }, "actions": ["find"] }
]
},
"asciidoc",
"html",
"dita",
"rst"
]
}

This example uses every container at once so you can compare them. A real project picks the one or two its pipeline keeps.

prose.md
# Echo text back
Check that the page server is up:
```bash
curl -sf http://localhost:8092/type-echo.html > /dev/null
```
Open the type echo page at `http://localhost:8092/type-echo.html`.
Click the field labeled Type here:, then type Hello, Doc Detective.
The field echoes each keystroke, so the page shows Hello, Doc Detective below the field.
Older versions of the page echoed only after you pressed Enter.
If the page doesn't load, restart the page server from the repository root:
```sh no-run
node test/server/start.js
```

What detection finds

Markup in detected.mdRead byStep
A bash code blockrunCode markup, replacedrunShell the block
A dd code block{ "codeBlock": "dd" }goTo
[](#dd '…'){.dd}, a link with no textlink container, value: "title"find
![…](#dd){.dd}, an imageimage container, the alt textclick
<dd-statement>…</dd-statement>{ "element": "dd-statement" }type
<span data-dd='…'></span>element container, value: "attributes.data-dd"wait
Test step: step {…}text container with regexfind
Test: **step {…}**strong containerfind with selector and elementText
Test: _step {…}_emphasis containercheckLink
<!-- dd: step {…} -->comment container with regexfind
A doc-detective code blockcodeBlock container with languagefind
A doc-detective draft code blockNone. metaExcludes skips itNone
<!-- dd-step {…} --> and <!-- doc-detective-step {…} -->step patternsfind
A dd code block between dd-skip and doc-detective-resumeNone. The ignore patterns skip itNone
An sh no-run code blockNone. metaExcludes skips itNone
  • Each regex statement key lists two patterns, one for the older dd- keywords and one for the newer doc-detective- keywords. Files that use either work while a project moves between them. An ignored section can start with one keyword and end with the other.
  • A container’s value names the field that holds the statement. Without value, the statement is the node’s main text: a code block’s content, an image’s alt text, or an element’s content.
  • A container’s options narrow it like a selector’s do. precededBy: "^\\s*$" takes only a node that starts its block. excludes: "\\S" takes only a link or <span> with no visible text. "class": "^dd$" takes only markup with the dd class, which the site can hide.
  • The text container’s excludes skips every prose run that doesn’t start with Test step:, and its regex keeps the statement after the label.
  • The replaced findOnscreenText skips bold text that starts with step or test, so the bold statement doesn’t also become a find of its own text.
  • "comment" as a string reads every comment. The built-in Markdown file type has it too. The inline variant’s plain test comments therefore work with this config and with the default one.
  • The bash definition’s name is runCode, so it replaces the built-in runCode definition. A bash block then runs as a runShell step and isn’t marked unsafe.
  • This example is Markdown only. MDX reads {.dd} as a JavaScript expression, so it needs JSX attributes instead, and the other formats write links, images, and elements their own ways.

Selector kind permutations

Each example detects steps with one selector kind and no selector options. Its file types don’t use extends, so no built-in definition adds steps. step statements open the page where the procedure needs it. Each definition below is the one entry in markup, and the config repeats it in one file type per format. An example leaves out the formats that don’t produce its kind.

comment

Varies: markup.comment · Value: {} · Effect: every comment is a candidate, and regex picks the ones that start with expect:.

{
"name": "findExpected",
"comment": {},
"regex": "^\\s*expect:\\s*(.+?)\\s*$",
"actions": [
"find"
]
}
prose.md
# Check the page heading
Open the type echo page.
The heading names the page.

The expect: comment is in the detected variants only. A bare comment: {} would also match the test and step comments, so a comment definition needs regex.

codeBlock

Varies: markup.codeBlock · Value: {} · Effect: every code block runs, whatever its language.

{
"name": "runBlock",
"codeBlock": {},
"actions": [
"runShell"
]
}
prose.md
# Check that the page server is up
Request the type echo page. The command fails if the server doesn't answer:
```bash
curl -sf -o /dev/null http://localhost:8092/type-echo.html
```

Varies: markup.link · Value: {} · Effect: each link’s text, its main text, becomes $1.

{
"name": "findLinkText",
"link": {},
"actions": [
"find"
]
}
prose.md
# Check the page heading
Open the type echo page.
The page's heading is [Type Echo Test Page](http://localhost:8092/type-echo.html).

DITA has no link nodes, so this example leaves it out. Select <xref> as an element instead.

image

Varies: markup.image · Value: {} · Effect: every image matches, and captures uses its source.

{
"name": "checkImage",
"image": {},
"captures": [
"src"
],
"actions": [
"checkLink"
]
}
prose.md
# Check a hosted icon
The page uses this icon:
![Target icon](http://localhost:8092/find-image-target.svg)

Without captures, $1 is the image’s alt text.

strong

Varies: markup.strong · Value: {} · Effect: every bold phrase becomes a find.

{
"name": "findBold",
"strong": {},
"actions": [
"find"
]
}
prose.md
# Check the field label
Open the type echo page.
The field is labeled **Type here:**.

emphasis

Varies: markup.emphasis · Value: {} · Effect: every italic phrase becomes a find.

{
"name": "findItalic",
"emphasis": {},
"actions": [
"find"
]
}
prose.md
# Check the page heading
Open the type echo page.
The heading reads _Type Echo Test Page_.

text

Varies: markup.text · Value: {} · Effect: each run of prose is a candidate, and regex finds the heading name inside it.

{
"name": "findHeading",
"text": {},
"regex": "\\bheading reads ([^.]+)\\.",
"actions": [
"find"
]
}
prose.md
# Check the page heading
Open the type echo page.
The heading reads Type Echo Test Page.

A bare text: {} matches every run of prose, so a text definition needs regex.

element

Varies: markup.element · Value: "samp" · Effect: each <samp> element becomes a find. A string names one tag.

{
"name": "findSample",
"element": "samp",
"actions": [
"find"
]
}
prose.md
# Check the field label
Open the type echo page.
The page shows <samp>Type here:</samp> next to the field.

Only Markdown, MDX, and HTML produce <samp>. AsciiDoc and reStructuredText produce no element nodes. DITA’s equivalent tag is in the tag example below.

Selector option permutations

Each example adds one option to a selector, and leaves out the content the option skips or keeps. The file types don’t use extends, as in the kind examples.

precededBy

Varies: markup.strong.precededBy · Value: \\b[Cc]lick\\s+$ · Effect: only a bold phrase right after Click becomes a click.

{
"name": "clickBold",
"strong": {
"precededBy": "\\b[Cc]lick\\s+$"
},
"actions": [
"click"
]
}
prose.md
# Type into the field
Open the type echo page.
Click **Type here:**.
Type Hello, Doc Detective.
The page shows **Hello, Doc Detective** below the field.

The second bold phrase isn’t after Click, so detection skips it. A step statement checks it instead.

attributes

Varies: markup.image.attributes · Value: { "class": "(^|\\s)check(\\s|$)" } · Effect: only the image with the check class gets a checkLink.

{
"name": "checkMarkedImage",
"image": {
"attributes": {
"class": "(^|\\s)check(\\s|$)"
}
},
"captures": [
"src"
],
"actions": [
"checkLink"
]
}
prose.md
# Check the icons a page uses
The page uses these icons:
![Target icon](http://localhost:8092/find-image-target.svg){.check}
![Gear icon](http://localhost:8092/find-image-gear.svg)

Each format sets class its own way: {.check} in Markdown, className in MDX, role= in AsciiDoc, :class: in reStructuredText, and outputclass in DITA.

excludes

Varies: markup.strong.excludes · Value: ^(?:Note|Tip):?$ · Effect: the Note: label isn’t turned into a find.

{
"name": "findBold",
"strong": {
"excludes": "^(?:Note|Tip):?$"
},
"actions": [
"find"
]
}
prose.md
# Check the field label
Open the type echo page.
**Note:** The field echoes each keystroke.
The field is labeled **Type here:**.

captures

Varies: markup.captures · Value: ["url"] · Effect: $1 is the link’s URL instead of its text, so the step checks the link.

{
"name": "checkLinkUrl",
"link": {},
"captures": [
"url"
],
"actions": [
"checkLink"
]
}
prose.md
# Check a link
Open [the type echo page](http://localhost:8092/type-echo.html).

Compare the link kind example, where $1 is the link text. DITA has no link nodes, so this example leaves it out.

batchMatches

Varies: markup.batchMatches · Value: true · Effect: the two code blocks join into one runCode step, so the second block can use the first block’s variable.

{
"name": "runScript",
"codeBlock": {
"language": [
"javascript"
]
},
"batchMatches": true,
"actions": [
{
"runCode": {
"language": "javascript",
"code": "$1"
}
}
]
}
prose.md
# Print a greeting with Node.js
Define the name to greet:
```javascript
const name = "Doc Detective";
```
Print the greeting:
```javascript
console.log(`Hello, ${name}!`);
```

regex without a selector

Varies: markup.regex · Value: \\bheading reads ([^.<]+)\\. · Effect: the pattern runs on the file’s raw text, including markup, and its first group becomes $1.

{
"name": "findHeading",
"regex": "\\bheading reads ([^.<]+)\\.",
"actions": [
"find"
]
}
prose.md
# Check the page heading
Open the type echo page.
The heading reads Type Echo Test Page.

Compare the text kind example, where the same kind of pattern runs only on prose. [^.<] keeps an HTML or DITA match from running into the closing tag.

language

Varies: markup.codeBlock.language · Value: ["bash"] · Effect: only the bash block runs. The text block that shows the output doesn’t.

{
"name": "runBash",
"codeBlock": {
"language": [
"bash"
]
},
"actions": [
"runShell"
]
}
prose.md
# Check the page's status code
Print the page's status code:
```bash
curl -s -o /dev/null -w "%{http_code}" http://localhost:8092/type-echo.html
```
The command prints:
```text
200
```

metaExcludes

Varies: markup.codeBlock.metaExcludes · Value: \\bno-run\\b · Effect: the bash block marked no-run doesn’t run.

{
"name": "runBash",
"codeBlock": {
"language": [
"bash"
],
"metaExcludes": "\\bno-run\\b"
},
"actions": [
"runShell"
]
}
prose.md
# Check that the page server is up
Request the type echo page:
```bash
curl -sf -o /dev/null http://localhost:8092/type-echo.html
```
If the request fails, start the server from the repository root:
```bash no-run
node test/server/start.js
```

HTML and DITA code blocks have no text after the language, so this example leaves them out. The meta is bash no-run in Markdown, [source,bash,no-run] in AsciiDoc, and :class: no-run in reStructuredText.

url

Varies: markup.link.url · Value: ^http://localhost:8092/ · Effect: only the link to the test server gets a checkLink. The #next-steps link doesn’t.

{
"name": "checkLocalLinks",
"link": {
"url": "^http://localhost:8092/"
},
"captures": [
"url"
],
"actions": [
"checkLink"
]
}
prose.md
# Check the page's links
Open [the type echo page](http://localhost:8092/type-echo.html). For more, see [Next steps](#next-steps).

DITA has no link nodes, so this example leaves it out.

src

Varies: markup.image.src · Value: \\.svg$ · Effect: only the SVG icon gets a checkLink. The PNG chart doesn’t.

{
"name": "checkSvg",
"image": {
"src": "\\.svg$"
},
"captures": [
"src"
],
"actions": [
"checkLink"
]
}
prose.md
# Check a hosted icon
The page uses this icon and chart:
![Target icon](http://localhost:8092/find-image-target.svg)
![Chart](http://localhost:8092/find-image-chart.png)

tag

Varies: markup.element.tag · Value: ["samp", "systemoutput"] · Effect: a <samp> element in Markdown, MDX, and HTML, or a <systemoutput> element in DITA, becomes a find.

{
"name": "findSample",
"element": {
"tag": [
"samp",
"systemoutput"
]
},
"actions": [
"find"
]
}
prose.md
# Check the field label
Open the type echo page.
The page shows <samp>Type here:</samp> next to the field.

AsciiDoc and reStructuredText produce no element nodes, so this example leaves them out.

actions permutations

Each example uses a bold phrase or an italic phrase and changes only the form of actions.

An action name

Varies: markup.actions · Value: ["click"] · Effect: the action takes $1 as its value, so detection clicks the bold phrase.

{
"name": "clickBold",
"strong": {},
"actions": [
"click"
]
}
prose.md
# Click the field
Open the type echo page.
Click **Type here:**.

An action name as a string

Varies: markup.actions · Value: "click" · Effect: a single action can skip the array. Detection clicks the bold phrase, as with ["click"].

{
"name": "clickBold",
"strong": {},
"actions": "click"
}
prose.md
# Click the field
Open the type echo page.
Click **Type here:**.

A step template

Varies: markup.actions · Value: [{ "find": { "elementText": "$1", "timeout": 5000 } }] · Effect: $1 fills a field of a full step, so the find sets its own timeout.

{
"name": "findBold",
"strong": {},
"actions": [
{
"find": {
"elementText": "$1",
"timeout": 5000
}
}
]
}
prose.md
# Check the field label
Open the type echo page.
The field is labeled **Type here:**.

A step with no $1

Varies: markup.actions · Value: [{ "wait": 500 }] · Effect: each match adds the same step. The italic phrase only marks where the wait goes.

{
"name": "waitForEcho",
"emphasis": {},
"actions": [
{
"wait": 500
}
]
}
prose.md
# Wait for the echo
Open the type echo page.
Type Hello, Doc Detective.
Wait _a moment_ for the echo.

extends permutations

Both examples use the same procedure and the same definition, which finds italic text. Only the file type’s form changes.

extends

Varies: fileTypes.extends · Value: markdown · Effect: the built-in definitions run too, so the bold label also becomes a find.

{
"extends": "markdown",
"markup": [
{
"name": "findItalic",
"emphasis": {},
"actions": [
"find"
]
}
]
}
prose.md
# Check the page heading
Open the type echo page.
The field is labeled **Type here:**.
The heading reads _Type Echo Test Page_.

From scratch

Varies: fileTypes.extends · Value: (not set) · Effect: only the custom definition runs, so the bold label is plain text. The file type needs its own extensions and inlineStatements.

{
"name": "markdown-custom",
"extensions": [
"md",
"mdx"
],
"inlineStatements": {
"in": [
"comment"
]
},
"markup": [
{
"name": "findItalic",
"emphasis": {},
"actions": [
"find"
]
}
]
}
prose.md
# Check the page heading
Open the type echo page.
The field is labeled **Type here:**.
The heading reads _Type Echo Test Page_.

runShell file type permutations

A file type with runShell doesn’t detect steps. Each matching file becomes one test with one runShell step, and $1 is the file’s absolute path. These examples run a Node.js check that fails when a release-notes file still says TODO. The detected variant is the whole file, so prose and detected are the same text. The examples leave out the other formats and the inline variant, because the file type runs every .txt file it matches.

runShell as a string

Varies: fileTypes.runShell · Value: "node -e \"…\" $1" · Effect: runs the command with $1 unquoted. On Windows, $1 uses forward slashes, so Bash reads the path intact.

doc-detective.json (fileTypes)
{
"fileTypes": [
{
"name": "release-notes",
"extensions": ["txt"],
"runShell": "node -e \"process.exit(require('fs').readFileSync(process.argv[1], 'utf8').includes('TODO') ? 1 : 0)\" $1"
}
]
}
prose.txt
Release notes for version 2.1
- The search box now matches part of a word.
- Exports keep the column order you set.

runShell as an object

Varies: fileTypes.runShell · Value: { "command": "node -e \"…\" '$1'", "timeout": 10000 } · Effect: takes any runShell field, here a timeout. Quoting '$1' keeps a path with spaces in one argument.

doc-detective.json (fileTypes)
{
"fileTypes": [
{
"name": "release-notes",
"extensions": ["txt"],
"runShell": {
"command": "node -e \"process.exit(require('fs').readFileSync(process.argv[1], 'utf8').includes('TODO') ? 1 : 0)\" '$1'",
"timeout": 10000
}
}
]
}
prose.txt
Release notes for version 2.1
- The search box now matches part of a word.
- Exports keep the column order you set.

The standalone variants run the same check on detected.txt, with workingDirectory set to the folder that holds the spec.

Replace or add a definition

Both examples extend the built-in formats with one definition that clicks bold text. Only the definition’s name changes.

A built-in name

Varies: markup.name · Value: findOnscreenText · Effect: the definition replaces the built-in one of that name, so detection clicks the bold label and doesn’t find it.

{
"name": "findOnscreenText",
"strong": {},
"actions": [
"click"
]
}
prose.md
# Click the field
Open the type echo page.
The field is labeled **Type here:**.

A new name

Varies: markup.name · Value: clickBoldText · Effect: the definition runs beside the built-in ones, so detection clicks the bold label and then finds it.

{
"name": "clickBoldText",
"strong": {},
"actions": [
"click"
]
}
prose.md
# Click the field
Open the type echo page.
The field is labeled **Type here:**.

inlineStatements permutations

The plain-text examples change the form of the regex statement keys. The others keep the built-in statements for the inline variants and add one in container that the detected variants use.

Regex keys as strings

Varies: inlineStatements.testStart · Value: (?:^|\\n)TEST (\\{.*\\}) · Effect: each key holds one pattern.

{
"testStart": "(?:^|\\n)TEST (\\{.*\\})",
"testEnd": "(?:^|\\n)END TEST",
"step": "(?:^|\\n)STEP (\\{.*\\})"
}
prose.txt
Check the field label
Open the type echo page at http://localhost:8092/type-echo.html.
Check that the page shows Type here:.

Regex keys as arrays

Varies: inlineStatements.testStart · Value: ["…TEST…", "…Test…"] · Effect: each key holds several patterns, so TEST and Test both start a test. The detected and inline variants use the Test, Step, and End test forms.

{
"testStart": [
"(?:^|\\n)TEST (\\{.*\\})",
"(?:^|\\n)Test (\\{.*\\})"
],
"testEnd": [
"(?:^|\\n)END TEST",
"(?:^|\\n)End test"
],
"step": [
"(?:^|\\n)STEP (\\{.*\\})",
"(?:^|\\n)Step (\\{.*\\})"
]
}
prose.txt
Check the field label
Open the type echo page at http://localhost:8092/type-echo.html.
Check that the page shows Type here:.

An in code block

Varies: inlineStatements.in[].codeBlock · Value: "dd" · Effect: a code block whose language is dd holds a statement.

{
"codeBlock": "dd"
}
prose.md
# Check the field label
Open the type echo page.
The field is labeled Type here:.

An in comment with regex

Varies: inlineStatements.in[].regex · Value: ^\\s*dd:\\s*([\\s\\S]*)$ · Effect: a comment that starts with dd: holds a statement, and regex keeps the text after the prefix.

{
"comment": {},
"regex": "^\\s*dd:\\s*([\\s\\S]*)$"
}
prose.md
# Check the field label
Open the type echo page.
The field is labeled Type here:.

An in element with value

Varies: inlineStatements.in[].value · Value: attributes.data-dd · Effect: an empty <span> holds its statement in the data-dd attribute.

{
"element": {
"tag": [
"span"
],
"attributes": {
"data-dd": true
}
},
"value": "attributes.data-dd"
}
prose.md
# Check the field label
Open the type echo page.
The field is labeled Type here:.

This example shows Markdown, MDX, and HTML. DITA’s built-in statements already use this form, with <data> and value.

includeStatements permutations

Each example includes a shared file whose line detection turns into a find. Includes need resolveIncludes, which is on by default.

One pattern

Varies: fileTypes.includeStatements · Value: ^INCLUDE (\\S+)$ · Effect: an INCLUDE line pulls in check-label.txt.

{
"includeStatements": "^INCLUDE (\\S+)$"
}
prose.txt
Check the field label
Open the type echo page at http://localhost:8092/type-echo.html.
INCLUDE check-label.txt

Several patterns

Varies: fileTypes.includeStatements · Value: ["^INCLUDE (\\S+)$", …] · Effect: an INCLUDE line and a #include line each pull in a file.

{
"includeStatements": [
"^INCLUDE (\\S+)$",
"^#include \"([^\"]+)\"$"
]
}
prose.txt
Check the field label
Open the type echo page at http://localhost:8092/type-echo.html.
INCLUDE check-label.txt
Then check the heading.
#include "check-heading.txt"