Skip to navigation

Markdown input format

Markdown is the most commonly used format for documentation sites. Doc Detective supports standard Markdown, MDX, and various Markdown flavors including GitHub Flavored Markdown.

File extensions

Doc Detective processes Markdown files with the following extensions:

  • .md
  • .markdown
  • .mdx

Inline test syntax

Markdown files support multiple comment styles for inline tests:

JSX-style comments (recommended for MDX):

{/* test { "testId": "my-test" } */}
{/* step { "goTo": "https://example.com" } */}
{/* test end */}

HTML comments:

<!-- test { "testId": "my-test-2" } -->
<!-- step { "goTo": "https://example.com" } -->
<!-- test end -->

Markdown link comments:

[comment]: # (test { "testId": "my-test-3" })
[comment]: # (step { "goTo": "https://example.com" })
[comment]: # (test end)

All three styles work identically. Choose the style that fits your documentation workflow. MDX doesn’t support HTML comments, so use the JSX-style or link style in .mdx files.

Doc Detective reads statements from comments only. A statement inside a code block or inline code is part of the sample, not a test.

Best practices

  • Use bold text for UI elements you want to interact with (buttons, menu items, etc.)
  • Use explicit navigation verbs (go to, navigate to, etc.) before links you want to open
  • Add the .screenshot class to images you want to capture as screenshots
  • Combine inline and detected tests for comprehensive coverage
  • Use testIgnore in code blocks that should not be executed as tests

Detected test patterns

With step detection on, Markdown files detect the steps listed in What gets detected. The definitions match parsed Markdown, so text inside code blocks and inline code never becomes a step. Links, images, and bold text written as HTML, such as <a href> and <strong>, count too, as do lowercase JSX tags in MDX.

Default Markdown definitions

The built-in definitions are selectors:

{
"fileTypes": [
{
"name": "markdown",
"extensions": [
"md",
"markdown",
"mdx"
],
"inlineStatements": {
"in": [
"comment"
]
},
"markup": [
{
"name": "goToUrl",
"link": {
"url": "^https?://",
"precededBy": "\\b(?:[Gg]o\\s+to|[Oo]pen|[Nn]avigate\\s+to|[Vv]isit|[Aa]ccess|[Pp]roceed\\s+to|[Ll]aunch|[Bb]rowse\\s+to)\\b\\s+$"
},
"captures": [
"url"
],
"actions": [
"goTo"
]
},
{
"name": "checkHyperlink",
"link": {
"url": "^https?://"
},
"captures": [
"url"
],
"actions": [
"checkLink"
]
},
{
"name": "clickOnscreenText",
"strong": {
"precededBy": "\\b(?:[Cc]lick|[Tt]ap|[Ll]eft-click|[Cc]hoose|[Ss]elect|[Cc]heck)\\b\\s+$"
},
"captures": [
"text"
],
"actions": [
"click"
]
},
{
"name": "findOnscreenText",
"strong": {},
"captures": [
"text"
],
"actions": [
"find"
]
},
{
"name": "screenshotImage",
"image": {
"attributes": {
"class": "(^|\\s)screenshot"
}
},
"captures": [
"src"
],
"actions": [
"screenshot"
]
},
{
"name": "typeText",
"text": {},
"regex": [
"\\b(?:[Pp]ress|[Ee]nter|[Tt]ype)\\b\\s+\"([^\"]+)\""
],
"actions": [
"type"
]
},
{
"name": "httpRequestFormat",
"codeBlock": {
"language": [
"http",
""
]
},
"regex": [
"^([A-Z]+)[ \\t]+(\\S+)(?:[ \\t]+HTTP\\/[\\d.]+)?[ \\t]*(?:\\r?\\n((?:\\S+:[ \\t]+[^\\r\\n]+(?:\\r?\\n|$))+))?(?:\\s+([\\s\\S]+?))?\\s*$"
],
"actions": [
{
"httpRequest": {
"method": "$1",
"url": "$2",
"request": {
"headers": "$3",
"body": "$4"
}
}
}
]
},
{
"name": "runCode",
"codeBlock": {
"language": [
"bash",
"python",
"py",
"javascript",
"js"
],
"metaExcludes": "testIgnore"
},
"captures": [
"language",
"content"
],
"actions": [
{
"unsafe": true,
"runCode": {
"language": "$1",
"code": "$2"
}
}
]
}
]
}
]
}

Pattern descriptions

DefinitionMarkdown that matchesStep
goToUrlGo to [Acme](https://acme.com), and the other navigation verbsgoTo
checkHyperlinkAny link to an http or https URL, such as [docs](https://docs.example.com)checkLink
clickOnscreenTextClick **Search**, Select __Save__, and the other click verbsclick
findOnscreenTextAny bold textfind
screenshotImage![Results](results.png){.screenshot}screenshot
typeTextType "kittens", Enter "admin", or Press "Enter" in prosetype
httpRequestFormatA code block tagged http, or with no language, that holds a requesthttpRequest
runCodeA code block tagged bash, python, py, javascript, or jsrunCode, marked unsafe

A bold phrase is its rendered text, so **`Save`** finds Save. A screenshot’s attribute list can sit right after the image, as in {.screenshot} or {: .screenshot}.

An HTTP request block holds the method and URL on its first line, then any headers, then a blank line and the body. A header’s value runs to the end of its line, spaces included:

```http
POST https://api.example.com/users HTTP/1.1
Content-Type: application/json; charset=utf-8
{"name": "test"}
```

To keep a code block from running, add testIgnore after its language, as in ```bash testIgnore.

Example with detected tests

Markdown input:

To get started,
1. Go to [Acme Console](https://console.acme.com).
2. Click **Search**.
3. Type "American Shorthair kittens".
Check out our [documentation](https://docs.example.com) for more information.
![Search results](search-results.png){ .screenshot }

Detected tests:

{
"tests": [
{
"steps": [
{ "goTo": "https://console.acme.com" },
{ "checkLink": "https://console.acme.com" },
{ "click": "Search" },
{ "find": "Search" },
{ "type": "American Shorthair kittens" },
{ "checkLink": "https://docs.example.com" },
{ "screenshot": "search-results.png" }
]
}
]
}

Each link gets a checkLink step, including the one after “Go to”, and each bold phrase gets a find step, including the one after “Click”.

Combining inline and detected tests

You can mix inline test statements with detected tests for maximum flexibility:

{/* test { "testId": "tutorial", "detectSteps": true } */}
## Setup Instructions
1. Go to [Console](https://console.example.com).
2. Click **Login**.
{/* step { "type": { "keys": "username", "selector": "[name=username]" } } */}
{/* step { "type": { "keys": "password", "selector": "[name=password]" } } */}
3. Click **Submit**.
{/* test end */}

In this example:

  • The navigation and button clicks are detected automatically
  • Specific form field typing is defined inline for precise control
  • detectSteps: true enables detection within the test block

Next steps