This tool updates examples in fenced code blocks in markdown files to match source files in example/ or test/, using the same #region, #endregion, and #hide markers as dartdoc's {@example} directive.
Mark a region in an example or test file:
import 'package:test/test.dart'; void main() { test('greets the world', () { // #region greeting final message = 'Hello, world!'; print(message); // #endregion greeting expect(message, isNotEmpty); }); }
Reference the file (or #region) after @example in your markdown fence's info string:
```dart @example example/example.dart#greeting final message = 'Hello, world!'; print(message); ```
A leading / resolves from the package root; any other path resolves relative to the markdown file. Pass indent=keep (default indent=strip) to keep shared leading indentation.
Update all markdown files locally (requires Dart 3.12+):
$ dart run snippets@ update
Check that no markdown code block is out of date:
$ dart run snippets@ validate
In GitHub Actions, call the reusable workflow (pinned to a commit SHA):
jobs: examples: uses: dart-lang/tools/.github/workflows/validate_snippets.yaml@<commit-sha>