Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Unified Diff: third_party/Python-Markdown/markdown/extensions/tables.py

Issue 1356203004: Check in a simple pure-python based Markdown previewer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add
Patch Set: fix license file Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/Python-Markdown/markdown/extensions/tables.py
diff --git a/third_party/markdown/extensions/tables.py b/third_party/Python-Markdown/markdown/extensions/tables.py
similarity index 54%
copy from third_party/markdown/extensions/tables.py
copy to third_party/Python-Markdown/markdown/extensions/tables.py
index dacf78bab7dabcbaecf9312dde6b0778b431a7e1..368321d4624a6440b7c9e5eeb72c6dc78d4cd20b 100644
--- a/third_party/markdown/extensions/tables.py
+++ b/third_party/Python-Markdown/markdown/extensions/tables.py
@@ -1,49 +1,18 @@
-# markdown is released under the BSD license
-# Copyright 2007, 2008 The Python Markdown Project (v. 1.7 and later)
-# Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
-# Copyright 2004 Manfred Stienstra (the original version)
-#
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# * Neither the name of the <organization> nor the
-# names of its contributors may be used to endorse or promote products
-# derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE PYTHON MARKDOWN PROJECT ''AS IS'' AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL ANY CONTRIBUTORS TO THE PYTHON MARKDOWN PROJECT
-# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-
-
"""
Tables Extension for Python-Markdown
====================================
Added parsing of tables to Python-Markdown.
-A simple example:
+See <https://pythonhosted.org/Markdown/extensions/tables.html>
+for documentation.
+
+Original code Copyright 2009 [Waylan Limberg](http://achinghead.com)
- First Header | Second Header
- ------------- | -------------
- Content Cell | Content Cell
- Content Cell | Content Cell
+All changes Copyright 2008-2014 The Python Markdown Project
+
+License: [BSD](http://www.opensource.org/licenses/bsd-license.php)
-Copyright 2009 - [Waylan Limberg](http://achinghead.com)
"""
from __future__ import absolute_import
@@ -52,13 +21,14 @@ from . import Extension
from ..blockprocessors import BlockProcessor
from ..util import etree
+
class TableProcessor(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
+ return (len(rows) > 1 and '|' in rows[0] and
+ '|' in rows[1] and '-' in rows[1] and
rows[1].strip()[0] in ['|', ':', '-'])
def run(self, parent, blocks):
@@ -66,7 +36,7 @@ class TableProcessor(BlockProcessor):
block = blocks.pop(0).split('\n')
header = block[0].strip()
seperator = block[1].strip()
- rows = block[2:]
+ rows = [] if len(block) < 3 else block[2:]
# Get format type (bordered by pipes or not)
border = False
if header.startswith('|'):
@@ -97,13 +67,13 @@ class TableProcessor(BlockProcessor):
if parent.tag == 'thead':
tag = 'th'
cells = self._split_row(row, border)
- # We use align here rather than cells to ensure every row
+ # 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:
+ except IndexError: # pragma: no cover
c.text = ""
if a:
c.set('align', a)
@@ -123,10 +93,10 @@ class TableExtension(Extension):
def extendMarkdown(self, md, md_globals):
""" Add an instance of TableProcessor to BlockParser. """
- md.parser.blockprocessors.add('table',
+ md.parser.blockprocessors.add('table',
TableProcessor(md.parser),
'<hashheader')
-def makeExtension(configs={}):
- return TableExtension(configs=configs)
+def makeExtension(*args, **kwargs):
+ return TableExtension(*args, **kwargs)
« no previous file with comments | « third_party/Python-Markdown/markdown/extensions/smarty.py ('k') | third_party/Python-Markdown/markdown/extensions/toc.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698