dart doc tool to generate structured HTML API reference documentation. Unlike standard comments, which are ignored by the documentation compiler, documentation comments are lexically bound to the declaration that immediately follows them and natively support Markdown formatting.
Syntax
Dart supports two syntaxes for documentation comments: single-line (///) and multi-line (/** ... */). The Dart style guide strongly mandates the use of consecutive single-line /// comments over the block syntax for all API documentation.
Parsing Rules and Structure
Thedart doc compiler parses the text within documentation comments using specific structural rules:
- Summary Sentence: The compiler parses the first sentence of a documentation comment (up to the first period followed by whitespace) as the concise summary. This summary is extracted and displayed in high-level lists and tables within the generated documentation.
- Detailed Description: Any text following the summary sentence is parsed as the detailed description, appearing only on the specific page for that member.
- Markdown Processing: The compiler processes standard Markdown elements, including bolding (
**text**), italics (*text*), lists, and code blocks.
Lexical Linking
Dart documentation comments feature a specialized bracket syntax[identifier] to create hyperlinked references to other in-scope API elements.
When the compiler encounters brackets, it attempts to resolve the enclosed text against the lexical scope of the documented element. It can resolve:
- Parameters of the current method/function.
- Methods, properties, and constructors of the current class.
- Top-level functions, classes, and variables in the current library or imported libraries.
[ClassName.constructorName] or [ClassName.methodName].
Directives and Pragmas
The documentation compiler recognizes specific directives (often prefixed with@) embedded within the comments to control documentation generation:
@nodoc: Instructs the compiler to exclude the associated member (and its children, if it is a class) from the generated HTML output, even if it is public.@template/@macro: Used for documentation reuse.@template template_namedefines a block of documentation, and{@macro template_name}injects that block into another documentation comment, preventing duplication across similar API members.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More





