Added support for emoji spreadsheets

This commit is contained in:
Leonardo Cavaletti 2020-08-15 13:29:47 +01:00
parent 73c21cc607
commit 29bf4969e2

View File

@ -352,7 +352,7 @@ class Parser:
log.debug(f"Adding meta tag {str(tag)}") log.debug(f"Adding meta tag {str(tag)}")
soup.head.append(tag) soup.head.append(tag)
# process images # process images & emojis
cache_images = True cache_images = True
for img in soup.findAll("img"): for img in soup.findAll("img"):
if img.has_attr("src"): if img.has_attr("src"):
@ -372,6 +372,21 @@ class Parser:
if img["src"].startswith("/"): if img["src"].startswith("/"):
img["src"] = "https://www.notion.so" + img["src"] img["src"] = "https://www.notion.so" + img["src"]
# on emoji images, cache their sprite sheet and re-set their background url
if img.has_attr("class") and "notion-emoji" in img["class"]:
style = cssutils.parseStyle(img["style"])
spritesheet = style["background"]
spritesheet_url = spritesheet[
spritesheet.find("(") + 1 : spritesheet.find(")")
]
cached_spritesheet_url = self.cache_file(
"https://www.notion.so" + spritesheet_url
)
style["background"] = spritesheet.replace(
spritesheet_url, str(cached_spritesheet_url)
)
img["style"] = style.cssText
# process stylesheets # process stylesheets
for link in soup.findAll("link", rel="stylesheet"): for link in soup.findAll("link", rel="stylesheet"):
if link.has_attr("href") and link["href"].startswith("/"): if link.has_attr("href") and link["href"].startswith("/"):