I am currently working on this snippet
@register_snippet
class Foo(models.Model):
body = RichTextField()
Somehow I decided that I need to define __str__ so that I can distinguish between multiple snippets. I believe that using body contents as the string representation might be a good idea. Although, body can grow incredibly large, so the first 20 characters should do.
Thinking this task is a piece of cake, I wrote this code:
@register_snippet
class Foo(models.Model):
body = RichTextField()
def __str__(self):
return self.body[:20]
... which resulted in ugly representations such as <p>Quequeueueueue?</ and <p>FOO<br/></p>.
I checked the database and found out that the markup is stored in the database, which seemed pretty obvious. Although, I'm still wondering.
What is the way to remove HTML markup without using CPU-heavy HTML parsers and parsing the whole body?
I believe regular expressions can remove some tags, but how do I handle situations like </a, </blockqu, <, </?