facelessuser / pymdown-extensions

Extensions for Python Markdown
https://facelessuser.github.io/pymdown-extensions/
Other
951 stars 253 forks source link

Styling information is not being included in html output when using highlight extension with Pygments #2260

Closed Spitfire1900 closed 9 months ago

Spitfire1900 commented 9 months ago

Description

Maybe this is a clone of #2230, but after reading through that I am unable to resolve issues

The following snippet does not produce code with the appropriate styles for syntax highlighting in the source.

The html references classes, but no <style> tag or inline style is included in the output.

<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">foo.bar</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;hello world!&quot;</span><span class="p">)</span>
</code></pre></div>

Minimal Reproduction

Run the following code with required extensions installed. (Code is tabbed over to manage ``` escaping issues.)

    import pathlib

    import markdown

    MD = """
    ```python
    import foo.bar
    print("hello world!")
"""

html = markdown.markdown(
    MD,
    extensions=[
        "pymdownx.highlight",
        "pymdownx.superfences",
    ],
)

pathlib.Path('2230.html').write_text(html)


### Version(s) & System Info

- Operating System: Windows 10
- Python Version: 3.11
- Package Version: 
    markdown           3.5.1
    pymdown-extensions 10.5
    pygments           2.17.2
facelessuser commented 9 months ago

Yes, you need to provide your styling. This is not a bug. We simply process the code, attaching the classes needed to style the content. Pygments can dump CSS for you to include in your documents.

If you want, you can enable noclasses mode via pymdownx.highlight which will attach inline styling to elements. This is a bit heavy, so I would normally opt to getting Pygments to dump the CSS style and use it in your documents, making any adjustments that you'd like to the styling.

Spitfire1900 commented 9 months ago

Thanks, that helped me move forward on this.

html = markdown.markdown(
    MD,
    extensions=[
        "pymdownx.highlight",
        "pymdownx.superfences",
    ],
    extension_config={
        "pymdownx.highlight": {
            "noclasses": True
        },
    },
)