Implement urlencode filter
This commit is contained in:
parent
864217a9bd
commit
4e42eeb9fd
@ -45,6 +45,11 @@ class Emitter:
|
||||
|
||||
raise NotImplementedError()
|
||||
|
||||
def output_variable_urlencoded(self, variable: str) -> None:
|
||||
"""Emit code to output a variable, as encoded URL component"""
|
||||
|
||||
raise NotImplementedError()
|
||||
|
||||
def start_block(self, block_name: str) -> None:
|
||||
"""Called at {% block ... %}"""
|
||||
|
||||
|
@ -35,6 +35,9 @@ class CgitEmitter(Emitter):
|
||||
def output_variable_as_text(self, variable: str) -> None:
|
||||
self.emit(f'html_txt({variable});')
|
||||
|
||||
def output_variable_urlencoded(self, variable: str) -> None:
|
||||
self.emit(f'html_url_arg({variable});')
|
||||
|
||||
def start_page(self, page_name: str) -> None:
|
||||
super().start_page(page_name)
|
||||
self.emit('cgit_print_http_headers();')
|
||||
|
@ -129,6 +129,10 @@ class Parser:
|
||||
# Output as HTML attribute
|
||||
variable = variable[:-len('attr')].rstrip()[:-1].rstrip()
|
||||
self.emitter.output_variable_as_attr(variable)
|
||||
elif variable.endswith('urlencode') and variable[:-len('urlencode')].rstrip().endswith('|'):
|
||||
# Output as URL component
|
||||
variable = variable[:-len('urlencode')].rstrip()[:-1].rstrip()
|
||||
self.emitter.output_variable_urlencoded(variable)
|
||||
else:
|
||||
# No filter - output as text
|
||||
self.emitter.output_variable_as_text(variable)
|
||||
|
Loading…
x
Reference in New Issue
Block a user