• Stars
    star
    473
  • Rank 92,832 (Top 2 %)
  • Language
    Dart
  • License
    BSD 3-Clause "New...
  • Created about 10 years ago
  • Updated 28 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

API documentation tool for Dart.

Dart documentation generator

Build Status OpenSSF Scorecard

Use dart doc to generate HTML documentation for your Dart package.

For information about contributing to the dartdoc project, see the contributor docs.

For issues/details related to the hosted Dart SDK API docs, see dart-lang/api.dart.dev.

Installation

The dart tool, with the dart doc command, is part of the Dart SDK.

Generating docs

Run dart doc . from the root directory of a package. You must first run dart pub get or flutter pub get and your package must analyze without errors with dart analyze or flutter analyze as appropriate. Here is an example of dartdoc documenting itself:

$ dart pub get
...
$ dart doc .
Documenting dartdoc...
...
Initialized dartdoc with 766 libraries in 63.9 seconds
Generating docs for library dartdoc from package:dartdoc/dartdoc.dart...
Validating docs...
no issues found
Documented 1 public library in 17.9 seconds
Success! Docs generated into <path to dartdoc>/doc/api

By default, the documentation is generated to the doc/api directory as static HTML files.

To view the generated documentation, you must load them with an HTTP server. To learn more, follow the Viewing docs guide.

Run dart help doc to see the available command-line options.

Viewing docs

To enable navigation and search, the generated docs must be served with an HTTP server.

An easy way to run an HTTP server locally is to use package:dhttpd. For example:

$ dart pub global activate dhttpd
$ dart pub global run dhttpd --path doc/api

To then read the generated docs in your browser, open the link that dhttpd outputs, usually http://localhost:8080.

Link structure

dartdoc produces static files with a predictable link structure.

index.html                          # homepage
index.json                          # machine-readable index
library-name/                       # : is turned into a - e.g. dart:core => dart-core
  ClassName-class.html              # "homepage" for a class (and enum)
  ClassName/
    ClassName.html                  # constructor
    ClassName.namedConstructor.html # named constructor
    method.html
    property.html
  CONSTANT.html
  property.html
  top-level-function.html

File names are case-sensitive.

Writing docs

To learn about writing documentation comments, check out the Effective Dart: Documentation guide.

The guide covers formatting, linking, markup, and general best practices when authoring doc comments for Dart with dart doc.

Excluding from documentation

dart doc will not generate documentation for a Dart element and its children that have the @nodoc tag in the documentation comment.

Advanced features

dartdoc_options.yaml

Creating a file named dartdoc_options.yaml at the top of your package can change how Dartdoc generates docs.

An example (not necessarily recommended settings):

dartdoc:
  categories:
    "First Category":
      markdown: doc/First.md
      name: Awesome
    "Second Category":
      markdown: doc/Second.md
      name: Great
  categoryOrder: ["First Category", "Second Category"]
  includeExternal: ['bin/unusually_located_library.dart']
  nodoc: ['lib/sekret/*.dart']
  linkTo:
    url: "https://my.dartdocumentationsite.org/dev/%v%"
  showUndocumentedCategories: true
  ignore:
    - ambiguous-doc-reference
  errors:
    - unresolved-doc-reference
  warnings:
    - tool-error

dartdoc_options.yaml fields

