• Stars
    star
    459
  • Rank 91,867 (Top 2 %)
  • Language
    Dart
  • License
    BSD 3-Clause "New...
  • Created over 9 years ago
  • Updated 20 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, dart2js, core libraries, and more.
Dart
9,763
star
2

language

Design of the Dart language
TeX
2,536
star
3

dart-pad

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

pub

The pub command line tool
Dart
1,024
star
5

http

A composable API for making HTTP requests in Dart.
Dart
994
star
6

site-www

Source for Dart website
Dart
922
star
7

shelf

Web server middleware for Dart
Dart
870
star
8

build

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

pub-dev

The pub.dev website
Dart
762
star
10

dart-vim-plugin

Syntax highlighting for Dart in Vim
Vim Script
635
star
11

dart_style

An opinionated formatter/linter for Dart code
Dart
629
star
12

linter

Linter for Dart.
Dart
626
star
13

mockito

Mockito-inspired mock library for Dart
Dart
618
star
14

samples

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

test

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

source_gen

Automatic source code generation for Dart
Dart
479
star
17

markdown

A Dart markdown library
Dart
428
star
18

code_builder

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

web_socket_channel

StreamChannel wrappers for WebSockets.
Dart
405
star
20

leak_tracker

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

ffigen

FFI binding generator
Dart
364
star
22

collection

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

logging

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

wasm

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

async

A Dart package that contains tools to work with asynchronous computations.
Dart
300
star
26

html

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

crypto

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

path

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

webdev

A CLI for Dart web development.
Dart
210
star
30

oauth2

An OAuth2 client library for Dart.
Dart
208
star
31

args

A command-line argument parsing library for Dart.
Dart
202
star
32

pana

Package ANAlysis for Dart
Dart
190
star
33

setup-dart

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

yaml

A Dart YAML parser.
Dart
163
star
35

jnigen

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

http2

A HTTP/2 implementation for dart.
Dart
150
star
37

ffi

Utilities for working with Foreign Function Interface (FFI) code
Dart
149
star
38

homebrew-dart

Dart team's official tap for homebrew.
Ruby
147
star
39

sample-pop_pop_win

"Pop, Pop, Win!" is an implementation of Minesweeper in Dart.
Dart
146
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
135
star
42

stack_trace

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

gcloud

High-level interfaces to Google Cloud Platform APIs
Dart
127
star
44

mime

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

stream_transform

Dart utility methods to create StreamTransfomer instances to manipulate Streams
Dart
118
star
46

lints

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

coverage

Dart coverage data manipulation and formatting
Dart
102
star
48

appengine

Dart support for App Engine managed VMs
Dart
93
star
49

csslib

A library for parsing CSS.
Dart
92
star
50

benchmark_harness

The official benchmark harness for Dart
Dart
92
star
51

web

Lightweight browser API bindings built around JS static interop.
Dart
89
star
52

sse

Dart Server Sent Events package
Dart
89
star
53

fake_async

Fake asynchronous events for deterministic testing.
Dart
87
star
54

native

Dart packages related to FFI and native assets bundling.
Dart
74
star
55

matcher

A declarative API for specifying expectations.
Dart
70
star
56

json_rpc_2

A Dart implementation of the JSON-RPC 2.0 spec.
Dart
70
star
57

convert

Conversion utilities
Dart
68
star
58

characters

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

dart-docker

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

pub_semver

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

string_scanner

A class for parsing strings using a sequence of patterns.
Dart
59
star
62

cli_util

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

glob

Bash-style filename globbing for Dart.
Dart
55
star
64

pubspec_parse

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

i18n

A general mono-repo for Dart i18n and l10n packages.
Dart
50
star
66

pool

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

stream_channel

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

io

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

fixnum

Fixed-width integer library for Dart.
Dart
44
star
70

clock

A fakeable wrapper for dart:core clock APIs.
Dart
40
star
71

site-shared

Content shared across Dart websites
Dart
40
star
72

co19

A Dart language and library conformance test suite
Dart
36
star
73

http_parser

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

ecosystem

This repository is home to general Dart Ecosystem tools and packages.
Dart
35
star
75

typed_data

Utility functions and classes that makes working with typed data lists easier in Dart
Dart
35
star
76

source_span

A library for identifying source spans and locations.
Dart
28
star
77

http_multi_server

A dart:io HttpServer wrapper that handles requests from multiple servers.
Dart
27
star
78

native_synchronization

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

dartbug.com

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

bazel_worker

Dart integration for Bazel build system
Dart
23
star
81

boolean_selector

A flexible syntax for boolean expressions.
Dart
23
star
82

os_detect

Dart multi-platform operating system identification
Dart
22
star
83

dart-syntax-highlight

Tools and documentation for how Dart code is formatted
Dart
21
star
84

yaml_edit

A library for YAML manipulation with comment and whitespace preservation.
Dart
21
star
85

tools

This repository is home to tooling related Dart packages.
Dart
21
star
86

api.dart.dev

Dart API docs
Python
19
star
87

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
88

test_process

A Dart package for testing subprocesses
Dart
17
star
89

term_glyph

Useful glyphs and Windows-safe equivalents
Dart
16
star
90

browser_launcher

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

source_maps

A package to programmatically manipulate source maps.
Dart
15
star
92

grpc_cronet

Flutter dart:grpc implementation that uses the Cronet native library.
Dart
14
star
93

timing

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

package_config

Support for working with Package Resolution Configuration files
Dart
14
star
95

root_certificates

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

test_descriptor

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

dartlang_project_templates

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

source_map_stack_trace

Convert stack traces generated by dart2js-compiled code into readable native Dart stack traces
Dart
7
star
99

.github

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

test_reflective_loader

Discover tests and test suites using reflection
Dart
5
star