04.08.2014 Views

o_18ufhmfmq19t513t3lgmn5l1qa8a.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 20 ■ PROJECT 1: INSTANT MARKUP 405<br />

def start_listitem(self):<br />

print ''<br />

def end_listitem(self):<br />

print ''<br />

def start_title(self):<br />

print ''<br />

def end_title(self):<br />

print ''<br />

def sub_emphasis(self, match):<br />

return '%s' % match.group(1)<br />

def sub_url(self, match):<br />

return '%s' % (match.group(1), match.group(1))<br />

def sub_mail(self, match):<br />

return '%s' % (match.group(1), match.group(1))<br />

def feed(self, data):<br />

print data<br />

Listing 20-5. The Rules (rules.py)<br />

class Rule:<br />

"""<br />

Base class for all rules.<br />

"""<br />

def action(self, block, handler):<br />

handler.start(self.type)<br />

handler.feed(block)<br />

handler.end(self.type)<br />

return True<br />

class HeadingRule(Rule):<br />

"""<br />

A heading is a single line that is at most 70 characters and<br />

that doesn't end with a colon.<br />

"""<br />

type = 'heading'<br />

def condition(self, block):<br />

return not '\n' in block and len(block)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!