From cd07b3abf8152942c474c5125b7d502d4bedf6a9 Mon Sep 17 00:00:00 2001 From: Greenscreener Date: Thu, 22 Feb 2024 11:50:50 +0100 Subject: [PATCH] Creating of dirs in namespaces only when they're accessed (this is needed because until then, we don't know what $dir is. Also telling pandoc to strip comments. --- src/formatitko/images.py | 17 ++++++++++------- src/formatitko/util.py | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/formatitko/images.py b/src/formatitko/images.py index d7741f0..6dcf52e 100644 --- a/src/formatitko/images.py +++ b/src/formatitko/images.py @@ -38,11 +38,6 @@ class ImageProcessorNamespace: self.lookup_dirs = lookup_dirs self.web_path = web_path if web_path[-1] != "/" else web_path[:-1] self.include_src = include_src - if not os.path.exists(self.public_dir): - os.mkdir(self.public_dir) - if not os.path.exists(self.cache_dir): - os.mkdir(self.cache_dir) - class ImageProcessorSearcher: def get_lookup_dirs(self) -> list[str]: @@ -96,6 +91,8 @@ class ImageProcessorCacheSearcher(ImageProcessorSearcher): def __init__(self, cache_dir: str): self.cache_dir = cache_dir + if not os.path.exists(self.cache_dir): + os.makedirs(self.cache_dir, exist_ok=True) def get_lookup_dirs(self) -> list[str]: return [self.cache_dir] @@ -129,10 +126,16 @@ class ImageProcessorNamespaceSearcher(ImageProcessorSearcher): return path.replace("$dir", self.rel_dir) def get_cache_dir(self) -> str: - return self.transform_path(self.namespace.cache_dir) + cache_dir = self.transform_path(self.namespace.cache_dir) + if not os.path.exists(cache_dir): + os.makedirs(cache_dir, exist_ok=True) + return cache_dir def get_public_dir(self) -> str: - return self.transform_path(self.namespace.public_dir) + public_dir = self.transform_path(self.namespace.public_dir) + if not os.path.exists(public_dir): + os.makedirs(public_dir, exist_ok=True) + return public_dir def get_web_path(self) -> str: return self.transform_path(self.namespace.web_path) diff --git a/src/formatitko/util.py b/src/formatitko/util.py index f4eb6b4..0cf614b 100644 --- a/src/formatitko/util.py +++ b/src/formatitko/util.py @@ -37,7 +37,7 @@ def parse_string(s: str) -> list[Union[Str, Space]]: # we ever want to disable or enable some of panflute's markdown extensions, # this is the place to do it. def import_md(s: str, standalone: bool=True) -> Union[Doc, list[Element]]: - return convert_text(s, standalone=standalone, input_format="markdown-definition_lists-latex_macros") + return convert_text(s, standalone=standalone, input_format="markdown-definition_lists-latex_macros", extra_args=["--strip-comments"]) def import_md_list(s: str) -> list[Element]: return import_md(s, standalone=False)