Add alt text as title text... for the single image on my entire site

This commit is contained in:
askiiart 2024-03-12 20:45:03 -05:00
parent d47156ebba
commit ebbd2bef19
Signed by untrusted user who does not match committer: askiiart
GPG key ID: BC3800E55FB54D67
6 changed files with 19 additions and 4 deletions

14
regex-chicanery.py Normal file
View file

@ -0,0 +1,14 @@
#!/usr/bin/env python3
import re
import sys
# add title attribute to img tags
filename = sys.argv[1]
with open(filename, 'r+') as f:
contents = ''.join(f.readlines())
regexp = re.compile('alt="(.*?)"')
for match in regexp.finditer(contents):
contents = contents.replace(match.group(0), f'title="{match.group(1)}" {match.group(0)}')
with open(filename, 'wt') as f:
f.write(contents)