-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
explain.sh
executable file
·83 lines (72 loc) · 2.2 KB
/
explain.sh
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
75
76
77
78
79
80
81
82
83
#!/bin/bash
# Check if a directory is provided as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <directory>"
exit 1
fi
# Read the directory
DIR=$1
# Check if the directory exists
if [ ! -d "$DIR" ]; then
echo "Directory not found!"
exit 1
fi
# Check if README.md exists in the directory
FILE="$DIR/README.md"
if [ ! -f "$FILE" ]; then
echo "README.md not found in the directory!"
exit 1
fi
# Function to process Markdown
process_markdown() {
while IFS= read -r line; do
if [[ "$in_code_block" == "true" ]]; then
# Process code block content
if [[ "$line" =~ ^\`\`\` ]]; then
in_code_block=false
echo -e "\033[0m"
else
echo -e "\033[7m$line\033[0m"
fi
else
# Process headers
if [[ "$line" =~ ^\#{1,6}\ ]]; then
level=$(echo "$line" | grep -o '^#*' | wc -c)
level=$((level - 1))
line=$(echo "$line" | sed 's/^#* //')
case $level in
1) echo -e "\033[1;34m$line\033[0m" ;; # Header 1 (blue)
2) echo -e "\033[1;32m$line\033[0m" ;; # Header 2 (green)
3) echo -e "\033[1;36m$line\033[0m" ;; # Header 3 (cyan)
4) echo -e "\033[1;35m$line\033[0m" ;; # Header 4 (magenta)
5) echo -e "\033[1;33m$line\033[0m" ;; # Header 5 (yellow)
6) echo -e "\033[1;31m$line\033[0m" ;; # Header 6 (red)
esac
# Process bold
elif [[ "$line" =~ \*\* ]]; then
line=$(echo "$line" | sed -e 's/\*\*\([^\*]*\)\*\*/\x1B[1m\1\x1B[0m/g')
echo -e "$line"
# Process italics
elif [[ "$line" =~ \* ]]; then
line=$(echo "$line" | sed -e 's/\*\([^\*]*\)\*/\x1B[3m\1\x1B[0m/g')
echo -e "$line"
# Process code blocks
elif [[ "$line" =~ ^\`\`\` ]]; then
if [ "$in_code_block" == "true" ]; then
in_code_block=false
else
in_code_block=true
fi
elif [ "$in_code_block" == "true" ]; then
echo -e "\e[7m$line\e[0m"
# Default case, just print the line
else
echo "$line"
fi
fi
done < "$FILE"
}
# Initial state
in_code_block=false
# Process the README.md file
process_markdown