|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# Script to identify markdown files with severe HTML corruption |
| 4 | +# These files will be excluded from the build |
| 5 | + |
| 6 | +echo "🔍 Scanning for corrupted translation files..." >&2 |
| 7 | + |
| 8 | +# Array to store corrupted files (sh compatible) |
| 9 | +corrupted_files="" |
| 10 | + |
| 11 | +# Find all markdown files in translation directories (any 2-letter language code) |
| 12 | +find src -name "*.md" -type f 2>/dev/null | grep -E 'src/[a-z]{2}(-[A-Z]{2})?/' | while IFS= read -r file; do |
| 13 | + # Check for common corruption patterns |
| 14 | + has_error=false |
| 15 | + error_details="" |
| 16 | + |
| 17 | + # Pattern 1: Tags with numbers like </0>, </1> or <0>, <1>, including with spaces like </0 > |
| 18 | + if grep -qE '</?[0-9]+\s*>' "$file" 2>/dev/null || grep -qE '</\s*[0-9]+\s*>' "$file" 2>/dev/null; then |
| 19 | + has_error=true |
| 20 | + error_details="${error_details}numeric tag (<0>, </0>, </0 >, etc); " |
| 21 | + fi |
| 22 | + |
| 23 | + # Pattern 2: Unclosed code tags followed by table syntax |
| 24 | + if grep -q '<code>[^<]*`.*|' "$file" 2>/dev/null; then |
| 25 | + has_error=true |
| 26 | + error_details="${error_details}unclosed <code> with table syntax; " |
| 27 | + fi |
| 28 | + |
| 29 | + # Pattern 3: Mixing HTML table with markdown table syntax |
| 30 | + if grep -q '<table' "$file" 2>/dev/null && grep -q '<code>.*|.*|' "$file" 2>/dev/null; then |
| 31 | + has_error=true |
| 32 | + error_details="${error_details}mixed HTML/markdown table; " |
| 33 | + fi |
| 34 | + |
| 35 | + # Pattern 4: Orphaned closing paragraph tags or other malformed closing tags |
| 36 | + if grep -qE '^[^<]*</p>|</[0-9 ]+>' "$file" 2>/dev/null; then |
| 37 | + has_error=true |
| 38 | + error_details="${error_details}orphaned/malformed closing tag; " |
| 39 | + fi |
| 40 | + |
| 41 | + # Pattern 5: Opening tags with numbers |
| 42 | + if grep -qE '<[0-9]+[^>]*>' "$file" 2>/dev/null; then |
| 43 | + has_error=true |
| 44 | + error_details="${error_details}numeric opening tag; " |
| 45 | + fi |
| 46 | + |
| 47 | + if [ "$has_error" = true ]; then |
| 48 | + corrupted_files="$corrupted_files$file |
| 49 | +" |
| 50 | + echo " ⚠️ $file" >&2 |
| 51 | + echo " └─ Errors: $error_details" >&2 |
| 52 | + # Output to stdout for the build script to capture |
| 53 | + echo "$file" |
| 54 | + fi |
| 55 | +done |
0 commit comments