Well, hot on the heels of the last new feature, I've added code hilighting to the blog - or at least, I think I have. To test it out, here's the overridden save() function for this blog.

  1. def save(self):
  2. self.slug=slugify(self.title)
  3. if not self.id:
  4. self.pub_date=datetime.now()
  5. self.text = markdown.markdown(self.source, ['codehilite'])
  6. super(Post,self).save()
  7. new_tag_list=[t for t in re.split('[\s,]+', self.tag_list) if t]
  8. current_tags=list(self.tags.all())
  9. for tag in current_tags:
  10. if tag.title not in new_tag_list:
  11. self.tags.remove(tag)
  12. for tag_title in new_tag_list:
  13. if tag_title not in [tag.title for tag in current_tags]:
  14. tag, created=Tag.objects.get_or_create(title=tag_title)
  15. self.tags.add(tag)
  16. return
I'm using the python-markdown extension [codehilite](http://achinghead.com/markdown/codehilite/). Just to have some extra CSS to style, here is a part of the CSS theme for the code hilighting.
  1. .codehilite
  2. {
  3. /* The source code snippet box */
  4. color:#ccc;
  5. background-color:#333;
  6. }
  7. /* self */
  8. .codehilite .bp { color:#9df;font-weight:bold; }
  9. /* keywords: def, return, if, while, for. */
  10. .codehilite .k { color:#f99; font-weight:bold; }
  11. /* Variables */
  12. .codehilite .n { color:#ccc; }
  13. /* Strings */
  14. .codehilite .s { color:#7b7; }
  15. /* Bools: not, in */
  16. .codehilite .ow { color:#c66; }
md5:4733b3e58d15cbfea0b04e92f38e2c15