Adding attributes to the code fence info string (e.g., ```php ignore) can break syntax highlighting in editors like PHPStorm, VS Code, and others. These editors only recognize the language identifier (php) and treat anything else in the info string as unknown, disabling PHP-specific highlighting for the entire block.
HTML comment attributes solve this by moving attributes outside the code fence:
markdown
<!-- doctest-attr: ignore -->```php// Editor sees plain ```php — full syntax highlighting preservedecho 'Hello, World!';```
The rendered documentation looks identical — HTML comments are invisible to readers.
<!-- doctest-attr: attribute1 key="value" attribute2 -->```php// your code here```
The comment must appear on the line immediately before the code fence. If any other content (paragraphs, headings, etc.) appears between the comment and the fence, the comment is ignored.
Both syntaxes can coexist in the same file — some blocks can use info string attributes, others can use HTML comment attributes.
However, a single block cannot have the same attribute from both sources. If both the info string and the HTML comment set the same attribute (e.g., both set group), DocTest throws a RuntimeException:
Conflicting group: info string has 'cart' but HTML comment has 'orders'. Use only one source.
Complementary attributes are fine — for example, group from the comment and setup from the info string:
markdown
<!-- doctest-attr: group="db" -->```php setup$pdo = new PDO('sqlite::memory:');```
HTML Comment Attribute Syntax
An alternative way to specify attributes using HTML comments instead of the code fence info string.
Why?
Adding attributes to the code fence info string (e.g.,
```php ignore) can break syntax highlighting in editors like PHPStorm, VS Code, and others. These editors only recognize the language identifier (php) and treat anything else in the info string as unknown, disabling PHP-specific highlighting for the entire block.HTML comment attributes solve this by moving attributes outside the code fence:
The rendered documentation looks identical — HTML comments are invisible to readers.
Syntax
The comment must appear on the line immediately before the code fence. If any other content (paragraphs, headings, etc.) appears between the comment and the fence, the comment is ignored.
Supported Attributes
<!-- doctest-attr: ignore --><!-- doctest-attr: no_run --><!-- doctest-attr: throws --><!-- doctest-attr: throws(RuntimeException) --><!-- doctest-attr: throws(RuntimeException, "not found") --><!-- doctest-attr: parse_error --><!-- doctest-attr: group="name" --><!-- doctest-attr: setup group="name" --><!-- doctest-attr: teardown group="name" --><!-- doctest-attr: bootstrap="laravel" --><!-- doctest-attr: bootstrap="laravel,database" -->Multiple attributes can be combined in a single comment:
Examples
Ignore
No Run (syntax check only)
Throws
Group with setup
Bootstrap
One Comment Per Block
Only one
doctest-attrcomment is allowed before each code block. Multiple comments throw aRuntimeException:Combine all attributes into a single comment instead:
Merging Rules
Both syntaxes can coexist in the same file — some blocks can use info string attributes, others can use HTML comment attributes.
However, a single block cannot have the same attribute from both sources. If both the info string and the HTML comment set the same attribute (e.g., both set
group), DocTest throws aRuntimeException:Complementary attributes are fine — for example,
groupfrom the comment andsetupfrom the info string: