From 37ad8cd3fc11e0e2678ea3a30374d09e1198e549 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sat, 24 Feb 2024 15:11:43 +0700 Subject: [PATCH] Apply some suggestions Co-authored-by: Silvan Mosberger --- doc/migration.md | 3 +- src/format.rs | 10 ++---- src/snapshots/nixdoc__test__doc_comment.snap | 3 -- src/snapshots/nixdoc__test__headings.snap | 8 ++--- test.nix | 37 -------------------- test/headings.md | 12 +++---- 6 files changed, 14 insertions(+), 59 deletions(-) delete mode 100644 test.nix diff --git a/doc/migration.md b/doc/migration.md index 4293737..257e40e 100644 --- a/doc/migration.md +++ b/doc/migration.md @@ -97,8 +97,7 @@ If arguments require more complex documentation consider starting an extra secti # Arguments - ## **x** - + ## **x** (Any) (...Some comprehensive documentation) */ diff --git a/src/format.rs b/src/format.rs index 6d9efff..9ccb028 100644 --- a/src/format.rs +++ b/src/format.rs @@ -64,11 +64,11 @@ pub fn handle_indentation(raw: &str) -> Option { /// pub fn shift_headings(raw: &str, levels: usize) -> String { let mut result = String::new(); - for line in raw.lines() { + for line in raw.split_inclusive('\n') { if line.trim_start().starts_with('#') { - result.push_str(&format!("{}\n", &handle_heading(line, levels))); + result.push_str(&handle_heading(line, levels)); } else { - result.push_str(&format!("{line}\n")); + result.push_str(line); } } result @@ -83,10 +83,6 @@ pub fn handle_heading(line: &str, levels: usize) -> String { let mut rest = String::new(); for char in chars { match char { - // ' ' | '\t' if hashes.is_empty() => { - // // only collect trivial before the initial hash - // leading_trivials.push(char) - // } '#' if rest.is_empty() => { // only collect hashes if no other tokens hashes.push(char) diff --git a/src/snapshots/nixdoc__test__doc_comment.snap b/src/snapshots/nixdoc__test__doc_comment.snap index 23ce5c9..c69cec1 100644 --- a/src/snapshots/nixdoc__test__doc_comment.snap +++ b/src/snapshots/nixdoc__test__doc_comment.snap @@ -20,7 +20,6 @@ This is a parsed example doc comment in markdown format - ## `lib.debug.argumentTest` {#function-library-lib.debug.argumentTest} doc comment in markdown format @@ -33,7 +32,6 @@ Type: (Should NOT be a heading) This is just markdown - structured function argument : `formal1` @@ -60,4 +58,3 @@ structured function argument Comment - diff --git a/src/snapshots/nixdoc__test__headings.snap b/src/snapshots/nixdoc__test__headings.snap index f38195e..78deea6 100644 --- a/src/snapshots/nixdoc__test__headings.snap +++ b/src/snapshots/nixdoc__test__headings.snap @@ -8,15 +8,15 @@ expression: output ##### h3-heading -##### h4-heading +###### h4-heading -Should be h6 +This should be h6 ###### h5-heading -This should be h6 +This should be h6 as well ###### h6-heading -This should be h6 +This should be h6 as well diff --git a/test.nix b/test.nix deleted file mode 100644 index 3a2310e..0000000 --- a/test.nix +++ /dev/null @@ -1,37 +0,0 @@ -/** -Prequel -*/ -{lib}: -{ - - /** - Create a file set from a path that may or may not exist - */ - packagesFromDirectoryRecursive = - # Options. - { - /** - rfc style - - ``` - Path -> AttrSet -> a - ``` - */ - callPackage, - /* - legacy multiline - - ``` - Path - ``` - */ - directory, - # legacy single line - config, - # legacy - # block - # comment - moreConfig, - }: - 1; -} \ No newline at end of file diff --git a/test/headings.md b/test/headings.md index f79eedb..bad1393 100644 --- a/test/headings.md +++ b/test/headings.md @@ -4,14 +4,14 @@ ### h3-heading -### h4-heading +#### h4-heading -Should be h6 +This should be h6 -#### h5-heading +##### h5-heading -This should be h6 +This should be h6 as well -##### h6-heading +###### h6-heading -This should be h6 +This should be h6 as well