in python/moz/l10n/formats/dtd/serialize.py [0:0]
def comment(comment: str, meta: Any, standalone: bool) -> Iterator[str]:
nonlocal at_empty_line
if trim_comments:
return
if meta:
raise ValueError("Metadata is not supported")
if comment:
if standalone and not at_empty_line:
yield "\n"
# Comments can't include --, so add a zero width space between and after dashes beyond the first
lines = [
line.rstrip().replace("--", "-\u200b-\u200b")
for line in comment.strip("\n").split("\n")
]
cstr = "<!--" if not lines[0] or lines[0].startswith(" ") else "<!-- "
cstr += lines[0]
for line in lines[1:]:
cstr += "\n"
if line and not line.isspace():
if not line.startswith(" "):
cstr += " "
cstr += line
yield cstr + " -->\n"
if standalone:
yield "\n"
at_empty_line = True