A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Python-Markdown/markdown/issues/1329 below:

admonition extension returns **invalid** html code without blank line. · Issue #1329 · Python-Markdown/markdown · GitHub

In [8]: import markdown
In [9]: some_text = """
   ...: !!! danger "Danger"
   ...:     don't try this at home.
   ...:
   ...: """
In [10]: markdown.markdown(some_text, tab_length=2, extensions=['admonition'])
Out[10]: '<div class="admonition danger">\n<p class="admonition-title">Danger<p>don\'t try this at home.</p>\n</p>\n</div>'
  1. A paragraph inside a paragraph is invalid html and etree parser complains!
  2. the simple solution of turning the title paragraph into a div will work, but it wraps the inner paragraph, resulting in a CSS mess.

Recommended working solution:

     CLASSNAME_TITLE = 'admonition-title'
+    CLASSNAME_BODY = 'admonition-body'
     RE = re.compile(r'(?:^|\n)!!! ?([\w\-]+(?: +[\w\-]+)*)(?: +"(.*?)")? *(?:\n|$)')

@@ -130,9 +134,11 @@ class AdmonitionProcessor(BlockProcessor):
             div = etree.SubElement(parent, 'div')
             div.set('class', '{} {}'.format(self.CLASSNAME, klass))
             if title:
-                p = etree.SubElement(div, 'p')
+                p = etree.SubElement(div, 'div')
                 p.text = title
                 p.set('class', self.CLASSNAME_TITLE)
+                p = etree.SubElement(div, 'div')
+                p.set('class', self.CLASSNAME_BODY)

Note: the parse_content() method of your admonition extension is an unreadable code-mess ;-)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4