Python-Markdown / markdown

A Python implementation of John Gruber’s Markdown with Extension support.
https://python-markdown.github.io/
BSD 3-Clause "New" or "Revised" License
3.74k stars 858 forks source link

codehilite extension: Pygments style only applied to first block #1240

Closed gertvdijk closed 2 years ago

gertvdijk commented 2 years ago

I have tracked down a bug and written a fix for this, wanted to explain the issue in an Issue. PR: https://github.com/Python-Markdown/markdown/pull/1241.

I'm running a small static blog using Pelican, the Elegant theme and I have enabled the Markdown plugin to do code highlighting for me.

My Markdown configuration via Pelican is like this (note 'pygments_style': 'native'):

MARKDOWN = {
            'output_format': 'html5',
            'extension_configs': {
                'markdown.extensions.admonition': {},
                'markdown.extensions.codehilite': {
                                                   'css_class': 'highlight',
                                                   'noclasses': True,
                                                   'pygments_style': 'native',
                                                  },
                'markdown.extensions.extra': {},
                'markdown.extensions.meta': {},
                # Enable permalink on headings.
                # Note: value set to a space, so that the symbol doesn't become
                # part of the RSS feed as per recommendation.
                # https://elegant.oncrashreboot.com/permalinks-to-headings
                'markdown.extensions.toc': {'permalink': ' '},
            },
           }

With the upgrade of the Markdown package from 3.2.2 to 3.3.any, the highlighting of any subsequent blocks after the first would be 'default' instead of 'native': 🤔

Screenshot_20220402_001102

The commit 10058fae6577e79b786f4e185218aebb1b53e937 (_Refactor fencedcode & codehilite options) seems to have introduced a 'pop' rather than proper 'get' from the local configuration in the sequence of blocks, resulting in this behaviour.

https://github.com/Python-Markdown/markdown/blob/383de86c64101b8d14768d9a247c9efc97d703bd/markdown/extensions/codehilite.py#L238-L245