In general, paths are relative to the directory of the dartdoc_options.yaml file in which the option is defined, and should be specified as POSIX paths. Dartdoc will convert POSIX paths automatically on Windows. Unrecognized options will be ignored. Supported options:

  • categories: More details for each category/topic. For topics you'd like to document, specify the markdown file with markdown: to use for the category page. Optionally, rename the category from the source code into a display name with name:. If there is no matching category defined in dartdoc_options.yaml, those declared categories in the source code will be invisible.
  • categoryOrder: Specify the order of topics for display in the sidebar and the package page.
  • exclude: Specify a list of library names to avoid generating docs for, overriding any specified in include. All libraries listed must be local to this package, unlike the command line --exclude. See also nodoc.
  • errors: Specify warnings to be treated as errors. See the lists of valid warnings in the command line help for --errors, --warnings, and --ignore.
  • favicon: A path to a favicon for the generated docs.
  • footer: A list of paths to footer files containing HTML text.
  • footerText: A list of paths to text files for optional text next to the package name and version
  • header: A list of paths to header files containing HTML text.
  • ignore: Specify warnings to be completely ignored. See the lists of valid warnings in the command line help for --errors, --warnings, and --ignore.
  • include: Specify a list of library names to generate docs for, ignoring all others. All libraries listed must be local to this package (unlike the command line --include).
  • includeExternal: Specify a list of library filenames to add to the list of documented libraries.
  • linkTo: For other packages depending on this one, if this map is defined those packages will use the settings here to control how hyperlinks to the package are generated. This will override the default for packages hosted on pub.dev and api.flutter.dev.
    • url: A string indicating the base URL for documentation of this package. Ordinarily you do not need to set this in the package: consider --link-to-hosted and --link-to-sdks instead of this option if you need to build your own website with dartdoc.

      The following strings will be substituted in to complete the URL:

      • %b%: The branch as indicated by text in the version. 2.0.0-dev.3 is branch "dev". No branch is considered to be "stable".
      • %n%: The name of this package, as defined in pubspec.yaml.
      • %v%: The version of this package as defined in pubspec.yaml.
  • linkToSource: Generate links to a source code repository based on given templates and revision information.
    • excludes: A list of directories to exclude from processing source links.

    • root: The directory to consider the 'root' for inserting relative paths into the template. Source code outside the root directory will not be linked.

    • uriTemplate: A template to substitute revision and file path information. If revision is present in the template but not specified, or if root is not specified, dartdoc will throw an exception. To hard-code a revision, don't specify it with %r%.

      The following strings will be substituted in to complete the URL:

      • %f%: Relative path of file to the repository root
      • %r%: Revision
      • %l%: Line number
  • nodoc: Specify files (via globs) which should be treated as though they have the @nodoc tag in the documentation comment of every defined element. Unlike exclude this can specify source files directly, and neither inheritance nor reexports will cause these elements to be documented when included in other libraries. For more fine-grained control, use @nodoc in element documentation comments directly, or the exclude directive.
  • warnings: Specify otherwise ignored or set-to-error warnings to simply warn. See the lists of valid warnings in the command line help for --errors, --warnings, and --ignore.

Unsupported and experimental options:

  • ambiguousReexportScorerMinConfidence: The ambiguous reexport scorer will emit a warning if it is not at least this confident. Adjusting this may be necessary for some complex packages but most of the time, the default is OK. Default: 0.1

Categories

You can tag libraries or top level classes, functions, and variables in their documentation with the string {@category YourCategory}. For libraries, that will cause the library to appear in a category when showing the sidebar on the Package and Library pages. For other types of objects, the {@category} will be shown with a link to the category page but only if specified in dartdoc_options.yaml, as above.

/// Here is my library.
///
/// {@category Amazing}
library my_library;

Other category tags and categories.json

A file categories.json will be generated at the top level of the documentation tree with information about categories collected from objects in the source tree. The directives @category, and @subCategory are understood and saved into this json.

As an example, if we document the class Icon in flutter using the following:

/// {@category Basics}
/// {@category Assets and Icons}
/// {@subCategory Information displays}
class Icon extends StatelessWidget {}

that will result in the following json:

  {
    "name": "Icon",
    "qualifiedName": "widgets.Icon",
    "href": "widgets/Icon-class.html",
    "type": "class",
    "categories": [
      "Assets and Icons",
      "Basics"
    ],
    "subcategories": [
      "Information displays"
    ],
  }

Animations

You can specify links to videos inline that will be handled with a simple HTML5 player:

/// This widget is a dancing Linux penguin.
///
/// {@animation name 100 200 http://host.com/path/to/video.mp4}

'name' is user defined, and the numbers are the width and height of the animation in pixels.

Macros

You can specify "macros", i.e. reusable pieces of documentation. For that, first specify a template anywhere in the comments, like:

/// {@template template_name}
/// Some shared docs
/// {@endtemplate}

and then you can insert it via {@macro template_name}, like

/// Some comment
/// {@macro template_name}
/// More comments

