Compare commits

..

2 Commits

Author SHA1 Message Date
Matthias@Dell
ca60a1b02c add remove blanks in output 2023-11-19 20:12:15 +01:00
Matthias@Dell
36efa54904 add cmd unset 2023-11-19 19:28:22 +01:00
2 changed files with 26 additions and 2 deletions

View File

@ -97,6 +97,19 @@ Same as `set`, but it returns the value of the variable that is being set. This
### default
Same as `set`, but it sets the variable's value only if it has no value yet.
### unset
Unset a variable
**Synopsis**:
Unset `varname`, it will no longer be defined and can therefor be set with `default` again.
`<!-- #unset varname -->`
**Argument**:
Name of the variable
**Return Value**:
Empty string
---
### comment

View File

@ -273,7 +273,7 @@ def cmd_return(args: str, variables:dict[str, str]={}) -> str:
# pdebug(f"cmd_set: varname='{args[:space]}, 'arg='{args[space+1:]}', variables='{variables}'")
if not (space > 0 and space < len(args)-1):
variables[args] = ""
pdebug(f"cmd_set: Setting to emptry string: {args}")
pdebug(f"cmd_set: Setting to empty string: {args}")
else:
varname = args[:space]
variables[varname] = ""
@ -308,6 +308,14 @@ def cmd_set(args: str, variables:dict[str, str]={}) -> str:
cmd_return(args, variables)
return ""
def cmd_unset(args: str, variables:dict[str, str]={}) -> str:
variable = args.strip(' ')
if variable not in variables:
pdebug(f"unset: variable '{variable}' is not set", level=error_levels["light"])
else:
variables.pop(variable)
return ""
def cmd_default(args: str, variables:dict[str, str]={}) -> str:
separator = args.find(' ')
if args[:separator] not in variables:
@ -331,8 +339,9 @@ def cmd_warning(args: str, variables:dict[str, str]={}) -> str:
command2function:dict[str, Callable[[str, dict[str,str]], str]] = {
"include": cmd_include,
"section": cmd_section,
"set": cmd_set,
"return": cmd_return,
"set": cmd_set,
"unset": cmd_unset,
"default": cmd_default,
"comment": cmd_comment,
"uncomment": cmd_uncomment,
@ -651,6 +660,8 @@ if __name__ == "__main__":
target_html = file.read()
output_html = parse_file(target_html, variables, not args.preserve_comments)
# remove empty lines
output_html = re.sub(r"[\t\r ]*\n(?:[\t\r ]*\n[\t\r ]*)+", r"\n", output_html)
# pdebug(f"Output: {output_html}")