Updated auto-doc formatting for markdown files
All checks were successful
CI/CD Pipeline / test (pull_request) Successful in 37s
CI/CD Pipeline / build (pull_request) Has been skipped
CI/CD Pipeline / release (pull_request) Has been skipped

This commit is contained in:
2026-01-01 02:43:07 -07:00
parent 397aa47217
commit 9fd3a55182
4 changed files with 84 additions and 33 deletions

View File

@@ -1,4 +1,5 @@
use crc32fast::hash as crc32_hash;
/// This function takes an input which is meant to be hashed via the CRC32 algorithm, but it then
/// converts the generated UNSIGNED number into it's SIGNED counterpart.
pub fn crc_hash_signed(input: &str) -> i128 {
@@ -9,3 +10,38 @@ pub fn crc_hash_signed(input: &str) -> i128 {
hash_value_i32 as i128
}
/// Removes common leading whitespace from all lines in a string (dedent).
/// This is useful for cleaning up documentation strings that have uniform indentation.
pub fn dedent(text: &str) -> String {
let lines: Vec<&str> = text.lines().collect();
// Find minimum indentation (excluding empty lines)
let mut min_indent = usize::MAX;
for line in &lines {
if !line.trim().is_empty() {
let indent = line.len() - line.trim_start().len();
min_indent = min_indent.min(indent);
}
}
// If no lines or all empty, return as-is
if min_indent == usize::MAX {
return text.to_string();
}
// Remove the common indentation
lines
.iter()
.map(|line| {
if line.trim().is_empty() {
""
} else if line.len() >= min_indent {
&line[min_indent..]
} else {
line
}
})
.collect::<Vec<_>>()
.join("\n")
}

View File

@@ -1,4 +1,5 @@
mod helper_funcs;
pub use helper_funcs::dedent;
mod macros;
mod syscall;

View File

@@ -99,12 +99,12 @@ macro_rules! documented {
),*
];
doc_lines.iter()
let combined = doc_lines.iter()
.filter_map(|&d| d)
.collect::<Vec<_>>()
.join("\n")
.trim()
.to_string()
.join("\n");
$crate::dedent(&combined).trim().to_string()
}
)*
}
@@ -122,12 +122,13 @@ macro_rules! documented {
documented!(@doc_filter #[ $($variant_attr)* ])
),*
];
doc_lines.iter()
let combined = doc_lines.iter()
.filter_map(|&d| d)
.collect::<Vec<_>>()
.join("\n")
.trim()
.to_string()
.join("\n");
$crate::dedent(&combined).trim().to_string()
}
)
),*
@@ -136,4 +137,3 @@ macro_rules! documented {
}
};
}