diff options
Diffstat (limited to 'src/smp/builtins.py')
-rw-r--r-- | src/smp/builtins.py | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/smp/builtins.py b/src/smp/builtins.py index eae32ce..f9d6468 100644 --- a/src/smp/builtins.py +++ b/src/smp/builtins.py @@ -75,10 +75,9 @@ def _smp_builtin_add_metadata( Not added to macro_processor as macro """ for macro_name, value in metadata.items(): - if not macro_name.startswith( - macro_processor._get_macro_with_prefix("metadata_prefix") - ): - macro_name = f"{macro_processor._get_macro_with_prefix('metadata_prefix')}{macro_name}" + prefix = macro_processor._get_macro_builtin("metadata_prefix") + if not macro_name.startswith(prefix): + macro_name = f"{prefix}{macro_name}" macro_value: str | list[str] = str(value) if isinstance(value, list): @@ -91,7 +90,7 @@ def _smp_builtin_add_metadata( macro_processor.define_macro(macro_name, macro_value) -def smp_builtin_include_file(macro_processor, filename): +def smp_builtin_include(macro_processor, filename): return _smp_builtin_read( macro_processor, filename, template_content=None, inline=True ) @@ -190,7 +189,7 @@ def smp_builtin_html_from_markdown(macro_processor, text, extensions=list()): def _smp_builtin_template_content(): def inner(macro_processor): - filename, content, extension = macro_processor._get_macro_with_prefix( + filename, content, extension = macro_processor._get_macro_builtin( "template_stack_content" ).pop() @@ -221,28 +220,28 @@ def _smp_builtin_read(macro_processor, filename, template_content=None, inline=F file_content = f.read() metadata = {} - if smp_builtin_iftruthy(macro_processor._get_macro_with_prefix("parse_file_yaml")): + if smp_builtin_iftruthy(macro_processor._get_macro_builtin("parse_file_yaml")): metadata, file_content = extract_parse_yaml_metadata(file_content) _smp_builtin_add_metadata(macro_processor, metadata, overwrite=True) extension = os.path.splitext(filename)[1][1:] or "" if not inline: - macro_processor._define_macro_with_prefix("target_file_extension", extension) + macro_processor._define_macro_builtin("target_file_extension", extension) if template_content is not None: - macro_processor._get_macro_with_prefix("template_stack").append(filename) + macro_processor._get_macro_builtin("template_stack").append(filename) macro_processor.macros["CONTENT"] = template_content content = file_content if (template := macro_processor._get_metadata("template")) is not None: - template_prefix = macro_processor._get_macro_with_prefix("template_prefix") + template_prefix = macro_processor._get_macro_builtin("template_prefix") if not os.path.exists(template): template = os.path.join(template_prefix, template) - if template not in macro_processor._get_macro_with_prefix("template_stack"): - macro_processor._get_macro_with_prefix("template_stack_content").append( + if template not in macro_processor._get_macro_builtin("template_stack"): + macro_processor._get_macro_builtin("template_stack_content").append( (filename, content, extension) ) return _smp_builtin_read( @@ -264,9 +263,9 @@ def smp_builtin_indent(macro_processor, indent: int, content: str): def smp_builtin_wodl(macro_processor, link, timeout_seconds=5): - if (macro_processor._get_macro_with_prefix("wodl_cache")) is None: - macro_processor._define_macro_with_prefix("wodl_cache", {}) - cache = macro_processor._get_macro_with_prefix("wodl_cache") + if (macro_processor._get_macro_builtin("wodl_cache")) is None: + macro_processor._define_macro_builtin("wodl_cache", {}) + cache = macro_processor._get_macro_builtin("wodl_cache") url = urllib.parse.urlparse(link) @@ -292,14 +291,14 @@ def smp_builtin_wodl(macro_processor, link, timeout_seconds=5): def smp_builtin_expand_once(macro_processor, content): - if (cache := macro_processor._get_macro_with_prefix("once_cache")) is not None: + if (cache := macro_processor._get_macro_builtin("once_cache")) is not None: if (exp := cache.get(content)) is not None: return exp else: - macro_processor._define_macro_with_prefix("once_cache", {}) + macro_processor._define_macro_builtin("once_cache", {}) expanded_content = macro_processor.process_input(content) - macro_processor._get_macro_with_prefix("once_cache", expanded_content) + macro_processor._get_macro_builtin("once_cache", expanded_content) return expanded_content |