Skip to content

Commit 5a469fe

Browse files
authored
Merge pull request #140 from roberth/minimal-output
feat: Minimal format
2 parents 470670d + b5b6b34 commit 5a469fe

File tree

6 files changed

+1629
-15
lines changed

6 files changed

+1629
-15
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## Upcoming release
4+
5+
Add `--anchor-prefix` to remove or customize the `function-library-` prefix.
6+
7+
A header won't be rendered when `--description` and `--category` are empty.
8+
This makes the generated markdown more flexible for inclusion in other documents.
9+
10+
## Version 3.0.8
11+
12+
Add `--json-output`, providing a JSON representation of the documentation.
13+
14+
Fix: attrsets in patterns are now skipped correctly.
15+
316
## Version 3.0.7
417

518
Add support for empty prefix flags.

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ The following is an example of markdown documentation for new and current users
6060

6161
> Note: Within nixpkgs the convention of using [definition-lists](https://www.markdownguide.org/extended-syntax/#definition-lists) for documenting arguments has been established.
6262
63+
## Usage
64+
65+
Refer to `nixdoc --help` for the most up-to-date usage information.
66+
67+
For a minimal format, suitable for inclusion into a dedicated documentation page, use:
68+
69+
```sh
70+
nixdoc --file lib.nix --category "" --description "" --prefix "" --anchor-prefix "" >lib.md
71+
```
6372

6473
## Custom nixdoc format (Legacy)
6574

src/commonmark.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,17 @@ impl ManualEntry {
158158
}
159159

160160
/// Write a single CommonMark entry for a documented Nix function.
161-
pub fn write_section(self, output: &mut String) -> String {
161+
///
162+
/// # Arguments
163+
///
164+
/// - `anchor_prefix`: The prefix to use for the anchor links.
165+
/// In Nixpkgs this would be "function-library-".
166+
/// - `output`: The output string to append the CommonMark onto.
167+
pub fn write_section(self, anchor_prefix: &str, output: &mut String) -> String {
162168
let (ident, title) = self.get_ident_title();
163169
output.push_str(&format!(
164-
"## `{}` {{#function-library-{}}}\n\n",
165-
title, ident
170+
"## `{}` {{#{}{}}}\n\n",
171+
title, anchor_prefix, ident
166172
));
167173

168174
// <subtitle> (type signature)
@@ -193,8 +199,8 @@ impl ManualEntry {
193199
// examples, how can this be achieved automatically?
194200
if let Some(example) = &self.example {
195201
output.push_str(&format!(
196-
"::: {{.example #function-library-example-{}}}\n",
197-
ident
202+
"::: {{.example #{}example-{}}}\n",
203+
anchor_prefix, ident
198204
));
199205
output.push_str(&format!("# `{}` usage example\n\n", title));
200206
output.push_str(&format!("```nix\n{}\n```\n:::\n\n", example.trim()));

src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ struct Options {
5555
#[arg(short, long, default_value_t = String::from("lib"))]
5656
prefix: String,
5757

58+
#[arg(long, default_value_t = String::from("function-library-"))]
59+
anchor_prefix: String,
60+
5861
/// Whether to output JSON.
5962
#[arg(short, long, default_value_t = false)]
6063
json_output: bool,
@@ -310,6 +313,9 @@ fn collect_entries(
310313
}
311314

312315
fn retrieve_description(nix: &rnix::Root, description: &str, category: &str) -> String {
316+
if description.is_empty() && category.is_empty() {
317+
return String::new();
318+
}
313319
format!(
314320
"# {} {{#sec-functions-library-{}}}\n{}\n",
315321
description,
@@ -351,7 +357,7 @@ fn main_with_options(opts: Options) -> String {
351357
let mut output = description + "\n";
352358

353359
for entry in entries {
354-
entry.write_section(&mut output);
360+
entry.write_section(opts.anchor_prefix.as_str(), &mut output);
355361
}
356362
output
357363
}

0 commit comments

Comments
 (0)