summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfacelessuser <faceless.shop@gmail.com>2018-10-09 08:54:09 -0600
committerWaylan Limberg <waylan.limberg@icloud.com>2018-10-09 11:15:46 -0400
commit042bd0b10ee3f334e385db7bde5c53d847549e38 (patch)
tree51db88563bd911a052d162166ff15b384cb75811
parent908bd07618cec8b63a64f74e50dadb450715832b (diff)
downloadpython-markdown-042bd0b10ee3f334e385db7bde5c53d847549e38.tar.gz
Ensure block elements are defined per instance
Block level elements should be defined per instance, not as base class variables.
-rw-r--r--markdown/core.py24
-rw-r--r--tests/test_apis.py12
2 files changed, 24 insertions, 12 deletions
diff --git a/markdown/core.py b/markdown/core.py
index f2bd2fb..1c02580 100644
--- a/markdown/core.py
+++ b/markdown/core.py
@@ -52,18 +52,6 @@ class Markdown(object):
'xhtml': to_xhtml_string,
}
- block_level_elements = [
- # Elements which are invalid to wrap in a `<p>` tag.
- # See http://w3c.github.io/html/grouping-content.html#the-p-element
- 'address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl',
- 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3',
- 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'menu', 'nav', 'ol', 'p', 'pre',
- 'section', 'table', 'ul',
- # Other elements which Markdown should not be mucking up the contents of.
- 'canvas', 'dd', 'dt', 'group', 'iframe', 'li', 'math', 'noscript', 'output',
- 'progress', 'script', 'style', 'tbody', 'td', 'th', 'thead', 'tr', 'video'
- ]
-
def __init__(self, **kwargs):
"""
Creates a new Markdown instance.
@@ -88,6 +76,18 @@ class Markdown(object):
self.ESCAPED_CHARS = ['\\', '`', '*', '_', '{', '}', '[', ']',
'(', ')', '>', '#', '+', '-', '.', '!']
+ self.block_level_elements = [
+ # Elements which are invalid to wrap in a `<p>` tag.
+ # See http://w3c.github.io/html/grouping-content.html#the-p-element
+ 'address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl',
+ 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3',
+ 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'menu', 'nav', 'ol', 'p', 'pre',
+ 'section', 'table', 'ul',
+ # Other elements which Markdown should not be mucking up the contents of.
+ 'canvas', 'dd', 'dt', 'group', 'iframe', 'li', 'math', 'noscript', 'output',
+ 'progress', 'script', 'style', 'tbody', 'td', 'th', 'thead', 'tr', 'video'
+ ]
+
self.registeredExtensions = []
self.docType = ""
self.stripTopLevelTags = True
diff --git a/tests/test_apis.py b/tests/test_apis.py
index 71a8555..20144e4 100644
--- a/tests/test_apis.py
+++ b/tests/test_apis.py
@@ -942,6 +942,18 @@ class TestEscapeAppend(unittest.TestCase):
self.assertEqual('|' not in md2.ESCAPED_CHARS, True)
+class TestBlockAppend(unittest.TestCase):
+ """ Tests block kHTML append. """
+
+ def testBlockAppend(self):
+ """ Test that appended escapes are only in the current instance. """
+ md = markdown.Markdown()
+ md.block_level_elements.append('test')
+ self.assertEqual('test' in md.block_level_elements, True)
+ md2 = markdown.Markdown()
+ self.assertEqual('test' not in md2.block_level_elements, True)
+
+
class TestAncestorExclusion(unittest.TestCase):
""" Tests exclusion of tags in ancestor list. """