Is there a way to specify a different pygments style per language? #1971
-
Hello there, First, thank you very much for your awesome work. I have a markdown document where I have different language codeblocks. I would love to have the possibility to have different pygments styles for each language. I tried this: html_content = markdown.markdown(
content,
extensions=extras_markdown,
extension_configs={
"pymdownx.superfences": {
# ...
},
"pymdownx.highlight": {
"noclasses": True,
"extend_pygments_lang": [
{
"name": "php",
"lang": "php",
"options": {
"startinline": True,
"style": "monokai",
},
},
{
"name": "python",
"lang": "python",
"options": {
"style": "nord",
},
},
],
},
},
) But no luck. If I do this: html_content = markdown.markdown(
content,
extensions=extras_markdown,
extension_configs={
"pymdownx.superfences": {
# ...
},
"pymdownx.highlight": {
"noclasses": True,
"pygments_style": "material",
"extend_pygments_lang": [
{
"name": "php",
"lang": "php",
"options": {
"startinline": True,
"style": "monokai",
},
},
{
"name": "python",
"lang": "python",
"options": {
"style": "nord",
},
},
],
},
},
) Then everything is styled with Is there a way to achieve what I want? Thank you very much! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Unfortunately, this is a very niche request. I don't think I've ever been asked this one.
You could provide both CSS files and apply them based on the language class. You can force language class to be assigned to the block by enabling I'm not sure it makes sense to add |
Beta Was this translation helpful? Give feedback.
-
Hi @facelessuser, Thank you very much for your quick and helpful answer. I agree it's a niche request and I'm not surprised it's not a provided option. Thanks to your suggestions and the CSS export I was however able to achieve exactly what I wanted. Thank you again for making my life easier ❤️. Problem solved. |
Beta Was this translation helpful? Give feedback.
Unfortunately, this is a very niche request. I don't think I've ever been asked this one.
options
is more for lexer specific options that pertain to that language lexer specifically. Style is not language specific.You could provide both CSS files and apply them based on the language class. You can force language class to be assigned to the block by enabling
pygments_lang_class
. As you would be attempting to override material, you may have to add some!important
s to your CSS.I'm not sure it makes sense to add
style
to the language-specific options. Adding such a feature would not be a commonly used feature.