You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IPythonTracebackLexer errors on back ticks in the presence of line-breaks #14142
We've run into this error when rendering notebooks in sphinx documentation via myst-nb. Error messages that include line-breaks and backticks lead to failed code highlighting. The result is a sphinx warning, which in our build configuration leads to a build failure.
Minimal reproduction:
frompygmentsimporthighlightfromIPython.lib.lexersimportIPythonTracebackLexerfrompygments.formattersimportHtmlFormatterfrompygments.filtersimportRaiseOnErrorTokenFiltercode="TypeError: `foo` is deprecated.\nUse `bar` instead."lexer=IPythonTracebackLexer(filters=[RaiseOnErrorTokenFilter()])
print(highlight(code, lexer, HtmlFormatter()))
---------------------------------------------------------------------------
ErrorToken Traceback (most recent call last)
[<ipython-input-3-c8ff8ce8d25e>](https://localhost:8080/#) in <cell line: 8>()
6 code ="TypeError: `foo` is deprecated.\nUse `bar` instead."7 lexer = IPythonTracebackLexer(filters=[RaiseOnErrorTokenFilter()])
----> 8 print(highlight(code, lexer, HtmlFormatter()))
8 frames
[/usr/local/lib/python3.10/dist-packages/pygments/filters/__init__.py](https://localhost:8080/#) in filter(self, lexer, stream)
783for ttype, value in stream:
784if ttype is Error:
--> 785 raise self.exception(value)
786yield ttype, value
787ErrorToken: `
By contrast, the standard PythonTracebackLexer does not have issues with this:
Activity
matthew-brett commentedon Aug 6, 2026
We ran into the same problem, one potential workaround at matthew-brett/scipy-lecture-notes@5be6ea5 .