From a7cbe47b65e291a5fea5c8436f0b99bcbe670229 Mon Sep 17 00:00:00 2001 From: Maxime Gross Date: Fri, 16 Aug 2024 09:13:30 +0200 Subject: [PATCH] Set markdown parser instance as private --- staticjinjaplus/staticjinja_helpers.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/staticjinjaplus/staticjinja_helpers.py b/staticjinjaplus/staticjinja_helpers.py index e5df7c8..6c4e5a1 100644 --- a/staticjinjaplus/staticjinja_helpers.py +++ b/staticjinjaplus/staticjinja_helpers.py @@ -13,7 +13,7 @@ class MarkdownWithMetadata(Markdown): Meta: Dict[str, Any] -markdown_instance: Optional[MarkdownWithMetadata] = None +_markdown_instance: Optional[MarkdownWithMetadata] = None def minify_xml(out: str, site: Site, template_name: str, **kwargs) -> None: @@ -55,10 +55,10 @@ def minify_json_template(site: Site, template: Template, **kwargs) -> None: def convert_markdown_file(template: Template) -> Dict: """Parse and convert a Markdown file to HTML and return the result, as well as metadata if any, to be used in the current context""" - global markdown_instance + global _markdown_instance # Use a single Markdown parser instance for performance reasons - if not markdown_instance: + if not _markdown_instance: extension_configs = { 'markdown.extensions.extra': {}, 'markdown.extensions.meta': {}, @@ -71,13 +71,13 @@ def convert_markdown_file(template: Template) -> Dict: e for e in extension_configs.keys() ] - markdown_instance = MarkdownWithMetadata( + _markdown_instance = MarkdownWithMetadata( extensions=extensions, extension_configs=extension_configs, output_format='html5' ) else: # Reset the Markdown parser state before reusing it - markdown_instance.reset() + _markdown_instance.reset() with open(path.join(config['TEMPLATES_DIR'], template.name), 'r', encoding='utf-8') as f: filename = path.normpath(template.name).replace('\\', '/') @@ -85,11 +85,11 @@ def convert_markdown_file(template: Template) -> Dict: return { 'markdown': { - 'converted': Markup(markdown_instance.convert(f.read())), + 'converted': Markup(_markdown_instance.convert(f.read())), 'source': filename, 'url': url, 'meta': { - k: '\n'.join(v) for k, v in markdown_instance.Meta.items() + k: '\n'.join(v) for k, v in _markdown_instance.Meta.items() } } }