Template definitions are currently unscoped -- if dartdoc reads a file containing a template, it can be used in anything dartdoc is currently documenting. This can lead to inconsistent behavior between runs on different packages, especially if different command lines are used for dartdoc. It is recommended to use collision-resistant naming for any macros by including the package name and/or library it is defined in within the name.

Tools

Dartdoc allows you to filter parts of the documentation through an external tool and then include the output of that tool in place of the given input.

First, you have to configure the tools that will be used in the dartdoc_options.yaml file:

dartdoc:
  tools:
    drill:
      command: ["bin/drill.dart"]
      setup_command: ["bin/setup.dart"]
      description: "Puts holes in things."
      compile_args: ["--no-sound-null-safety"]
    echo:
      macos: ['/bin/sh', '-c', 'echo']
      setup_macos: ['/bin/sh', '-c', 'setup.sh']
      linux: ['/bin/sh', '-c', 'echo']
      setup_linux: ['/bin/sh', '-c', 'setup.sh']
      windows: ['C:\\Windows\\System32\\cmd.exe', '/c', 'echo']
      setup_windows: ['/bin/sh', '-c', 'setup.sh']
      description: 'Works on everything'

The command tag is used to describe the command executable, and any options that are common among all executions. If the first element of this list is a filename that ends in .dart, then the dart executable will automatically be used to invoke that script. The command defined will be run on all platforms.

If the command is a Dart script, then the first time it is run, a snapshot will be created using the input and first-time arguments as training arguments, and will be run from the snapshot from then on. Note that the Platform.script property will point to the snapshot location during the snapshot runs. You can obtain the original .dart script location in a tool by looking at the TOOL_COMMAND environment variable.

The setup_command tag is used to describe a command executable, and any options, for a command that is run once before running a tool for the first time. If the first element of this list is a filename that ends in .dart, then the dart executable will automatically be used to invoke that script. The setup_command defined will be run on all platforms. If the setup command is a Dart script, then it will be run with the Dart executable, but will not be snapshotted, as it will only be run once.

The macos, linux, and windows tags are used to describe the commands to be run on each of those platforms, and the setup_macos, setup_linux, and setup_windows tags define setup commands for their respective platforms.

The description is just a short description of the tool for use as help text.

Only tools which are configured in the dartdoc_options.yaml file are able to be invoked.

The compile_args tag is used to pass options to the dart compiler when the first run of the tool is being snapshotted.

To use the tools in comment documentation, use the {@tool <name> [<options> ...] [$INPUT]} directive to invoke the tool:

/// {@tool drill --flag --option="value" $INPUT}
/// This is the text that will be sent to the tool as input.
/// {@end-tool}

The $INPUT argument is a special token that will be replaced with the name of a temporary file that the tool needs to read from. It can appear anywhere in the options, and can appear multiple times.

If the example drill tool with those options is a tool that turns the content of its input file into a code-font heading, then the directive above would be the equivalent of having the following comment in the code:

/// # `This is the text that will be sent to the tool as input.`

Tool Environment Variables

Tools have a number of environment variables available to them. They will be interpolated into any arguments given to the tool as $ENV_VAR or $(ENV_VAR), as well as available in the process environment.

  • SOURCE_LINE: The source line number in the original source code.
  • SOURCE_COLUMN: The source column in the original source code.
  • SOURCE_PATH: The relative path from the package root to the original source file.
  • PACKAGE_PATH: The path to the package root.
  • PACKAGE_NAME: The name of the package.
  • LIBRARY_NAME: The name of the library, if any.
  • ELEMENT_NAME: The name of the element that this doc is attached to.
  • TOOL_COMMAND: The path to the original .dart script or command executable.
  • DART_SNAPSHOT_CACHE: The path to the directory containing the snapshot files of the tools. This directory will be removed before Dartdoc exits.
  • DART_SETUP_COMMAND: The path to the setup command script, if any.
  • INVOCATION_INDEX: An index for how many times a tool directive has been invoked on the current dartdoc block. Allows multiple tool invocations on the same block to be differentiated.

Injecting HTML

It rarely happens, but sometimes what you really need is to inject some raw HTML into the dartdoc output, without it being subject to Markdown processing beforehand. This can be useful when the output of an external tool is HTML, for instance. This is where the {@inject-html}...{@end-inject-html} tags come in.

