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.
- def save(self):
- self.slug=slugify(self.title)
- if not self.id:
- self.pub_date=datetime.now()
- self.text = markdown.markdown(self.source, ['codehilite'])
- super(Post,self).save()
- new_tag_list=[t for t in re.split('[\s,]+', self.tag_list) if t]
- current_tags=list(self.tags.all())
- for tag in current_tags:
- if tag.title not in new_tag_list:
- self.tags.remove(tag)
- for tag_title in new_tag_list:
- if tag_title not in [tag.title for tag in current_tags]:
- tag, created=Tag.objects.get_or_create(title=tag_title)
- self.tags.add(tag)
- return
- .codehilite
- {
- /* The source code snippet box */
- color:#ccc;
- background-color:#333;
- }
- /* self */
- .codehilite .bp { color:#9df;font-weight:bold; }
- /* keywords: def, return, if, while, for. */
- .codehilite .k { color:#f99; font-weight:bold; }
- /* Variables */
- .codehilite .n { color:#ccc; }
- /* Strings */
- .codehilite .s { color:#7b7; }
- /* Bools: not, in */
- .codehilite .ow { color:#c66; }
Comments
19 spam comments omitted.
I am no longer accepting new comments.