'Match and store Fenced Code Blocks in the HtmlStash.'

def run(self, lines):

    output = []
    class BaseHandler(object, ):
        def handle_line(self, line):
            raise NotImplementedError()
        def done(self):
            raise NotImplementedError()
    processor = self
    handlers = []
    def push(handler):
        handlers.append(handler)
    def pop():
        handlers.pop()
    def check_for_new_fence(output, line):
        m = FENCE_RE.match(line)
        if m:
            fence = m.group('fence')
            lang = m.group('lang')
            handler = generic_handler(output, fence, lang)
            push(handler)
        else:
            output.append(line)
    class OuterHandler(BaseHandler, ):
        def __init__(self, output):
            self.output = output
        def handle_line(self, line):
            check_for_new_fence(self.output, line)
        def done(self):
            pop()
    def generic_handler(output, fence, lang):
        if (lang in ('quote', 'quoted')):
            return QuoteHandler(output, fence)
        elif (lang in ('math', 'tex', 'latex')):
            return TexHandler(output, fence)
        else:
            return CodeHandler(output, fence, lang)
    class CodeHandler(BaseHandler, ):
        def __init__(self, output, fence, lang):
            self.output = output
            self.fence = fence
            self.lang = lang
            self.lines = []
        def handle_line(self, line):
            if (line.rstrip() == self.fence):
                self.done()
            else:
                self.lines.append(line.rstrip())
        def done(self):
            text = '\n'.join(self.lines)
            text = processor.format_code(self.lang, text)
            text = processor.placeholder(text)
            processed_lines = text.split('\n')
            self.output.append('')
            self.output.extend(processed_lines)
            self.output.append('')
            pop()
    class QuoteHandler(BaseHandler, ):
        def __init__(self, output, fence):
            self.output = output
            self.fence = fence
            self.lines = []
        def handle_line(self, line):
            if (line.rstrip() == self.fence):
                self.done()
            else:
                check_for_new_fence(self.lines, line)
        def done(self):
            text = '\n'.join(self.lines)
            text = processor.format_quote(text)
            processed_lines = text.split('\n')
            self.output.append('')
            self.output.extend(processed_lines)
            self.output.append('')
            pop()
    class TexHandler(BaseHandler, ):
        def __init__(self, output, fence):
            self.output = output
            self.fence = fence
            self.lines = []
        def handle_line(self, line):
            if (line.rstrip() == self.fence):
                self.done()
            else:
                check_for_new_fence(self.lines, line)
        def done(self):
            text = '\n'.join(self.lines)
            text = processor.format_tex(text)
            text = processor.placeholder(text)
            processed_lines = text.split('\n')
            self.output.append('')
            self.output.extend(processed_lines)
            self.output.append('')
            pop()
    handler = OuterHandler(output)
    push(handler)
    for line in lines:
        handlers[(-1)].handle_line(line)
    while handlers:
        handlers[(-1)].done()
    if ((len(output) > 2) and (output[(-2)] != '')):
        output.append('')
    return output
