diff options
author | Qrius <[email protected]> | 2025-04-24 08:58:17 +0200 |
---|---|---|
committer | Qrius <[email protected]> | 2025-04-24 08:58:18 +0200 |
commit | 82df20d90a978535024cc2b8b87c7a2cfcfc1f7b (patch) | |
tree | a33b0c0d5a8e1dc98b0c0cc4ba9dbd85fba93454 /src | |
parent | fc9564127cc13ff435789fa2dde3a526367234f3 (diff) | |
download | skaldpress-82df20d90a978535024cc2b8b87c7a2cfcfc1f7b.tar.gz skaldpress-82df20d90a978535024cc2b8b87c7a2cfcfc1f7b.zip |
Add inline option to read macro, so we don't override target_file_extension with includes
Diffstat (limited to 'src')
-rw-r--r-- | src/smp/builtins.py | 10 |
1 files changed, 6 insertions, 4 deletions
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: |