Filename as title for untitled pages, title attr. adition, add TXT input pages + file formats fixes

This commit is contained in:
2022-08-14 17:35:58 +02:00
parent 1faf0014be
commit be37e2d845
7 changed files with 69 additions and 40 deletions

View File

@ -32,7 +32,7 @@ def StripAttrs(HTML):
t.attrs = {}
return str(Soup)
def StripTags(HTML, ToStrip):
def StripTags(HTML, ToStrip): # Remove desired tags from the HTML
Soup = MkSoup(HTML)
Tags = Soup.find_all()
for t in Tags:
@ -40,6 +40,14 @@ def StripTags(HTML, ToStrip):
t.replace_with('')
return str(Soup)
def ImgAltToTitle(HTML): # Adds title attr. to <img> which don't have it, but have alt text
Soup = MkSoup(HTML)
Tags = Soup.find_all('img')
for t in Tags:
if 'alt' in t.attrs and 'title' not in t.attrs:
t.attrs.update({'title': t.attrs['alt']})
return str(Soup)
def AddToTagStartEnd(HTML, MatchStart, MatchEnd, AddStart, AddEnd): # This doesn't handle nested tags
StartPos = None
for i,e in enumerate(HTML):