From 29bf4969e288774d04a7a0b5b7c4b412518a226b Mon Sep 17 00:00:00 2001 From: Leonardo Cavaletti Date: Sat, 15 Aug 2020 13:29:47 +0100 Subject: [PATCH] Added support for emoji spreadsheets --- loconotion/notionparser.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/loconotion/notionparser.py b/loconotion/notionparser.py index c7fcb5f..974bcd7 100644 --- a/loconotion/notionparser.py +++ b/loconotion/notionparser.py @@ -352,7 +352,7 @@ class Parser: log.debug(f"Adding meta tag {str(tag)}") soup.head.append(tag) - # process images + # process images & emojis cache_images = True for img in soup.findAll("img"): if img.has_attr("src"): @@ -372,6 +372,21 @@ class Parser: if img["src"].startswith("/"): 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 for link in soup.findAll("link", rel="stylesheet"): if link.has_attr("href") and link["href"].startswith("/"):