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()
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)
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)
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))
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')) }
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()
def b_p(self, match): return u'<p>%s</p>\n' % p_inline.sub(self.inlines, match.group('p')).strip()
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())
def i_ins(self, match): return u'<ins>%s</ins>' % p_inline.sub(self.inlines, match.group(match.lastgroup))
def i_del(self, match): return u'<del>%s</del>' % p_inline.sub(self.inlines, match.group(match.lastgroup))
def i_strong(self, match): return u'<strong>%s</strong>' % p_inline.sub( self.inlines, match.group(match.lastgroup))
def i_em(self, match): return u'<em>%s</em>' % p_inline.sub(self.inlines, match.group(match.lastgroup))
def i_code(self, match): return u'<tt class="code">%s</tt>' % p_inline.sub( self.inlines, match.group(match.lastgroup))