Skip to content

extensions: copy config dict on each highlighted block #1241

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

Merged
merged 1 commit into from
Apr 18, 2022
Merged

extensions: copy config dict on each highlighted block #1241

merged 1 commit into from
Apr 18, 2022

Conversation

gertvdijk
Copy link
Contributor

This fixes a bug where any subsequent highlighted block with codehilite would result in the omission of the style setting, falling back to default.

Fixes #1240

@mitya57
Copy link
Collaborator

mitya57 commented Apr 2, 2022

Can you please add a test for multiple highlighted blocks?

@gertvdijk
Copy link
Contributor Author

@mitya57 Added them to the now amended commit. 😃

@gertvdijk
Copy link
Contributor Author

gertvdijk commented Apr 3, 2022

CI error appears unrelated to my change. 😕

43 files checked.
ERROR: 5 files with dead links found!

@waylan
Copy link
Member

waylan commented Apr 4, 2022

The reason why we pop the setting is because we also pass the rest of the config items on to Pygments (see the very next line). As each of Pygmants' lexers/formatters have a different set of options they accept, we just pass all unknown keywords on. However, there is no need to pass the style on as we have already defined that. The only reason we don't get an error is because Pygments just ignores any unknown keywords passed to its lexers and formatters. Still, it would be best to not pass it on to avoid any weird conflicts in the future.

Perhaps we should be making a copy of the config for each code block and then we can pop the setting off of the copy.

As an aside, we have the pygments_style setting for historical reasons (it existed before we accepted all Pygments options). If we were starting fresh today we would not define a special option for it and users could just use style which would get passed it on with the rest of the Pygments' keyword options. Actually, a user could avoid this bug by using style now (without this fix). That said, we should still fix the bug. Although, we might want to deprecate the pygments_style option as it is duplicative and unnecessary.

@waylan
Copy link
Member

waylan commented Apr 4, 2022

CI error appears unrelated to my change. 😕

43 files checked.
ERROR: 5 files with dead links found!

Yes, I see that. I have opened a separate issue for that in #1243. You can ignore that failure here.

@waylan waylan added extension Related to one or more of the included extensions. needs-decision A decision needs to be made regarding request. requires-changes Awaiting updates after a review. labels Apr 4, 2022
@gertvdijk
Copy link
Contributor Author

@waylan Thanks for the explanation! 😃
It took a bit longer to get back to this, but I've pushed an amendment.

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
@gertvdijk gertvdijk changed the title extensions: use get() for getting value of 'pygments_style' extensions: copy config dict on each highlighted block Apr 15, 2022
@waylan waylan added approved The pull request is ready to be merged. and removed needs-decision A decision needs to be made regarding request. requires-changes Awaiting updates after a review. labels Apr 18, 2022
@waylan waylan merged commit ed417a1 into Python-Markdown:master Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved The pull request is ready to be merged. extension Related to one or more of the included extensions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

codehilite extension: Pygments style only applied to first block
3 participants