Set image width if it exists

main
Bob Mottram 2020-10-11 11:10:19 +01:00
parent e13cec3bbc
commit caafb4648c
2 changed files with 16 additions and 1 deletions

View File

@ -31,6 +31,20 @@ def removeHtmlTag(htmlStr: str, tag: str) -> str:
return htmlStr return htmlStr
def setHtmlTag(htmlStr: str, tag: str, value: str) -> str:
"""Removes a given tag from a html string
"""
matchStr = ' ' + tag + '="'
if matchStr not in htmlStr:
return htmlStr
sections = htmlStr.split(matchStr, 1)
if '"' not in sections[1]:
return htmlStr
htmlStr = sections[0] + matchStr + value + '"' + \
sections[1].split('"', 1)[1]
return htmlStr
def removeQuotesWithinQuotes(content: str) -> str: def removeQuotesWithinQuotes(content: str) -> str:
"""Removes any blockquote inside blockquote """Removes any blockquote inside blockquote
""" """

View File

@ -12,6 +12,7 @@ import datetime
from collections import OrderedDict from collections import OrderedDict
from newswire import getDictFromNewswire from newswire import getDictFromNewswire
from posts import createNewsPost from posts import createNewsPost
from content import setHtmlTag
from content import removeHtmlTag from content import removeHtmlTag
from content import dangerousMarkup from content import dangerousMarkup
from utils import loadJson from utils import loadJson
@ -134,7 +135,7 @@ def convertRSStoActivityPub(baseDir: str, httpPrefix: str,
# remove image dimensions # remove image dimensions
if '<img' in rssDescription: if '<img' in rssDescription:
rssDescription = removeHtmlTag(rssDescription, 'width') rssDescription = setHtmlTag(rssDescription, 'width', '10vw')
rssDescription = removeHtmlTag(rssDescription, 'height') rssDescription = removeHtmlTag(rssDescription, 'height')
followersOnly = False followersOnly = False