Add alt text as title text... for the single image on my entire site
This commit is contained in:
parent
d47156ebba
commit
ebbd2bef19
6 changed files with 19 additions and 4 deletions
14
regex-chicanery.py
Normal file
14
regex-chicanery.py
Normal 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)
|
Loading…
Add table
Add a link
Reference in a new issue