17 lines
390 B
Python
17 lines
390 B
Python
class FilterModule:
|
|
def filters(self):
|
|
return {
|
|
"enquote": enquote,
|
|
}
|
|
|
|
|
|
def enquote(string, delimiter='"', escape="\\"):
|
|
translation = str.maketrans(
|
|
{
|
|
delimiter: f"{escape}{delimiter}",
|
|
escape: f"{escape}{escape}",
|
|
}
|
|
)
|
|
escaped = string.translate(translation)
|
|
return f"{delimiter}{escaped}{delimiter}"
|