Skip to content
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

Leading whitespace removed in code blocks with syntax highlighting #1021

Open
rikedyp opened this issue Oct 4, 2022 · 2 comments · May be fixed by jupyter/nbconvert#2203
Open

Leading whitespace removed in code blocks with syntax highlighting #1021

rikedyp opened this issue Oct 4, 2022 · 2 comments · May be fixed by jupyter/nbconvert#2203

Comments

@rikedyp
Copy link

rikedyp commented Oct 4, 2022

Leading whitespaces in codeblocks are removed if syntax highlighting is done. Seemingly regardless of the language used. It is common to want 6 spaces denoting input lines in APL. However, if I use APL syntax highlighting, these spaces are removed. Non-breaking spaces or additional newlines do not help.

Here is a test notebook rendered with nbviewer: https://nbviewer.org/gist/rikedyp/59230d88565c3459d88230b8f2e3c256

And source as a GitHub gist: https://gist.github.com/rikedyp/59230d88565c3459d88230b8f2e3c256

@peytondmurray
Copy link

peytondmurray commented Jan 1, 2025

I'm taking a look at this now. It seems like this is likely an issue with the html output of nbconvert. Here's the same notebook converted to PDF, with the spaces preserved as expected:

Image

Confirmed this is not a problem with mistune itself (both code blocks correctly preserve whitespace whether they use apl syntax highlighting or not):

Image

@peytondmurray
Copy link

I tracked this down to an option to strip the input when the lexer is initialized in nbconvert. It's been this way for at least the last 10 years, potentially since the beginning, but I'm not sure if it's needed. Anyway, there's a PR up for this here: jupyter/nbconvert#2203.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants