Closed santiagobasulto closed 4 years ago
Please see this (oldish and still open) pull request from Pygments. The builtin codehilite
extension uses pygments when available, and pygments' default HTML formater adds no <code>
tag – according to the linked PR, this is for CSS theming reasons.
There is actually this pygments stub (search for _wrap_code
, this doc has zero anchors 😠) to add a <code>
block to the HTML formater. Alas, codehilite
gives no control over the instanciation of the pygments formater, so it's not possible to provide this kind of custom subclass.
As a result, this behavior has actually nothing to do with py-gfm (this stub uses no py-gfm code):
>>> source = """
#!python
print("Hello world")
"""
>>> markdown.markdown(source, extensions=[])
'<pre><code>#!python\nprint("Hello World")\n</code></pre>'
>>> markdown.markdown(source, extensions=[CodeHiliteExtension(use_pygments=False)])
'<pre class="codehilite"><code class="language-python linenums">print("Hello World")</code></pre>'
>>> markdown.markdown(source, extensions=[CodeHiliteExtension()])
# no <code>!
'<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="codehilite"><pre><span></span><span class="k">print</span><span class="p">(</span><span class="s2">"Hello World"</span><span class="p">)</span>\n</pre></div>\n</td></tr></table>'
I am not sure what to do about that. Adding an option to toggle <code>
would mean I have to ship a custom version of codehilite
, which is overkill. For the moment I prefer to keep this behavior, which is pygments' default. Further feedback & ideas are of course welcome, ping @santiagobasulto.
Hi, I had a look at the linked ticket and it looks like this may have been fixed in pygments - https://bitbucket.org/birkenfeld/pygments-main/pull-requests/438/add-a-tag-to-preformatted-code-blocks-in/diff
so may be worth revisiting this ticket.
Cheers S
I believe this is fixed in the just-released 1.0.0 revision.
According to the HTML5 spec the correct way to markup code blocks is with the
<code>
tag. Markdown correctly respects that, as you can see in this example:But py-gfm doesnt. Example using same source:
Produces this output: