From 0474b0f2d479075fbfa9507dc4aea19bec4eba01 Mon Sep 17 00:00:00 2001 From: Adrien Brignon Date: Sat, 27 May 2023 19:58:10 +0200 Subject: [PATCH] fix: explicit encodings when using open --- mkdocs_exporter/plugin.py | 4 ++-- mkdocs_exporter/plugins/pdf/plugin.py | 4 ++-- mkdocs_exporter/plugins/pdf/renderer.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mkdocs_exporter/plugin.py b/mkdocs_exporter/plugin.py index 4f24931..0595704 100644 --- a/mkdocs_exporter/plugin.py +++ b/mkdocs_exporter/plugin.py @@ -64,7 +64,7 @@ def on_post_build(self, **kwargs) -> None: for file in self.files: css = None - with open(file.abs_dest_path, 'r') as reader: + with open(file.abs_dest_path, 'r', encoding='utf-8') as reader: css = self.theme.stylesheet(reader.read()) - with open(file.abs_dest_path, 'w+') as writer: + with open(file.abs_dest_path, 'w+', encoding='utf-8') as writer: writer.write(css) diff --git a/mkdocs_exporter/plugins/pdf/plugin.py b/mkdocs_exporter/plugins/pdf/plugin.py index e4a4fb0..24e3a00 100644 --- a/mkdocs_exporter/plugins/pdf/plugin.py +++ b/mkdocs_exporter/plugins/pdf/plugin.py @@ -53,10 +53,10 @@ def on_page_markdown(self, markdown: str, page: Page, config: Config, **kwargs) covers = {**self.config.covers, **{k: os.path.join(os.path.dirname(config['config_file_path']), v) for k, v in page.meta.get('covers', {}).items()}} if covers.get('front'): - with open(covers['front'], 'r') as file: + with open(covers['front'], 'r', encoding='utf-8') as file: content = self.renderer.cover(file.read()) + content if covers.get('back'): - with open(covers['back'], 'r') as file: + with open(covers['back'], 'r', encoding='utf-8') as file: content = content + self.renderer.cover(file.read()) for path in [path for path in covers.values() if path is not None]: diff --git a/mkdocs_exporter/plugins/pdf/renderer.py b/mkdocs_exporter/plugins/pdf/renderer.py index 80e8b0b..4c4c535 100644 --- a/mkdocs_exporter/plugins/pdf/renderer.py +++ b/mkdocs_exporter/plugins/pdf/renderer.py @@ -62,10 +62,10 @@ async def render(self, page: Page) -> bytes: page.theme.preprocess(preprocessor) for stylesheet in self.stylesheets: - with open(stylesheet, 'r') as file: + with open(stylesheet, 'r', encoding='utf-8') as file: preprocessor.stylesheet(file.read()) for script in self.scripts: - with open(script, 'r') as file: + with open(script, 'r', encoding='utf-8') as file: preprocessor.script(file.read()) preprocessor.script(importlib_resources.files(js).joinpath('pagedjs.min.js').read_text())