From 82df20d90a978535024cc2b8b87c7a2cfcfc1f7b Mon Sep 17 00:00:00 2001 From: Qrius Date: Thu, 24 Apr 2025 08:58:17 +0200 Subject: Add inline option to read macro, so we don't override target_file_extension with includes --- src/smp/builtins.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/smp/builtins.py b/src/smp/builtins.py index 537da37..f06df4e 100644 --- a/src/smp/builtins.py +++ b/src/smp/builtins.py @@ -90,7 +90,9 @@ def smp_builtin_add_metadata(macro_processor, metadata: dict[str, Any], overwrit def smp_builtin_include_file(macro_processor, filename): - return _smp_builtin_read(macro_processor, filename, template_content=None) + return _smp_builtin_read( + macro_processor, filename, template_content=None, inline=True + ) def smp_builtin_parse_leading_yaml(macro_processor, content): @@ -203,7 +205,7 @@ def smp_builtin_template(macro_processor, template, content): return _smp_builtin_read(macro_processor, template, template_content=content) -def _smp_builtin_read(macro_processor, filename, template_content=None): +def _smp_builtin_read(macro_processor, filename, template_content=None, inline=False): macro_processor._enter_file_frame(filename, 0, template_content) with open(filename, "r") as f: file_content = f.read() @@ -214,13 +216,13 @@ def _smp_builtin_read(macro_processor, filename, template_content=None): 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) + if not inline: + macro_processor._define_macro_with_prefix("target_file_extension", extension) if template_content is not None: macro_processor._get_macro_with_prefix("template_stack").append(filename) macro_processor.macros["CONTENT"] = template_content - # content = macro_processor.process_input(file_content, file=filename) content = file_content if (template := macro_processor._get_metadata("template")) is not None: -- cgit v1.2.3