MCPcopy Create free account
hub / github.com/webpy/webpy / normalize_text

Method normalize_text

web/template.py:967–980  ·  view source on GitHub ↗

Normalizes template text by correcting \r\n, tabs and BOM chars.

(text)

Source from the content-addressed store, hash-verified

965 return f"<{self.__class__.__name__} {self.filename}>"
966
967 def normalize_text(text):
968 """Normalizes template text by correcting \r\n, tabs and BOM chars."""
969 text = text.replace("\r\n", "\n").replace("\r", "\n").expandtabs()
970 if not text.endswith("\n"):
971 text += "\n"
972
973 # ignore BOM chars at the beginning of template
974 BOM = "\xef\xbb\xbf"
975 if isinstance(text, str) and text.startswith(BOM):
976 text = text[len(BOM) :]
977
978 # support fort \$ for backward-compatibility
979 text = text.replace(r"\$", "$$")
980 return text
981
982 normalize_text = staticmethod(normalize_text)
983

Callers 2

__init__Method · 0.80
compile_templatesFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected