added return command
This commit is contained in:
parent
70ba760c6a
commit
e0f7b16639
@ -70,11 +70,15 @@ The first word is the name of the variable, the rest is the value or a dictionar
|
|||||||
|
|
||||||
**Return Value**:
|
**Return Value**:
|
||||||
Empty string
|
Empty string
|
||||||
|
|
||||||
You can make the value of `varname` dependant on the value of another variable `othervar` by using a dictionary-like syntax described above.
|
You can make the value of `varname` dependant on the value of another variable `othervar` by using a dictionary-like syntax described above.
|
||||||
In this case, `varname` will take the first value from the dictionary that matches tha value of `othervar`.
|
In this case, `varname` will take the first value from the dictionary that matches tha value of `othervar`.
|
||||||
`*` always everything and can be used as fallback. General wildcards like `a*` to match everything that starts with a are not supported.
|
`*` always everything and can be used as fallback. General wildcards like `a*` to match everything that starts with a are not supported.
|
||||||
Instead of commas `,` you can also use semicolons `;` as separators, but this must be consistend within the map.
|
Instead of commas `,` you can also use semicolons `;` as separators, but this must be consistend within the map.
|
||||||
|
|
||||||
|
### return
|
||||||
|
Same as `set`, but it returns the value of the variable that is being set. This is meant to use with maps, when you need a variable from a map you can 'inline' it with `return`
|
||||||
|
|
||||||
### default
|
### default
|
||||||
Same as `set`, but it sets the variable's value only if it has no value yet.
|
Same as `set`, but it sets the variable's value only if it has no value yet.
|
||||||
|
|
||||||
@ -91,6 +95,7 @@ Any string
|
|||||||
|
|
||||||
**Return Value**:
|
**Return Value**:
|
||||||
The argument in comment tags
|
The argument in comment tags
|
||||||
|
|
||||||
This can be useful in multiline comments that contain other commands: In that case, the comment tags will be removed and each command replaced with
|
This can be useful in multiline comments that contain other commands: In that case, the comment tags will be removed and each command replaced with
|
||||||
its return value, so if you want to just have commented text in there you can use `#comment`
|
its return value, so if you want to just have commented text in there you can use `#comment`
|
||||||
|
|
||||||
@ -105,6 +110,7 @@ Any string
|
|||||||
|
|
||||||
**Return Value**:
|
**Return Value**:
|
||||||
The argument
|
The argument
|
||||||
|
|
||||||
This can be useful when you want to look at the unprocessed html without variables or when your syntax highlighting gets confused by a variable.
|
This can be useful when you want to look at the unprocessed html without variables or when your syntax highlighting gets confused by a variable.
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -162,3 +168,4 @@ Empty string
|
|||||||
- The `#include` command must not be in the last line of the file
|
- The `#include` command must not be in the last line of the file
|
||||||
- The maps in `set` must have **at least 2** options
|
- The maps in `set` must have **at least 2** options
|
||||||
- If you want to use variables in markdown, you have to escape the `#` with a backslash, so `#$(var)` becomes `\#$(var)`
|
- If you want to use variables in markdown, you have to escape the `#` with a backslash, so `#$(var)` becomes `\#$(var)`
|
||||||
|
- You can not use the `return` command from within the arguments of other commands. Commands are executed in order, so `return` will end up as argument of the first command and thus never be executed
|
||||||
|
@ -215,7 +215,7 @@ def cmd_include(args: str, variables:dict[str, str]={}) -> str:
|
|||||||
glob_dependcies.append(args)
|
glob_dependcies.append(args)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def cmd_set(args: str, variables:dict[str, str]={}) -> str:
|
def cmd_return(args: str, variables:dict[str, str]={}) -> str:
|
||||||
# re_set_map = r"([a-zA-Z0-9_]+)\?\{(([a-zA-Z0-9_]+:.+,)*([a-zA-Z0-9_]+:.+))\}"
|
# re_set_map = r"([a-zA-Z0-9_]+)\?\{(([a-zA-Z0-9_]+:.+,)*([a-zA-Z0-9_]+:.+))\}"
|
||||||
# <!-- #set section=lang?{*:Fallback,de:Abschnitt,en:Section} -->
|
# <!-- #set section=lang?{*:Fallback,de:Abschnitt,en:Section} -->
|
||||||
space = args.find(' ')
|
space = args.find(' ')
|
||||||
@ -247,15 +247,20 @@ def cmd_set(args: str, variables:dict[str, str]={}) -> str:
|
|||||||
variables[varname] = option[colon+1:].strip(" ")
|
variables[varname] = option[colon+1:].strip(" ")
|
||||||
|
|
||||||
else: # simple asignment
|
else: # simple asignment
|
||||||
value = args[space+1:]
|
value = args[space+1:].strip(" ")
|
||||||
variables[varname] = value.strip(" ")
|
variables[varname] = value
|
||||||
pdebug(f"cmd_set: Assignment {varname} -> {value.strip(' ')}")
|
pdebug(f"cmd_set: Assignment {varname} -> {value}")
|
||||||
|
return variables[varname]
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def cmd_set(args: str, variables:dict[str, str]={}) -> str:
|
||||||
|
cmd_return(args, variables)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def cmd_default(args: str, variables:dict[str, str]={}) -> str:
|
def cmd_default(args: str, variables:dict[str, str]={}) -> str:
|
||||||
separator = args.find(' ')
|
separator = args.find(' ')
|
||||||
if args[:separator] not in variables:
|
if args[:separator] not in variables:
|
||||||
return cmd_set(args, variables)
|
cmd_return(args, variables)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
@ -268,6 +273,7 @@ def cmd_uncomment(args: str, variables:dict[str, str]={}) -> str:
|
|||||||
command2function:dict[str, Callable[[str, dict[str,str]], str]] = {
|
command2function:dict[str, Callable[[str, dict[str,str]], str]] = {
|
||||||
"include": cmd_include,
|
"include": cmd_include,
|
||||||
"set": cmd_set,
|
"set": cmd_set,
|
||||||
|
"return": cmd_return,
|
||||||
"default": cmd_default,
|
"default": cmd_default,
|
||||||
"comment": cmd_comment,
|
"comment": cmd_comment,
|
||||||
"uncomment": cmd_uncomment,
|
"uncomment": cmd_uncomment,
|
||||||
|
Loading…
Reference in New Issue
Block a user