Markup Plugins

When I was trying to rewrite the wiki.py parser, I noticed that adding markup for an element usually only needs several steps:

  1. Add a regular expression either to the block-level or to the text-level regular expressions
  2. (optional) Make sure it comes at the right place (i.e. before any more general expressions)
  3. Add a _repl method adding needed nodes to the document tree
  4. (optional) Add a method to the emitter to handle new node kind

This makes me wonder if I could refactor it to use markup objects instead. Such an object could look something like this:

   1 class Markup:
   2    def __init(self)__:
   3       self.level = 'block'     # or 'text' for text-level markup
   4       self.priority = 3        # determines the order of '|'.joining the expressions
   5       self.expression = r'...' # the expression, with apropriate groups
   6    
   7    def matched(self, groups, parser):
   8       """
   9       The function called when any of the groups in self.expression is matched.
  10 
  11       groups - the groups from match.groupdict()
  12       parser - used to carry some state
  13       """
  14       parser.current_node = DocumentNode('paragraph', parser.current_node)

The fourth step would have to be performed with other means (or maybe not at all).

This would enable admins to enable and disable markup on per-element basis, and also to easily add markup when it's required by the community.

( see also UnifyMarkup ? )


CategoryFeatureRejected

MoinMoin: FeatureRequests/MarkupPlugins (last edited 2007-10-29 19:10:22 by localhost)