Skip to content

Instantly share code, notes, and snippets.

@daeken
Created September 25, 2013 17:29
Show Gist options
  • Select an option

  • Save daeken/6703071 to your computer and use it in GitHub Desktop.

Select an option

Save daeken/6703071 to your computer and use it in GitHub Desktop.
class Profile(db.Model):
user = db.UserProperty()
nickname = db.TextProperty()
desc = db.TextProperty()
pic = db.TextProperty()
def html_desc(self):
def rep(match):
sub = match.group(1)
if '|' not in sub:
return '[' + sub + ']'
else:
color, text = sub.split('|', 1)
color = color.replace('<', '\0')
color = color.replace('>', '\x02')
color = color.replace('"', '\x01')
return '\0span style=\x01color: %s\x01\x02%s\x00/span\x02' % (color.strip(), text.strip())
desc = re.sub(r'\[(.*?)\]', rep, self.desc)
desc = desc.replace('<', '&lt;')
desc = desc.replace('>', '&gt;')
desc = desc.replace('"', '&quot;')
desc = desc.replace('\0', '<')
desc = desc.replace('\x02', '>')
desc = desc.replace('\x01', '"')
desc = desc.replace('\n', '<br>')
return desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment