home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import markdown
-
- class TablePattern(markdown.Pattern):
-
- def __init__(self, md):
- markdown.Pattern.__init__(self, '^\\|([^\\n]*)\\|(\\n|$)')
- self.md = md
-
-
- def handleMatch(self, m, doc):
- tr = doc.createElement('tr')
- tr.appendChild(doc.createTextNode('\n'))
- for t in m.group(2).split('|'):
- if len(t) >= 2 and t.startswith('*') and t.endswith('*'):
- td = doc.createElement('th')
- t = t[1:-1]
- else:
- td = doc.createElement('td')
- for n in self.md._handleInline(t):
- if type(n) == unicode:
- td.appendChild(doc.createTextNode(n))
- continue
- td.appendChild(n)
-
- tr.appendChild(td)
- tr.appendChild(doc.createTextNode('\n'))
-
- return tr
-
-
-
- class TablePostprocessor:
-
- def run(self, doc):
-
- def test_for_p(element):
- if element.type == 'element':
- pass
- return element.nodeName == 'p'
-
- for element in doc.find(test_for_p):
- for node in element.childNodes:
- if node.type == 'text' and node.value.strip() == '':
- continue
-
- if node.type == 'element' and node.nodeName == 'tr':
- element.nodeName = 'table'
-
-
-
-
-
-
- class TableExtension(markdown.Extension):
-
- def extendMarkdown(self, md, md_globals):
- md.inlinePatterns.insert(0, TablePattern(md))
- md.postprocessors.append(TablePostprocessor())
-
-
-
- def makeExtension(configs):
- return TableExtension(configs)
-
-