Snipdoc
Snipdoc is a straightforward tool for managing documentation that includes code snippets. It collects snippets from your code or YAML files and injects them into various parts of your documentation, making the documentation process more efficient.
Installation
Cargo install:
Or download from the GitHub Repository.
Getting started:
Collecting Snippets
To collect snippets, follow these steps:
- Identify the piece of content in your code that you want to grab.
- Wrap the snippet with the following tag:
// <snip id="SNIPPET_ID">
CONTENT HERE
// </snip>
- You can hide the snippet from presentation using various comment styles:
- In Markdown files (like readme.md), use HTML comments:
<!-- CONTENT HERE -->
- In Rust file docs, use:
//! CONTENT HERE
- In Rust function docs, use:
/// CONTENT HERE
- Use appropriate comment tags for other file formats.
- In Markdown files (like readme.md), use HTML comments:
Injecting Snippets
To inject snippets, create an empty placeholder with the snippet ID and add inject_from="code"
attribute like this:
<!-- <snip id="SNIPPET_ID" inject_from="code"> -->
CONTENT HERE
<!-- </snip> -->
After adding the placeholder, run the following command:
This command captures the SNIPPET_ID
and injects the snippet into the placeholder.
Managing Snippets
To manage all snippets effectively, run the following command:
For a live example, run the following command inside your project:
Managing Snippets in YAML
If you prefer managing snippets in a YAML file, follow these steps:
- Run the following command to create an empty
snipdoc.yml
file: - Add your snippets to
snipdoc.yml
, and use them by injecting from YAML (inject_from="code"
). For a live example, run the following command inside your project:
Check
validate that all snippets are valid and match the current injected versions. It is useful for incorporating into CI workflows to ensure documentation accuracy and consistency.