finalise.py 549 B

1234567891011121314151617181920212223
  1. import re
  2. from django.utils.translation import gettext as _
  3. HEADER_RE = re.compile(
  4. r"""
  5. <div class="quote-heading">(?P<title>.*?)</div>
  6. """.strip(),
  7. re.IGNORECASE | re.MULTILINE | re.DOTALL,
  8. )
  9. def finalise_markup(post):
  10. return HEADER_RE.sub(replace_headers, post)
  11. def replace_headers(matchobj):
  12. title = matchobj.group("title")
  13. if title:
  14. quote_title = _("%(title)s has written:") % {"title": title}
  15. else:
  16. quote_title = _("Quoted message:")
  17. return '<div class="quote-heading">%s</div>' % quote_title