summaryrefslogtreecommitdiff
path: root/src/macro_processor
diff options
context:
space:
mode:
authorQrius <[email protected]>2024-09-26 00:11:05 +0200
committerQrius <[email protected]>2024-09-26 00:11:05 +0200
commitd1da14e73c33e015e868a011cb473177edbd3759 (patch)
treea6994c8fde772fcde79270c09361a61c232b29bf /src/macro_processor
parent13734ba915a8e35c51766c72d40089fadec5854e (diff)
downloadskaldpress-d1da14e73c33e015e868a011cb473177edbd3759.tar.gz
skaldpress-d1da14e73c33e015e868a011cb473177edbd3759.zip
Add indent macro, because nested functions doesn't really work, this also does not really work
Diffstat (limited to 'src/macro_processor')
-rw-r--r--src/macro_processor/macro_processor.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/macro_processor/macro_processor.rs b/src/macro_processor/macro_processor.rs
index 7ec296e..cec742e 100644
--- a/src/macro_processor/macro_processor.rs
+++ b/src/macro_processor/macro_processor.rs
@@ -197,6 +197,27 @@ fn smp_builtin_expr(
}
}
+/// Indent argument 2 by N spaces
+fn smp_builtin_indent(
+ smp: &mut MacroProcessor,
+ _macro_name: &str,
+ args: &mut [String],
+) -> Result<String, SMPError> {
+ let indent_size = args[0].parse::<u32>().unwrap_or(0);
+ let mut out = String::with_capacity(args[1].len());
+ for l in args[1].lines() {
+ let mut lin = String::with_capacity(indent_size.try_into().unwrap_or(0) + l.len());
+ if args.len() <= 2 && (args[2] != "skip_first") {
+ for _ in 0..indent_size {
+ lin.push(' ');
+ }
+ }
+ lin.push_str(&smp.process_input(&l)?);
+ out.push_str(&lin);
+ }
+ Ok(String::new())
+}
+
/// Types of macros, this is to make it easy to store both functions and strings
#[derive(Clone)]
pub enum MacroType {
@@ -270,6 +291,10 @@ impl MacroProcessor {
String::from("shell"),
MacroType::Function(smp_builtin_shell),
);
+ self.define_macro(
+ String::from("indent"),
+ MacroType::Function(smp_builtin_indent),
+ );
self.define_macro(String::from("expr"), MacroType::Function(smp_builtin_expr));
// format('Result id %d', 3282)
}