Browse Source

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.

master
Jan Černohorský 2 months ago
parent
commit
cd07b3abf8
  1. 17
      src/formatitko/images.py
  2. 2
      src/formatitko/util.py

17
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)

2
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)

Loading…
Cancel
Save