From: Yuri T. <qar...@gm...> - 2008-11-14 09:44:41
|
Now that we are changing so much, I want to propose a change that has been on my mind for quite some time. Back in the day I made a decision to implement all processors as classes. Since then I've been thinking that perhaps implementing them simply as functions would make things a lot easier and intuitive. It may make some complicated cases a little more complicated, but will simplify the simple cases, which would make it easier for people to write simple extensions. For instance, we would have def handleFootnotePattern(md, match) : sup = etree.Element("sup") a = etree.SubElement(sup, "a") id = m.group(2) sup.set('id', md.footnotes.makeFootnoteRefId(id)) a.set('href', '#' + md.footnotes.makeFootnoteId(id)) a.set('rel', 'footnote') a.text = str(md.footnotes.footnotes.index(id) + 1) return sup instead of: class FootnotePattern(markdown.Pattern): """ InlinePattern for footnote markers in a document's body text. """ def __init__(self, pattern, footnotes): markdown.Pattern.__init__(self, pattern) self.footnotes = footnotes def handleMatch(self, m): sup = etree.Element("sup") a = etree.SubElement(sup, "a") id = m.group(2) sup.set('id', self.footnotes.makeFootnoteRefId(id)) a.set('href', '#' + self.footnotes.makeFootnoteId(id)) a.set('rel', 'footnote') a.text = str(self.footnotes.footnotes.index(id) + 1) return sup and then: md.inlinePatterns.add("footnote", (FOOTNOTE_RE, handleFootnotePattern), "<reference") instead of: md.inlinePatterns.add("footnote", FootnotePattern(FOOTNOTE_RE, self), "<reference") If we do this, I suggest that we do this for _all_ types of processors. I don't think this would be too complicated to implement. - yuri -- http://sputnik.freewisdom.org/ |