Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gertvdijk opened this issue Apr 1, 2022 · 0 comments · Fixed by #1241
Closed

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

gertvdijk opened this issue Apr 1, 2022 · 0 comments · Fixed by #1241
Labels
bug Bug report. confirmed Confirmed bug report or approved feature request. extension Related to one or more of the included extensions.

Comments

@gertvdijk
Copy link
Contributor

gertvdijk commented Apr 1, 2022

I have tracked down a bug and written a fix for this, wanted to explain the issue in an Issue. PR: #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 10058fa (Refactor fenced_code & 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.

for block in blocks:
if len(block) == 1 and block[0].tag == 'code':
code = CodeHilite(
self.code_unescape(block[0].text),
tab_length=self.md.tab_length,
style=self.config.pop('pygments_style', 'default'),
**self.config
)

@waylan waylan added bug Bug report. extension Related to one or more of the included extensions. confirmed Confirmed bug report or approved feature request. labels Apr 4, 2022
waylan pushed a commit that referenced this issue Apr 18, 2022
This fixes a bug where any subsequent highlighted block with codehilite
would result in the omission of the style setting, because it was popped
off the dict. It would then fall back to pygments_style 'default' after
the first block.

Fixes #1240
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report. confirmed Confirmed bug report or approved feature request. extension Related to one or more of the included extensions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants