Reputation: 468
I am using pygments to highlight some syntax in a jupyter notebook. Here a minimal code to reproduce the issue:
from IPython.display import display, HTML
from pygments import highlight
from pygments.lexers import SqlLexer
from pygments.formatters import HtmlFormatter
from helpers.mystyle import GhDarkStyle
fmtter = HtmlFormatter(style=GhDarkStyle)
query = """
SELECT
*
FROM
latest.tmp
"""
display(
HTML(
'<style type="text/css">{}</style> {}'.format(
fmtter.get_style_defs(".highlight"), highlight(query, SqlLexer(), fmtter)
)
)
)
the style I use is just a copy from the official pygments repo (https://github.com/pygments/pygments/blob/master/pygments/styles/gh_dark.py) in order to have better control on the elements.
The output of the display is correct running the code in a classical jupyter notebook:
but it fails within jupyter lab:
I am not an expert with css, so it is not clear to me where the error comes from (either jupyter-lab or pygments). Investigating a bit, I find that if I explicitly add the highligh attribute to the single <span>
classes generated from the highlight
function, at least I get to show a different color for the line background:
which however is suboptimal in my opinion.
I use:
Upvotes: 0
Views: 705