&langs in my links became 〈.
Advertise here: Contact FM.
def ampersands(string): """Allow terminated entities but escape wild ampersands.""" splits = string.split('&') if len(splits) == 1: return string result = splits[0] for split in splits[1:]: if split: for char in split: if char.isspace(): result += "&" + split; break elif char == ';': result += "&" + split; break else: # end of split result += "&" + split else: # empty split result += "&" return resultThere's a way to rewrite it as a regex using non-capturing expressions, but I've never bothered.def ampersands(string):
"""Allow terminated entities but escape wild ampersands."""
splits = string.split('&')
if len(splits) == 1:
return string
result = splits[0]
for split in splits[1:]:
if split:
for char in split:
if char.isspace():
result += "&" + split; break
elif char == ';':
result += "&" + split; break
else: # end of split
result += "&" + split
else: # empty split
result += "&"
return result
It's only for the opening post and it doesn't seem restricted to links. I'm on Firefox 3.0.4 and Safari 3.2 on OS X 10.5.5.
posted by Korou at 5:07 PM on November 14, 2008