示例#1
0
 def b_blockquote(self, match):
     return u'<blockquote><p>%s</p></blockquote>\n' % u'</p>\n<p>'.join(
         self._block_separator.split(
             p_inline.sub(
                 self.inlines,
                 self._first_gt_space.sub('', match.group(
                     match.lastgroup))))).rstrip()
示例#2
0
 def i_cite(self, match):
     r = ['<q']
     if match.group('cite_lang'):
         r.append(u' lang="%s"' % self.escape(match.group('cite_lang')))
     if match.group('cite_cite'):
         # FIXME? use urlencode, not escape
         r.append(u' cite="%s"' % self.escape(match.group('cite_cite')))
     r.append(u'>%s</q>' %
              p_inline.sub(self.inlines, match.group('cite_value')).strip())
     return ''.join(r)
示例#3
0
 def i_a(self, match):
     href = urlparse.urlsplit(match.group('a_href'))
     link = [u'<a href="%s"' % match.group('a_href')]
     if match.group('a_title'):
         link.append(u' title="%s"' % self.escape(match.group('a_title')))
     if match.group('a_lang'):
         link.append(u' hreflang="%s"' % self.escape(match.group('a_lang')))
     if href.scheme:
         # TODO: make a handle for the external using the hostname
         link.append(u' class="external"')
     link.append(u'>%s</a>' % (
      p_inline.sub(self.inlines, match.group('a_value')) \
      if match.group('a_value') \
      else self.escape(match.group('a_href'))
     ))
     return ''.join(link)
示例#4
0
 def b_list(self, match):
     ltprev = ''
     #? TODO: i'd like to do it without the nodes tree
     root = node = MazNode('div')
     for m in self._fragment_list.finditer(match.group()):
         ltcurr, value = m.groups()
         for prev, curr in itertools.dropwhile(
                 lambda x: not cmp(x[0], x[1]),
                 itertools.izip_longest(ltprev, ltcurr)):
             if prev:
                 node = node.parent
                 if node.name == 'li':
                     node = node.parent
             if curr:
                 if node.child and node.child.name == 'li':
                     node = node.child.prev
                 node += MazNode('%sl' % (curr == '#' and 'o' or 'u', ))
                 node = node.child.prev
         node += (MazNode('li') +
                  MazNode(value=p_inline.sub(self.inlines, value)))
         ltprev = ltcurr
     # FIXME: there is a bug in MazNode when descending from a higher level than the root
     root.child.parent = root.child
     return self._li_trim.sub('', node2html(root.child))
示例#5
0
 def b_head(self, match):
     return u'<h%(n)u>%(value)s</h%(n)u>\n' % {
         'n': 6 - len(match.group('head_level')),
         'value': p_inline.sub(self.inlines, match.group('head_value'))
     }
示例#6
0
 def b_pre(self, match):
     return u'<pre>%s</pre>\n' % p_inline.sub(
         self.inlines,
         self._first_space.sub('', match.group(match.lastgroup))).rstrip()
示例#7
0
 def b_p(self, match):
     return u'<p>%s</p>\n' % p_inline.sub(self.inlines,
                                          match.group('p')).strip()
示例#8
0
 def i_acronym(self, match):
     return u'<acronym%s>%s</acronym>' % (
         u' title="%s"' % self.escape(match.group('acronym_title').strip())
         if match.group('acronym_title') else '',
         p_inline.sub(self.inlines, match.group('acronym_value')).strip())
示例#9
0
 def i_ins(self, match):
     return u'<ins>%s</ins>' % p_inline.sub(self.inlines,
                                            match.group(match.lastgroup))
示例#10
0
 def i_del(self, match):
     return u'<del>%s</del>' % p_inline.sub(self.inlines,
                                            match.group(match.lastgroup))
示例#11
0
 def i_strong(self, match):
     return u'<strong>%s</strong>' % p_inline.sub(
         self.inlines, match.group(match.lastgroup))
示例#12
0
 def i_em(self, match):
     return u'<em>%s</em>' % p_inline.sub(self.inlines,
                                          match.group(match.lastgroup))
示例#13
0
 def i_code(self, match):
     return u'<tt class="code">%s</tt>' % p_inline.sub(
         self.inlines, match.group(match.lastgroup))