For security reasons, the {@inject-html} directive will be ignored unless the --inject-html flag is given on the dartdoc command line.

Since this HTML fragment doesn't undergo Markdown processing, reference links and other normal processing won't happen on the contained fragment.

So, this:

  ///     {@inject-html}
  ///     <p>[The HTML to inject.]()</p>
  ///     {@end-inject-html}

Will result in this be emitted in its place in the HTML output (notice that the markdown link isn't linked).

<p>[The HTML to inject.]()</p>

It's best to only inject HTML that is self-contained and doesn't depend upon other elements on the page, since those may change in future versions of Dartdoc.

Auto including dependencies

If --auto-include-dependencies flag is provided, dartdoc tries to automatically add all the used libraries, even from other packages, to the list of the documented libraries.

Using linkToSource

The source linking feature in dartdoc is a little tricky to use, since pub packages do not actually include enough information to link back to source code and that's the context in which documentation is generated for the pub site. This means that for now, it must be manually specified in dartdoc_options.yaml what revision to use. It is currently a recommended practice to specify a revision in dartdoc_options.yaml that points to the same revision as your public package. If you're using a documentation staging system outside of Dart's pub site, override the template and revision on the command line with the head revision number. You can use the branch name, but generated docs will generate locations that may start drifting with further changes to the branch.

Example dartdoc_options.yaml:

linkToSource:
  root: '.'
  uriTemplate: 'https://github.com/dart-lang/dartdoc/blob/v0.28.0/%f%#L%l%'

Example staging command line:

dart pub global run dartdoc --link-to-source-root '.' --link-to-source-revision 6fac6f770d271312c88e8ae881861702a9a605be --link-to-source-uri-template 'https://github.com/dart-lang/dartdoc/blob/%r%/%f%#L%l%'

This gets more complicated with --auto-include-dependencies as these command line flags will override all settings from individual packages. In that case, to preserve source links from third party packages it may be necessary to generate dartdoc_options.yaml options for each package you are intending to add source links to yourself.

Issues and bugs

Please file reports on the GitHub Issue Tracker. Issues are labeled with priority based on how much impact to the ecosystem the issue addresses and the number of generated pages that show the anomaly (widespread vs. not widespread).

Some examples of likely triage priorities:

  • P0

    • Broken links, widespread
    • Uncaught exceptions, widespread
    • Incorrect linkage outside of comment references, widespread
    • Very ugly or navigation impaired generated pages, widespread
    • Generation errors for high priority users (Flutter, Pub, Fuchsia, Dart), widespread and/or blocking critical teams
  • P1

    • Broken links, few or on edge cases
    • Uncaught exceptions, very rare or with simple workarounds
    • Incorrect linkage outside of comment references, few or on edge cases
    • Incorrect linkage in comment references, widespread or with high impact
    • Incorrect doc contents, widespread or with high impact
    • Minor display warts not significantly impeding navigation, widespread
    • Default-on warnings that are misleading or wrong, widespread
    • Generation errors that should be detected but aren't warned, widespread
    • Enhancements that have significant data around them indicating they are a big win
    • User performance problem (e.g. page load, search), widespread
    • Generation errors for high priority users (Flutter, Pub, Fuchsia, Dart), not widespread or blocking critical teams
  • P2

    • Incorrect doc contents, not widespread
    • Incorrect linkage in comment references, not widespread
    • Minor display warts not significantly impeding navigation, not widespread
    • Generation problems that should be detected but aren't warned, not widespread
    • Default-on warnings that are misleading or wrong, few or on edge cases
    • Non-default warnings that are misleading or wrong, widespread
    • Enhancements considered important but without significant data indicating they are a big win
    • User performance problem (e.g. page load, search), not widespread
    • Generation performance problem, widespread
  • P3

    • Theoretical or extremely rare problems with generation
    • Minor display warts on edge cases only
    • Non-default warnings that are misleading or wrong, few or on edge cases
    • Enhancements whose importance is uncertain
    • Generation performance problem, limited impact or not widespread

License

Please see the dartdoc license.

Generated docs include:

More Repositories

1

sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
Dart
10,110
star
2

language

Design of the Dart language
TeX
2,652
star
3

dart-pad

An online Dart editor with support for console, web, and Flutter apps
Dart
1,702
star
4

pub

The pub command line tool
Dart
1,040
star
5

http

A composable API for making HTTP requests in Dart.
Dart
1,021
star
6

site-www

Source for Dart website
Dart
944
star
7

shelf

Web server middleware for Dart
Dart
920
star
8

build

A build system for Dart written in Dart
Dart
785
star
9

pub-dev

The pub.dev website
Dart
785
star
10

dart_style

An opinionated formatter/linter for Dart code
Dart
645
star
11

dart-vim-plugin

Syntax highlighting for Dart in Vim
Vim Script
637
star
12

mockito

Mockito-inspired mock library for Dart
Dart
632
star
13

linter

Linter for Dart.
Dart
628
star
14

samples

A collection of Dart code samples by Dart DevRel
Dart
602
star
15

test

A library for writing unit tests in Dart.
Dart
492
star
16

source_gen

Automatic source code generation for Dart
Dart
484
star
17

markdown

A Dart markdown library
Dart
444
star
18

code_builder

A fluent API for generating valid Dart source code
Dart
428
star
19

web_socket_channel

StreamChannel wrappers for WebSockets.
Dart
418
star
20

leak_tracker

A framework for memory leak tracking for Dart and Flutter applications.
Dart
387
star
21

collection

The collection package for Dart contains a number of separate libraries with utility functions and classes that makes working with collections easier.
Dart
375
star
22

ffigen

FFI binding generator
Dart
364
star
23

logging

A Dart package for debug and error logging.
Dart
332
star
24

async

A Dart package that contains tools to work with asynchronous computations.
Dart
320
star
25

wasm

Utilities for loading and running WASM modules from Dart code
Dart
309
star
26

html

Dart port of html5lib. For parsing HTML/HTML5 with Dart. Works in the client and on the server.
Dart
276
star
27

crypto

A set of cryptographic functions implemented in pure Dart.
Dart
275
star
28

path

A string-based path manipulation library.
Dart
223
star
29

args

A command-line argument parsing library for Dart.
Dart
214
star
30

webdev

A CLI for Dart web development.
Dart
212
star
31

oauth2

An OAuth2 client library for Dart.
Dart
211
star
32

pana

Package ANAlysis for Dart
Dart
205
star
33

setup-dart

A GitHub Action to install and setup a Dart SDK.
Dart
188
star
34

yaml

A Dart YAML parser.
Dart
169
star
35

jnigen

Experimental bindings generator for Java bindings through dart:ffi and JNI.
Dart
154
star
36

homebrew-dart

Dart team's official tap for homebrew.
Ruby
153
star
37

native

Dart packages related to FFI and native assets bundling.
Dart
153
star
38

http2

A HTTP/2 implementation for dart.
Dart
153
star
39

sample-pop_pop_win

"Pop, Pop, Win!" is an implementation of Minesweeper in Dart.
Dart
149
star
40

usage

A Google Analytics wrapper for command-line, web, and Flutter apps.
Dart
143
star
41

watcher

A file system watcher library for Dart.
Dart
138
star
42

mime

Dart package for working with MIME type definitions and for processing streams of MIME multipart media types.
Dart
132
star
43

stack_trace

A package for manipulating stack traces and printing them readably.
Dart
128
star
44

web

Lightweight browser API bindings built around JS static interop.
Dart
128
star
45

gcloud

High-level interfaces to Google Cloud Platform APIs
Dart
126
star
46

platform

A generic platform abstraction for Dart
Dart
125
star
47

stream_transform

Dart utility methods to create StreamTransfomer instances to manipulate Streams
Dart
123
star
48

lints

Official Dart lint rules; the core and recommended set of lints suggested by the Dart team.
Dart
116
star
49

coverage

Dart coverage data manipulation and formatting
Dart
103
star
50

sse

Dart Server Sent Events package
Dart
96
star
51

csslib

A library for parsing CSS.
Dart
95
star
52

benchmark_harness

The official benchmark harness for Dart
Dart
94
star
53

appengine

Dart support for App Engine managed VMs
Dart
93
star
54

fake_async

Fake asynchronous events for deterministic testing.
Dart
90
star
55

convert

Conversion utilities
Dart
72
star
56

matcher

A declarative API for specifying expectations.
Dart
71
star
57

json_rpc_2

A Dart implementation of the JSON-RPC 2.0 spec.
Dart
71
star
58

characters

A package for characters represented as unicode extended grapheme clusters
Dart
69
star
59

dart-docker

Docker images for the Dart programming language (https://dart.dev)
Dart
68
star
60

pub_semver

A package for working with Pub/semver-style versions and version constraints
Dart
65
star
61

i18n

A general mono-repo for Dart i18n and l10n packages.
Dart
63
star
62

cli_util

A library to help in building Dart command-line apps
Dart
60
star
63

string_scanner

A class for parsing strings using a sequence of patterns.
Dart
60
star
64

glob

Bash-style filename globbing for Dart.
Dart
56
star
65

pubspec_parse

Simple package for parsing pubspec.yaml files with a type-safe API and rich error reporting
Dart
51
star
66

pool

A class for managing a finite pool of resources.
Dart
51
star
67

stream_channel

An abstraction for two-way communication channels.
Dart
50
star
68

io

Utilities for the Dart VM's dart:io.
Dart
49
star
69

macros

A Dart mono-repo for macro development.
Dart
48
star
70

fixnum

Fixed-width integer library for Dart.
Dart
45
star
71

clock

A fakeable wrapper for dart:core clock APIs.
Dart
41
star
72

ecosystem

This repository is home to general Dart Ecosystem tools and packages.
Dart
41
star
73

http_parser

A platform-independent Dart package for parsing and serializing HTTP formats.
Dart
39
star
74

site-shared

Content shared across Dart websites
JavaScript
38
star
75

co19

A Dart language and library conformance test suite
Dart
37
star
76

typed_data

Utility functions and classes that makes working with typed data lists easier in Dart
Dart
34
star
77

source_span

A library for identifying source spans and locations.
Dart
29
star
78

tools

This repository is home to tooling related Dart packages.
Dart
29
star
79

http_multi_server

A dart:io HttpServer wrapper that handles requests from multiple servers.
Dart
28
star
80

yaml_edit

A library for YAML manipulation with comment and whitespace preservation.
Dart
27
star
81

native_synchronization

Low-level synchronization primitives built using dart:ffi.
Dart
26
star
82

os_detect

Dart multi-platform operating system identification
Dart
24
star
83

dartbug.com

The redirect service for Dart issues and bugs.
Dart
23
star
84

bazel_worker

Dart integration for Bazel build system
Dart
23
star
85

boolean_selector

A flexible syntax for boolean expressions.
Dart
23
star
86

dart-syntax-highlight

Tools and documentation for how Dart code is formatted
Dart
22
star
87

api.dart.dev

Dart API docs
Python
19
star
88

grpc_cronet

Flutter dart:grpc implementation that uses the Cronet native library.
Dart
18
star
89

dart_ci

Tools used by Dart's continuous integration (CI) testing that aren't needed by Dart SDK contributors. Mirrored from dart.googlesource.com/dart_ci. Do not land pull requests on Github.
Dart
18
star
90

source_maps

A package to programmatically manipulate source maps.
Dart
16
star
91

term_glyph

Useful glyphs and Windows-safe equivalents
Dart
16
star
92

package_config

Support for working with Package Resolution Configuration files
Dart
16
star
93

test_process

A Dart package for testing subprocesses
Dart
16
star
94

browser_launcher

Provides a standardized way to launch web browsers.
Dart
16
star
95

timing

A Dart package for tracking time spent in child operations
Dart
14
star
96

root_certificates

The set of root certificates trusted by dart:io's default SecurityContext. Taken from Mozilla's NSS library.
C++
11
star
97

test_descriptor

Provides a convenient, easy-to-read API for defining and verifying directory structures in tests
Dart
10
star
98

dartlang_project_templates

Project templates for new repos under the dart-lang organization
Dart
8
star
99

source_map_stack_trace

Convert stack traces generated by dart2js-compiled code into readable native Dart stack traces
Dart
8
star
100

.github

GitHub default community health file for dart-lang repos
7
star