How to change the style of code block of pygments in ui.markdown? #1189
Replies: 2 comments 3 replies
-
Updates Tried with |
Beta Was this translation helpful? Give feedback.
-
Hi @jiangyipeng718! There might be a problem with the markdown element overwriting the style definition. But this is working for me: ui.add_head_html(f'<style>{HtmlFormatter(nobackground=False, style="perldoc").get_style_defs(".codehilite")}</style>')
ui.markdown('```py\nprint("Hello World!")```') You can also add the style definition to the markdown props. This avoids conflicting definitions: m = ui.markdown('```py\nprint("Hello World!")```')
m._props['codehilite_css'] = HtmlFormatter(nobackground=False, style='murphy').get_style_defs('.codehilite') And note that there's a second definition for dark mode. To change both, you either need to add them both to head HTML ui.add_head_html(f'<style>{HtmlFormatter(nobackground=False, style="perldoc").get_style_defs(".codehilite")}</style>')
ui.add_head_html(f'<style>{HtmlFormatter(nobackground=False, style="monokai").get_style_defs(".body--dark .codehilite")}</style>') or add them both to the props dictionary: m._props['codehilite_css'] = (
HtmlFormatter(nobackground=False, style='murphy').get_style_defs('.codehilite') +
HtmlFormatter(nobackground=False, style='monokai').get_style_defs('.body--dark .codehilite')
) I guess we should provide a simpler way for changing the theme for code blocks... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I have a code block which I want to dispaly in ui.markdown. After I read the pygments documentation, there are several built in styles to choose. However, I am not able to find a way to specify the style in ui.markdown. Any suggestions?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions