Skip to content

Commit 5c46cd8

Browse files
committed
fix: enhance Liquid syntax handling in fix-docs.sh script
- Updated the script to HTML-encode Liquid tags within code blocks while preserving original content outside of them. - Improved the logic for detecting code blocks to ensure accurate processing of Liquid syntax.
1 parent 00a8caa commit 5c46cd8

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

.github/scripts/docs/fix-docs.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,35 @@ for dir in code-based configuration-based; do
1515
echo " Creating lowercase copy: $lowercase"
1616
cp "$file" "$lowercase"
1717

18-
# Fix the Liquid templates in both files
18+
# Fix the Liquid templates in both files using HTML entities
1919
for target in "$file" "$lowercase"; do
2020
# Create a temporary file
2121
temp_file="${target}.tmp"
2222
> "$temp_file" # Create empty file
2323

24-
# Process line by line to properly wrap Liquid tags
24+
# Process line by line to HTML-encode Liquid tags
25+
in_code_block=false
2526
while IFS= read -r line; do
26-
if [[ "$line" == *"{{"*"}}"* ]]; then
27-
# Line contains Liquid syntax, wrap it
28-
echo "{% raw %}${line}{% endraw %}" >> "$temp_file"
27+
# Check if line starts/ends a code block
28+
if [[ "$line" =~ ^\`\`\`.* ]]; then
29+
in_code_block=!$in_code_block
30+
echo "$line" >> "$temp_file"
31+
continue
32+
fi
33+
34+
if $in_code_block; then
35+
# Inside code blocks, replace Liquid syntax with HTML entities
36+
# Replace {{ with {{
37+
line=$(echo "$line" | sed 's/{{\|{{/\{\{/g')
38+
# Replace }} with }}
39+
line=$(echo "$line" | sed 's/}}\|}}/\}\}/g')
40+
# Replace {% with {%
41+
line=$(echo "$line" | sed 's/{%\|{%/\{%/g')
42+
# Replace %} with %}
43+
line=$(echo "$line" | sed 's/%}\|%}/\%\}/g')
44+
echo "$line" >> "$temp_file"
2945
else
30-
# No Liquid syntax, keep as is
46+
# Outside code blocks, no encoding (use backticks for inline code)
3147
echo "$line" >> "$temp_file"
3248
fi
3349
done < "$target"

0 commit comments

Comments
 (0)