/
usr
/
lib
/
python2.6
/
site-packages
/
markdown
/
extensions
/
/usr/lib/python2.6/site-packages/markdown/extensions
mkdir
upload
Name
Size
Mode
Actions
abbr.py
2899
0644
edit
dl
rm
abbr.pyc
4294
0644
edit
dl
rm
abbr.pyo
4294
0644
edit
dl
rm
codehilite.py
7673
0644
edit
dl
rm
codehilite.pyc
8129
0644
edit
dl
rm
codehilite.pyo
8129
0644
edit
dl
rm
def_list.py
3170
0644
edit
dl
rm
def_list.pyc
4047
0644
edit
dl
rm
def_list.pyo
4047
0644
edit
dl
rm
extra.py
1739
0644
edit
dl
rm
extra.pyc
2323
0644
edit
dl
rm
extra.pyo
2323
0644
edit
dl
rm
fenced_code.py
3423
0644
edit
dl
rm
fenced_code.pyc
4371
0644
edit
dl
rm
fenced_code.pyo
4371
0644
edit
dl
rm
footnotes.py
10055
0644
edit
dl
rm
footnotes.pyc
11433
0644
edit
dl
rm
footnotes.pyo
11433
0644
edit
dl
rm
headerid.py
6326
0644
edit
dl
rm
headerid.pyc
7470
0644
edit
dl
rm
headerid.pyo
7470
0644
edit
dl
rm
html_tidy.py
2071
0644
edit
dl
rm
html_tidy.pyc
2756
0644
edit
dl
rm
html_tidy.pyo
2756
0644
edit
dl
rm
imagelinks.py
3491
0644
edit
dl
rm
imagelinks.pyc
3311
0644
edit
dl
rm
imagelinks.pyo
3311
0644
edit
dl
rm
meta.py
2590
0644
edit
dl
rm
meta.pyc
3275
0644
edit
dl
rm
meta.pyo
3275
0644
edit
dl
rm
rss.py
3693
0644
edit
dl
rm
rss.pyc
4337
0644
edit
dl
rm
rss.pyo
4337
0644
edit
dl
rm
tables.py
3079
0644
edit
dl
rm
tables.pyc
3877
0644
edit
dl
rm
tables.pyo
3877
0644
edit
dl
rm
toc.py
5098
0644
edit
dl
rm
toc.pyc
4466
0644
edit
dl
rm
toc.pyo
4466
0644
edit
dl
rm
wikilinks.py
5292
0644
edit
dl
rm
wikilinks.pyc
6281
0644
edit
dl
rm
wikilinks.pyo
6281
0644
edit
dl
rm
__init__.py
0
0644
edit
dl
rm
__init__.pyc
151
0644
edit
dl
rm
__init__.pyo
151
0644
edit
dl
rm
Edit:
/usr/lib/python2.6/site-packages/markdown/extensions/tables.py
(3079B)
""" Tables Extension for Python-Markdown ==================================== Added parsing of tables to Python-Markdown. A simple example: First Header | Second Header ------------- | ------------- Content Cell | Content Cell Content Cell | Content Cell Copyright 2009 - [Waylan Limberg](http://achinghead.com) """ import markdown from markdown import etree class TableProcessor(markdown.blockprocessors.BlockProcessor): """ Process Tables. """ def test(self, parent, block): rows = block.split('\n') return (len(rows) > 2 and '|' in rows[0] and '|' in rows[1] and '-' in rows[1] and rows[1][0] in ['|', ':', '-']) def run(self, parent, blocks): """ Parse a table block and build table. """ block = blocks.pop(0).split('\n') header = block[:2] rows = block[2:] # Get format type (bordered by pipes or not) border = False if header[0].startswith('|'): border = True # Get alignment of columns align = [] for c in self._split_row(header[1], border): if c.startswith(':') and c.endswith(':'): align.append('center') elif c.startswith(':'): align.append('left') elif c.endswith(':'): align.append('right') else: align.append(None) # Build table table = etree.SubElement(parent, 'table') thead = etree.SubElement(table, 'thead') self._build_row(header[0], thead, align, border) tbody = etree.SubElement(table, 'tbody') for row in rows: self._build_row(row, tbody, align, border) def _build_row(self, row, parent, align, border): """ Given a row of text, build table cells. """ tr = etree.SubElement(parent, 'tr') tag = 'td' if parent.tag == 'thead': tag = 'th' cells = self._split_row(row, border) # We use align here rather than cells to ensure every row # contains the same number of columns. for i, a in enumerate(align): c = etree.SubElement(tr, tag) try: c.text = cells[i].strip() except IndexError: c.text = "" if a: c.set('align', a) def _split_row(self, row, border): """ split a row of text into list of cells. """ if border: if row.startswith('|'): row = row[1:] if row.endswith('|'): row = row[:-1] return row.split('|') class TableExtension(markdown.Extension): """ Add tables to Markdown. """ def extendMarkdown(self, md, md_globals): """ Add an instance of TableProcessor to BlockParser. """ md.parser.blockprocessors.add('table', TableProcessor(md.parser), '<hashheader') def makeExtension(configs={}): return TableExtension(configs=configs)
Save
cmd:
run