-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Highlight.js strips whitespace in pre tag #3593
Comments
It's the APIs you are using. Use textContent instead of innerText. |
using textContent preserves spaces but still strips newlines. |
Please provide a jsfiddle demonstrating this and I will review. If your taking HTML out of another element you'll be responsible for doing any work necessary for preserving breaks, etc - such as possibly converting BR tags into new lines. Highlight.js merely requests the textContent property, which does not render HTML to white space. It silently drops HTML. |
Unfortunately JSFiddle does not support Kotlin/JS, so that's impossible... |
It does not - IF they are textual ( |
We are a pure JS library, if there is a bug with the library itself then it should be possible to reproduce it with just JS (and JSFiddle) - no need for Kotlin. But as mentioned, I think you're seeing the expected behavior here... |
Closing until a test JSFiddle case can be provided. Right now this sounds like expected behavior that can be resolved by using clean text (no HTML) inside the block and using the If you truly need BR, consider the use of a plugin or manually replacing the |
Describe the issue/behavior that seems buggy
When calling hljs.highlightElement, it strips all whitespace.
Sample Code or Instructions to Reproduce
Expected behavior
Highlight.js correctly keeps spaces.
Additional context
Disabling highlighting preserves spaces.
The text was updated successfully, but these errors were encountered: