diff options
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. |