Photo of Seemant

Seemant's Blog

Jun 5 2007

Building My Django Weblog: Part 6.5

Categories: , , Filed by: Seemant Kulleen
4 Comments Subscribe to this entry's comments RSS feed Subscribe to this entry's comments Atom feed

All of a sudden, more than a month has passed and I have not added any new entries. I've been working on and off on a markdown extension to handle abbr and acronym tags. So far it simply refuses to work (the code doesn't even seem to get executed). For the curious:

import re, markdown, random

class AcronymExtension (markdown.Extension):
    def __init__ (self, configs) :
        self.config = configs

    def extendMarkdown(self, md, md_globals) :
        self.md = md

        ABBR_RE = re.compile(r'\[(.+?)\]\{([^{]+?)\}')
        ACRONYM_RE = re.compile(r'\[([^\]]*)\]\{\{([^}]+)\}\}')

        md.inlinePatterns.append(AcronymPattern(ABBR_RE, self.config))
       # md.inlinePatterns.append(AcronymPattern(ACRONYM_RE, self.config))

class AcronymPattern (markdown.BasePattern) :
    def __init__ (self, pattern, config) :
        markdown.BasePattern.__init__(self, pattern)
        self.config = config

    def handleMatch(self, m, doc) :
        abbr = doc.createElement('abbr')
        abbr.appendChild(doc.createTextNode(m.group(1)))
        abbr.setAttribute('title', m.group(2))
        return abbr

def makeExtension(configs=None) :
    return AcronymExtension(configs=configs)

if __name__ == "__main__":
    import doctest
    doctest.testmod()

So, in the meanwhile, I'm not able to deliver on my promise to talk more about microformats.

However, if you're astute, you've noticed that the tag cloud on these pages has changed. John Buchanan recently released a distutils-enabled version of django-tagging.

He's implemented both the features I requested, which makes me greatly happy. I've added the first feature to this site already. Now, when you click on a specific user's blog, you will see the tag cloud that pertains to that user only. When you go back out to the main blog page you'll see an aggregate or global tag cloud. A lot of thanks to Mr. Buchanan for his work.

The other thing that this site now has is email. Jay Pfeifer has been helping me set up a lot of the back end of this site. He helped set up apache properly; he's been the signing authority for my SSL certificates; and this week he set up the email back-end. I'll have more to talk about when I do something with that (for now I'm just setting up imap access for my family members). Maybe the django-webmail project can move forward a little bit more.

Sorry to have kept so silent. If you have any feedback on the broken markdown extension code I pasted above, please leave me a comment. I'd love to get that working properly.

Permanent Link
Subscribe to this entry's comments RSS feed Subscribe to this entry's comments Atom feed

4 Comments

United States Comment by Waylan Limberg after 22 hours, 45 minutes

Seemant had emailed me asking for some help on this a while ago. At the time I was way to busy to take even a few minutes to look at it. Fortunately for him, I have a little time now and emailed him a working version of his code today. Thanks for the reminder Seemant.

For anyone following along at home the reason Seemant didn't think his code was being run was that he was passing Markdown compiled regex. However markdown expects a raw string which it then compiles. Obviously, compiling compiled regex will result in zero matches, so yes the code was running, but just wasn't getting any matches. This was an easy mistake to make, and, in fact, I did the same thing my first time around. There were a couple other minor issues, but with that worked out they should be pretty obvious.

Russian Federation Comment by sd after 1 month

gjhghj

United States Comment by Samuel Cormier-Iijima after 2 months

Django doesn't load any Markdown extensions unless you use a patch from http://code.djangoproject.com/ticket/2910 - for this to work, you have to put mdx_extension.py somewhere on your path, and then {{ content|markdown:"extension" }} should load it up. I had to create a tag that let people embed YouTube videos with ==youtube(code)==, so I just went through the same ordeal you did :-) Just thought I'd help out!

United States Comment by Waylan Limberg after 2 months, 2 weeks

With Seemant's permission, I've released the code with improvements. You can now define abbreviations by reference like in PHP Markdown Extra. Read the [announcement][1] and [docs][2], or get the [code][3].

[1]: http://achinghead.com/archive/77/announcing-abbreviation-extension-python-markdown/ [2]: http://achinghead.com/markdown/abbr/ [3]: https://code.achinghead.com/browser/mdx/abbr/trunk/mdx_abbr.py

Join the conversation