secretumvault/scripts/fix-markdown-errors.nu
2026-01-11 23:12:38 +00:00

183 lines
5.0 KiB
Plaintext
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env nu
# Fix markdown linting errors in secretumvault
def main [] {
print "🔧 Fixing markdown errors in secretumvault...\n"
# Fix malformed closing fences
print "1. Fixing malformed closing code fences..."
fix_malformed_closing_fences
# Fix MD040 - Add language to code fences
print "2. Fixing MD040 (code blocks missing language)..."
fix_md040
# Fix MD060 - Table formatting
print "3. Fixing MD060 (table formatting)..."
fix_md060
# Fix MD034 - Bare URLs
print "4. Fixing MD034 (bare URLs)..."
fix_md034
# Fix MD026 - Trailing punctuation in headings
print "5. Fixing MD026 (trailing punctuation in headings)..."
fix_md026
# Fix MD013 - Line length
print "6. Fixing MD013 (line length)..."
fix_md013
# Fix MD033 - Inline HTML
print "7. Fixing MD033 (inline HTML)..."
fix_md033
# Fix MD047 - Single trailing newline
print "8. Fixing MD047 (single trailing newline)..."
fix_md047
print "\n✅ All fixes applied. Run markdownlint-cli2 to verify."
}
# Fix malformed closing fences - Remove language specifiers from closing code fences
def fix_malformed_closing_fences [] {
# Use bash with find to process all markdown files with perl
# This is more reliable than trying to loop through files in Nushell
bash -c 'find . -name "*.md" -not -path "*/.git/*" -not -path "*/target/*" -not -path "*/.coder/*" -not -path "*/.claude/*" -not -path "*/.wrks/*" -exec perl -i.bak -f /tmp/fix_fences.pl {} \; -exec rm -f {}.bak \;'
print " ✓ Malformed closing fences fixed"
}
# Fix MD040 - Add 'text' language to bare code fences
def fix_md040 [] {
let files = [
"assets/branding/brand-guidelines.md"
"assets/branding/README.md"
"docs/architecture/complete-architecture.md"
"docs/architecture/overview.md"
"docs/user-guide/configuration.md"
"README.md"
]
for file in $files {
if ($file | path exists) {
sed -i.bak 's/^```$/```text/' $file
rm -f $"($file).bak"
}
}
}
# Fix MD060 - Table formatting (add spaces around pipes)
def fix_md060 [] {
let files = (glob **/*.md
| where {|f| not ($f | str contains ".git") }
| where {|f| not ($f | str contains "target") }
| where {|f| not ($f | str contains ".coder") }
)
for file in $files {
# Read file
let content = (open $file)
# Fix compact table style (missing spaces)
# Pattern: |word| → | word |
let fixed = ($content
| str replace --all --regex '\|([^\s\|][^\|]*[^\s\|])\|' '| $1 |'
| str replace --all --regex '\|([^\s\|])\|' '| $1 |'
)
$fixed | save -f $file
}
}
# Fix MD034 - Bare URLs (wrap in angle brackets)
def fix_md034 [] {
let file = ".woodpecker/README.md"
if ($file | path exists) {
sed -i.bak 's|https://your-woodpecker\.instance|<https://your-woodpecker.instance>|' $file
rm -f $"($file).bak"
}
}
# Fix MD026 - Remove trailing punctuation from headings
def fix_md026 [] {
let files = [
".typedialog/ci/README.md"
"CONTRIBUTING.md"
"SECURITY.md"
"docs/architecture/complete-architecture.md"
]
for file in $files {
if ($file | path exists) {
# Remove ? from headings
sed -i.bak 's/^\(#\+.*\)\?$/\1/' $file
rm -f $"($file).bak"
}
}
}
# Fix MD013 - Line length (break long lines)
def fix_md013 [] {
# These require manual review - just note them
print " ⚠️ Line length issues require manual review:"
print " - CODE_OF_CONDUCT.md:5, 47"
print " - CONTRIBUTING.md:7"
print " - README.md:9"
print " - assets/branding/brand-guidelines.md:9, 436, 450"
}
# Fix MD033 - Inline HTML
def fix_md033 [] {
# These are intentional HTML (div for centering) - update config
print " Inline HTML is intentional (centering divs) - updating config..."
let config_file = ".markdownlint-cli2.jsonc"
if ($config_file | path exists) {
# Add 'div' to allowed_elements
let content = (open $config_file)
let updated = ($content | str replace
'"allowed_elements": ["br", "hr", "details", "summary", "p", "img"]'
'"allowed_elements": ["br", "hr", "details", "summary", "p", "img", "div"]'
)
$updated | save -f $config_file
}
}
# Fix MD047 - Single trailing newline
def fix_md047 [] {
let md_files = [
"CODE_OF_CONDUCT.md"
"CONTRIBUTING.md"
"README.md"
"SECURITY.md"
"docs/architecture/complete-architecture.md"
"docs/architecture/overview.md"
"docs/architecture/README.md"
"docs/development/build-features.md"
"docs/development/features-control.md"
"docs/development/pqc-support.md"
"docs/development/README.md"
"docs/index.md"
"docs/operations/deployment.md"
"docs/operations/README.md"
"docs/README.md"
"docs/user-guide/configuration.md"
"docs/user-guide/howto.md"
"docs/user-guide/README.md"
]
for file in $md_files {
if ($file | path exists) {
let content = (open $file)
# Ensure file ends with exactly one newline
let fixed = ($content | str trim -r) + "\n"
$fixed | save -f $file
}
}
print " ✓ Single trailing newlines fixed"
}