| Index: third_party/Python-Markdown/markdown/serializers.py
|
| diff --git a/third_party/markdown/serializers.py b/third_party/Python-Markdown/markdown/serializers.py
|
| similarity index 78%
|
| copy from third_party/markdown/serializers.py
|
| copy to third_party/Python-Markdown/markdown/serializers.py
|
| index 67e9daed21aab383b4024e344fa0ab1a3fdfea47..1e8d9dd288f00ea0d5e001a22eb5004001cbcbf5 100644
|
| --- a/third_party/markdown/serializers.py
|
| +++ b/third_party/Python-Markdown/markdown/serializers.py
|
| @@ -1,35 +1,3 @@
|
| -# 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.
|
| -
|
| -
|
| # markdown/searializers.py
|
| #
|
| # Add x/html serialization to Elementree
|
| @@ -74,9 +42,9 @@ from __future__ import unicode_literals
|
| from . import util
|
| ElementTree = util.etree.ElementTree
|
| QName = util.etree.QName
|
| -if hasattr(util.etree, 'test_comment'):
|
| +if hasattr(util.etree, 'test_comment'): # pragma: no cover
|
| Comment = util.etree.test_comment
|
| -else:
|
| +else: # pragma: no cover
|
| Comment = util.etree.Comment
|
| PI = util.etree.PI
|
| ProcessingInstruction = util.etree.ProcessingInstruction
|
| @@ -88,7 +56,7 @@ HTML_EMPTY = ("area", "base", "basefont", "br", "col", "frame", "hr",
|
|
|
| try:
|
| HTML_EMPTY = set(HTML_EMPTY)
|
| -except NameError:
|
| +except NameError: # pragma: no cover
|
| pass
|
|
|
| _namespace_map = {
|
| @@ -105,17 +73,19 @@ _namespace_map = {
|
| }
|
|
|
|
|
| -def _raise_serialization_error(text):
|
| +def _raise_serialization_error(text): # pragma: no cover
|
| raise TypeError(
|
| "cannot serialize %r (type %s)" % (text, type(text).__name__)
|
| )
|
|
|
| +
|
| def _encode(text, encoding):
|
| try:
|
| return text.encode(encoding, "xmlcharrefreplace")
|
| - except (TypeError, AttributeError):
|
| + except (TypeError, AttributeError): # pragma: no cover
|
| _raise_serialization_error(text)
|
|
|
| +
|
| def _escape_cdata(text):
|
| # escape character data
|
| try:
|
| @@ -129,7 +99,7 @@ def _escape_cdata(text):
|
| if ">" in text:
|
| text = text.replace(">", ">")
|
| return text
|
| - except (TypeError, AttributeError):
|
| + except (TypeError, AttributeError): # pragma: no cover
|
| _raise_serialization_error(text)
|
|
|
|
|
| @@ -147,9 +117,10 @@ def _escape_attrib(text):
|
| if "\n" in text:
|
| text = text.replace("\n", " ")
|
| return text
|
| - except (TypeError, AttributeError):
|
| + except (TypeError, AttributeError): # pragma: no cover
|
| _raise_serialization_error(text)
|
|
|
| +
|
| def _escape_attrib_html(text):
|
| # escape attribute value
|
| try:
|
| @@ -162,7 +133,7 @@ def _escape_attrib_html(text):
|
| if "\"" in text:
|
| text = text.replace("\"", """)
|
| return text
|
| - except (TypeError, AttributeError):
|
| + except (TypeError, AttributeError): # pragma: no cover
|
| _raise_serialization_error(text)
|
|
|
|
|
| @@ -184,7 +155,7 @@ def _serialize_html(write, elem, qnames, namespaces, format):
|
| write("<" + tag)
|
| items = elem.items()
|
| if items or namespaces:
|
| - items.sort() # lexical order
|
| + items = sorted(items) # lexical order
|
| for k, v in items:
|
| if isinstance(k, QName):
|
| k = k.text
|
| @@ -199,28 +170,28 @@ def _serialize_html(write, elem, qnames, namespaces, format):
|
| write(" %s=\"%s\"" % (qnames[k], v))
|
| if namespaces:
|
| items = namespaces.items()
|
| - items.sort(key=lambda x: x[1]) # sort on prefix
|
| + items.sort(key=lambda x: x[1]) # sort on prefix
|
| for v, k in items:
|
| if k:
|
| k = ":" + k
|
| write(" xmlns%s=\"%s\"" % (k, _escape_attrib(v)))
|
| - if format == "xhtml" and tag in HTML_EMPTY:
|
| + if format == "xhtml" and tag.lower() in HTML_EMPTY:
|
| write(" />")
|
| else:
|
| write(">")
|
| - tag = tag.lower()
|
| if text:
|
| - if tag == "script" or tag == "style":
|
| + if tag.lower() in ["script", "style"]:
|
| write(text)
|
| else:
|
| write(_escape_cdata(text))
|
| for e in elem:
|
| _serialize_html(write, e, qnames, None, format)
|
| - if tag not in HTML_EMPTY:
|
| + if tag.lower() not in HTML_EMPTY:
|
| write("</" + tag + ">")
|
| if elem.tail:
|
| write(_escape_cdata(elem.tail))
|
|
|
| +
|
| def _write_html(root,
|
| encoding=None,
|
| default_namespace=None,
|
| @@ -265,7 +236,7 @@ def _namespaces(elem, default_namespace=None):
|
| if prefix:
|
| qnames[qname] = "%s:%s" % (prefix, tag)
|
| else:
|
| - qnames[qname] = tag # default element
|
| + qnames[qname] = tag # default element
|
| else:
|
| if default_namespace:
|
| raise ValueError(
|
| @@ -273,14 +244,14 @@ def _namespaces(elem, default_namespace=None):
|
| "default_namespace option"
|
| )
|
| qnames[qname] = qname
|
| - except TypeError:
|
| + except TypeError: # pragma: no cover
|
| _raise_serialization_error(qname)
|
|
|
| # populate qname and namespaces table
|
| try:
|
| iterate = elem.iter
|
| except AttributeError:
|
| - iterate = elem.getiterator # cET compatibility
|
| + iterate = elem.getiterator # cET compatibility
|
| for elem in iterate():
|
| tag = elem.tag
|
| if isinstance(tag, QName) and tag.text not in qnames:
|
| @@ -302,8 +273,10 @@ def _namespaces(elem, default_namespace=None):
|
| add_qname(text.text)
|
| return qnames, namespaces
|
|
|
| +
|
| def to_html_string(element):
|
| return _write_html(ElementTree(element).getroot(), format="html")
|
|
|
| +
|
| def to_xhtml_string(element):
|
| return _write_html(ElementTree(element).getroot(), format="xhtml")
|
|
|