Skip to content

Option to skip adding <pre><code> to highlighted code #256

Description

@andersk

Context

When using the highlight option to provide a custom syntax highlighter, markdown-it-py wraps the HTML output of the highlighter in <pre><code> unless it already starts with <pre:

if highlighted.startswith("<pre"):

But that heuristic fails for pygments.highlight, whose output does not begin with <pre:

>>> pygments.highlight('print("hello")', pygments.lexers.get_lexer_by_name("python"), pygments.formatters.HtmlFormatter())
'<div class="highlight"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;hello&quot;</span><span class="p">)</span>\n</pre></div>\n'

So markdown-it-py turns this into <pre><code><div class="highlight"><pre>…</pre></div></code></pre>, and existing CSS themes for Pygments need to be rewritten to account for the unnecessarily duplicated <pre>.

Proposal

Can we have an option to skip adding <pre><code> that’s not subject to the heuristic?

Tasks and updates

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions