def end_document(self):
print ‘’
def start_paragraph(self):
print ‘
’
def end_paragraph(self):
print ‘
’def start_heading(self):
print ‘
’
def end_heading(self):
print ‘’
def start_list(self):
print ‘
- ’
def end_list(self):
print ‘’
def start_listitem(self):
print ‘
- ’
-
def end_listitem(self):
print ‘’
def start_title(self):
print ‘
’
def end_title(self):
print ‘’
def sub_emphasis(self, match):
return ‘%s’ % match.group(1)
def sub_url(self, match):
return ‘%s’ % (match.group(1), match.group(1))
def sub_mail(self, match):
return ‘%s’ % (match.group(1), match.group(1))
def feed(self, data):
print data
3. 规则
有了处理程序和文本块生成器,接下来就需要一定的规则来判断每个文本块交给处理程序将要加什么标记,rules.py 代码如下:
#!/usr/bin/python
encoding: utf-8
class Rule:
“”"
规则父类
“”"
def action(self, block, handler):
“”"
加标记
“”"
handler.start(self.type)
handler.feed(block)