#!/usr/bin/env bash
set -euo pipefail

# Directory containing your HTML files (defaults to current directory)
TARGET_DIR="${1:-.}"

# Normalize [MM:SS.mmm --> ...] to [00:MM:SS.mmm --> ...] in all .htm files
# (Supports both "-->" and "--&gt;", and creates .bak backup files)
find "$TARGET_DIR" -type f \( -name "*.htm" \) -exec perl -i.bak -pe '
  s{\[(\d{2}:)?(\d{2}:\d{2}\.\d{3})(\s+(?:-->|--&gt;)\s+)(\d{2}:)?(\d{2}:\d{2}\.\d{3})\]}{
    "[" . (defined $1 ? $1 : "00:") . $2 . $3 . (defined $4 ? $4 : "00:") . $5 . "]"
  }ge;
' {} +

echo "Done! Backups saved with .bak extension."
