#!/bin/bash

for file in *.md; do
  perl -0777 -i -pe '
    s/\r\n/\n/g;              # Normalize Windows line endings to Unix
    s/(?:[ \t]*\n){2,}/\n\n/g;  # Collapse multiple blank lines (even with whitespace)
  ' "$file"
done

echo "Collapsed extra blank lines."