How do I get an empty tag using markdown.extensions.attr_list?

I am trying to add microdata to my generated HTML and found the attr_list extension . He does almost everything I need.

Here's some sample code I'm using:

>>> text = """This is a paragraph.
... {: itemscope itemtype="http://schema.org/Movie"}
... """
>>> markdown.markdown(text, extensions=['markdown.extensions.attr_list'])
u'<p itemscope="itemscope" itemtype="http://schema.org/Movie">This is a paragraph.</p>'

      

The only problem I am facing is this itemscope="itemscope"

. According to the examples provided by schema.org, it should be simple:

<p itemscope itemtype="http://schema.org/Movie">This is a paragraph.</p>

      

The closest I got

text = """This is a paragraph.
... {: itemscope="" itemtype="http://schema.org/Movie"}
... """

      

Which generates output as

u'<p itemscope="" itemtype="http://schema.org/Movie">This is a paragraph.</p>'

      

Is there a way to keep this as an open tag (just itemscope

no equals) using this extension?

+3


source to share


1 answer


Use html

output_format (which you probably want anyway) rather than the default xhtml

:

t = """This is a paragraph.
... { itemscope itemtype="http://schema.org/Movie"}
... """
>>> markdown.markdown(t, extensions=['attr_list'], output_format="html")
u'<p itemscope itemtype="http://schema.org/Movie">This is a paragraph.</p>'

      

Since Markdown was first developed when XHTML got hot, the rules and reference implementation expect a formatted XHTML result. Since Python-Markdown is an old school Markdown parser, it also uses XHTML as the default output format by default (since the XHTML spec simply refers to the HTML4 spec , see this for details).



The html

non-default output format has been more recently updated for HTML5 output and uses the minified form.

By the way, you don't need to include colon in attribute lists (see my example above). More recently, it has become optional for compatibility with other implementations.

+5


source







All Articles