From f2c2588c60dfd091fbf661501f4c3ce8874814f4 Mon Sep 17 00:00:00 2001 From: Qrius Date: Tue, 22 Apr 2025 08:27:08 +0200 Subject: Approach malleable system --- src/smp/builtins.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/smp/builtins.py') diff --git a/src/smp/builtins.py b/src/smp/builtins.py index afa153d..2fde231 100644 --- a/src/smp/builtins.py +++ b/src/smp/builtins.py @@ -201,7 +201,7 @@ def smp_builtin_read(macro_processor, filename, template_content=None): metadata = {} if macro_processor._get_macro_with_prefix("parse_file_yaml"): metadata, file_content = extract_parse_yaml_metadata(file_content) - smp_builtin_add_metadata(macro_processor, metadata, overwrite=False) + smp_builtin_add_metadata(macro_processor, metadata, overwrite=True) extension = os.path.splitext(filename)[1][1:] or "" macro_processor._define_macro_with_prefix("target_file_extension", extension) @@ -215,13 +215,22 @@ def smp_builtin_read(macro_processor, filename, template_content=None): if extension == "md": content = smp_builtin_html_from_markdown(macro_processor, content) - if (template := macro_processor.macros.get("METADATA_template")) is not None: + if (template := macro_processor._get_metadata("template")) is not None: if template not in macro_processor._get_macro_with_prefix("template_stack"): return smp_builtin_read(macro_processor, template, content) return content +def smp_builtin_indent(macro_processor, indent: int, content: str): + indent = int(indent) + content = macro_processor.process_input(content) + return "\n".join( + f"{' ' * (indent if i > 0 else 0)}{x}" + for i, x in enumerate(content.split("\n")) + ) + + 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", {}) -- cgit v1.2.3