<pre> line breaks get deleted when calling prism.highlightElement(code)
See original GitHub issueI set up my HTML using the following snippet:
<div>
<pre><code class=" language-js" contenteditable="true"></code></pre>
</div>
When I call prism.highlightElement(code);
from the following TypeScript snippet:
import * as prism from "prismjs";
const code: HTMLElement = document.getElementsByTagName("code")[0];
prism.highlightElement(code);
… all line breaks in the <code>
element get deleted when calling prism.highlightElement(code)
.
The result is that all code is getting displayed in a single line then:
before
after
I believe this is not supposed to happen?
Issue Analytics
- State:
- Created 5 years ago
- Comments:19 (8 by maintainers)
Top Results From Across the Web
PrismJS no line breaks - javascript - Stack Overflow
Not sure if anyone has come across this. I'm using PrismJS syntax highlighter to highlight code. Application is ...
Read more >Trouble formating <pre> using Prism in Gatsby - Prismic People
gatsby-remark-prismjs Adds syntax highlighting to code blocks in markdown files using ... <pre> line breaks get deleted when calling prism.
Read more >Prism
Adds special CSS classes for each keyword for fine-grained highlighting. Remove initial line feed. Removes the initial line feed in code blocks. Inline...
Read more >Prism - GitHub Pages
Dead simple Include prism.css and prism.js, use proper HTML5 code tags ... highlightElement: function(element, async, callback) { // Find language var ...
Read more >[Solved]-PrismJS no line breaks-Reactjs - appsloveworld
css file to using white-space: pre-wrap like this: Prism.plugins.NormalizeWhitespace.setDefaults({ 'remove-trailing': true, 'remove-indent': true, 'left-trim ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The hook appears to be incorrect. The correct hook name is:
before-highlight
innerText
has a few other properties which make it less useful for Prism. It would also change the current behavior of Prism, so for some people out there, this might be a breaking change.Also, you can use hooks to make Prism use
innerText
.