-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-markdown-formatting.sh
More file actions
executable file
·74 lines (64 loc) · 2.16 KB
/
fix-markdown-formatting.sh
File metadata and controls
executable file
·74 lines (64 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Script to fix consecutive double-asterisk lines in markdown files
# Inserts blank lines between them to prevent line merging
#
# Usage: Run from anywhere in the repository
# ./scripts/fix-markdown-formatting.sh
set -euo pipefail
# Get the repository root directory (parent of the scripts directory)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(dirname "$SCRIPT_DIR")"
cd "$REPO_DIR"
# Find all .md files and check for consecutive ** lines
echo "Scanning for markdown files with consecutive ** lines..."
echo ""
found_issues=false
while IFS= read -r file; do
# Use awk to find consecutive lines starting with **
if awk '
BEGIN { prev_is_double_star = 0; found = 0 }
/^\*\*/ {
if (prev_is_double_star) {
found = 1
exit 0
}
prev_is_double_star = 1
}
!/^\*\*/ {
prev_is_double_star = 0
}
END { exit !found }
' "$file"; then
echo "Found issue in: $file"
found_issues=true
# Create backup
cp "$file" "$file.bak"
# Fix the file: insert blank line before ** if previous line also starts with **
awk '
BEGIN { prev_line = "" }
{
current_line = $0
# If current line starts with ** and previous line starts with **
if (current_line ~ /^\*\*/ && prev_line ~ /^\*\*/) {
# Insert blank line before current line
print ""
}
print current_line
prev_line = current_line
}
' "$file.bak" > "$file"
# Show what changed
echo " Fixed: inserted blank lines between consecutive ** lines"
echo ""
fi
done < <(find "$REPO_DIR" -name "*.md" -type f)
if [ "$found_issues" = false ]; then
echo "No issues found! All markdown files are properly formatted."
else
echo "---"
echo "Done! Modified files have been updated."
echo "Backups saved with .bak extension."
echo ""
echo "To remove backups after verifying:"
echo " find $REPO_DIR -name '*.md.bak' -delete"
fi