nixdoc
Parser for Nixdoc documentation comments implementing the RFC 145 format for
documenting Nix library functions. While the Nixdoc format is not enforced by
any tooling, it is somewhat widely adopted and is treated as a formal
specification. Nixdoc uses /** … */ doc comments containing Markdown with
structured sections introduced by level-1 headings (# Section). This crate, in
turn, parses that format into a typed DocComment structure, extracting the
description, type signature, arguments, examples, and any other sections.
Installation
Nixdoc is officially published on https://crates.io. You may install it by adding it to your Cargo manifest with the latest version:
[]
= "0.1"
Usage
Quick Start
use DocComment;
// Simple one-liner:
let doc = parse.unwrap;
assert_eq!;
assert!;
use DocComment;
// Multi-section comment:
let doc = parse.unwrap;
assert_eq!;
let args = doc.arguments;
assert_eq!;
assert_eq!;
assert_eq!;
Comment format
A Nixdoc comment starts with /** and ends with */. Content is indented
(typically by two spaces) and the indentation is automatically stripped.
Sections are introduced by level-1 Markdown headings (# Section). The section
body is Markdown text and may contain fenced code blocks.
Recognised section headings (case-insensitive):
TypeArguments/ArgsExample/ExamplesNote/NotesWarning/Warnings/CautionDeprecated
Development
# Run with Nix flake
# Run tests
License
This project is made available under Mozilla Public License (MPL) version 2.0. See LICENSE for more details on the exact conditions. An online copy is provided here.
Attributions
This project is greatly inspired by noogle's Pesto module. While pesto is a
CLI and prefers to consume the rnix parser, nixdoc is completely standalone
and is designed as a library with the integration and extraction left to the
user.