code: def wp_caption(self, post):
          
          for match in re.finditer(r"\[caption (.*?)\](.*?)\[/caption\]", post):
              meta = '<div '
              caption = ''
              for imatch in re.finditer(r'(\w+)="(.*?)"', match.group(1)):
                  if imatch.group(1) == 'id':
                      meta += 'id="%s" ' % imatch.group(2)
                  if imatch.group(1) == 'align':
                      meta += 'class="wp-caption %s" ' % imatch.group(2)
                  if imatch.group(1) == 'width':
                      width = int(imatch.group(2)) + 10
                      meta += 'style="width: %spx;" ' % width
                  if imatch.group(1) == 'caption':
                      caption = imatch.group(2)
              parts = (match.group(2), caption)
              meta += '>%s<p class="wp-caption-text">%s</p></div>' % parts
              post = post.replace(match.group(0), meta)
          return post
docs: Filters a Wordpress Post for Image Captions and renders to
          match HTML.