Custom raw **HTML** which gets ignored.
**Markdown** content.
title: Markdown in HTML Extension # Markdown in HTML ## Summary An extension that parses Markdown inside of HTML tags. ## Syntax By default, Markdown ignores any content within a raw HTML block-level element. With the `md-in-html` extension enabled, the content of a raw HTML block-level element can be parsed as Markdown by including a `markdown` attribute on the opening tag. The `markdown` attribute will be stripped from the output, while all other attributes will be preserved. The `markdown` attribute can be assigned one of three values: [`"1"`](#1), [`"block"`](#block), or [`"span"`](#span). !!! note The expressions "block-level" and "span-level" as used in this document refer to an element's designation according to the HTML specification. Whereas the `"span"` and `"block"` values assigned to the `markdown` attribute refer to the Markdown parser's behavior. ### `markdown="1"` { #1 } When the `markdown` attribute is set to `"1"`, then the parser will use the default behavior for that specific tag. The following tags have the `block` behavior by default: `article`, `aside`, `blockquote`, `body`, `colgroup`, `details`, `div`, `dl`, `fieldset`, `figcaption`, `figure`, `footer`, `form`, `group`, `header`, `hgroup`, `hr`, `iframe`, `main`, `map`, `menu`, `nav`, `noscript`, `object`, `ol`, `output`, `progress`, `section`, `table`, `tbody`, `tfoot`, `thead`, `tr`, `ul` and `video`. For example, the following: ```
This is a Markdown Paragraph.
This is not a *Markdown* Paragraph.
``` ... is rendered as: ``` htmlThis is not a Markdown Paragraph.
``` ### `markdown="block"` { #block } When the `markdown` attribute is set to `"block"`, then the parser will force the `block` behavior on the contents of the element so long as it is one of the `block` or `span` tags. The content of a `block` element is parsed into block-level content. In other words, the text is rendered as paragraphs, headers, lists, blockquotes, etc. Any inline syntax within those elements is processed as well. For example, the following: ```A Markdown paragraph.
` element to be nested within another `
` element. In most cases it is recommended to use the default behavior of `markdown="1"`. Explicitly setting `markdown="block"` should be reserved for advanced users who understand the HTML specification and how browsers parse and render HTML. ### `markdown="span"` { #span } When the `markdown` attribute is set to `"span"`, then the parser will force the `span` behavior on the contents of the element so long as it is one of the `block` or `span` tags. The content of a `span` element is not parsed into block-level content. In other words, the content will not be rendered as paragraphs, headers, etc. Only inline syntax will be rendered, such as links, strong, emphasis, etc. For example, the following: ```
Custom raw **HTML** which gets ignored.
**Markdown** content.
A Markdown paragraph.
Custom raw **HTML** which gets ignored.
Markdown content.
A Markdown paragraph with *no* closing tag.
A raw paragraph with *no* closing tag.
A Markdown paragraph with no closing tag.
A raw paragraph with *no* closing tag.
` tag ends when another `
` tag begins or when the parent element ends. In both cases, a closing `
` was added to the end of the element, regardless of whether a `markdown` attribute was assigned to the element. To avoid any normalization, an element must not be a descendant of any block-level element which has a `markdown` attribute defined. !!! warning The normalization behavior is only documented here so that document authors are not surprised when their carefully crafted raw HTML is altered by Markdown. This extension should not be relied on to normalize and generate valid HTML. For the best results, always include valid raw HTML (with both opening and closing tags) in your Markdown documents. ## Usage From the Python interpreter: ``` pycon >>> import markdown >>> html = markdown.markdown(text, extensions=['md_in_html']) ```