diff options
author | Waylan Limberg <waylan.limberg@icloud.com> | 2018-07-31 14:12:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-31 14:12:49 -0400 |
commit | 1e7fd3f236f63f9ca9b85de9cd172b77e7f9be80 (patch) | |
tree | 480f31abf71a8c205d04f961478fd579680b570f /markdown/core.py | |
parent | 7dad12c07e3e701da42474696398cb32e5c9979f (diff) | |
download | markdown-1e7fd3f236f63f9ca9b85de9cd172b77e7f9be80.tar.gz markdown-1e7fd3f236f63f9ca9b85de9cd172b77e7f9be80.tar.bz2 markdown-1e7fd3f236f63f9ca9b85de9cd172b77e7f9be80.zip |
Move isBlockLevel to class. (#693)
Allows users and/or extensions to alter the list of block level
elements. The old implementation remains with a DeprecationWarning.
Fixes #575.
Diffstat (limited to 'markdown/core.py')
-rw-r--r-- | markdown/core.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/markdown/core.py b/markdown/core.py index 98c9252..f2bd2fb 100644 --- a/markdown/core.py +++ b/markdown/core.py @@ -52,6 +52,18 @@ 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. @@ -207,6 +219,13 @@ class Markdown(object): raise return self + def is_block_level(self, tag): + """Check if the tag is a block level HTML tag.""" + if isinstance(tag, util.string_type): + return tag.lower().rstrip('/') in self.block_level_elements + # Some ElementTree tags are not strings, so return False. + return False + def convert(self, source): """ Convert markdown to serialized XHTML or HTML. |