scanner: add a filter to escape ei protocol names

By default escape them with backticks for markdown
This commit is contained in:
Peter Hutterer 2023-03-03 10:14:06 +10:00
parent 2fb1ff70e3
commit eb9fa07c10

View file

@ -807,9 +807,19 @@ def generate_source(
def filter_as_c_arg(name):
return f"struct {name} *{name}"
# escape any ei[s]?_foo.bar with markdown backticks
def filter_ei_escape_names(str, quotes="`"):
if not str:
return str
import re
return re.sub(rf"({component}[_-]\w*)(\.\w*)?", rf"{quotes}\1\2{quotes}", str)
env.filters["c_type"] = filter_c_type
env.filters["as_c_arg"] = filter_as_c_arg
env.filters["camel"] = snake2camel
env.filters["ei_escape_names"] = filter_ei_escape_names
jtemplate = env.get_template(filename)
return jtemplate.stream(data)