Highlight.js on Blogger wraps code lines automatically
See original GitHub issueAt the moment I’m facing an issue integrating highlight.js with Blogger. The syntax highlight works great, but the text lines inside the pre/code
tags are auto wrapping. Is this the intended behavior? If yes, can we have an option to show a horizontal scroll bar instead? Looking at the demo page I can see that some examples have a scroll bar, so I’m guessing this is a problem with Blogger instead.
I have also opened a StackOverflow question about this, so far unanswered.
Following is a screenshot of the problem I’m facing. As you can see, the code gets quite unreadable with the line wrapping:
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Highlight.js with Blogger: can't disable auto line wrap
So far, the syntax highlighting works great, but I can't seem to find a way of preventing the code lines inside the <pre><code>...
Read more >How to use highlight.js
The bare minimum to auto-detect the language and highlight some code. ... We strongly recommend <pre><code> wrapping for code blocks.
Read more >How to Add Code Syntax Highlighting to Blogger
The highlight.js library lets you set up syntax highlighting on Blogger by adding 3 lines to the header and wrapping code blocks within...
Read more >Code samples with line highlighting · How to build
For simplicity and better performance, our Code component calls highlight.js directly instead of using the automatic detection of code samples ...
Read more >Line numbering plugin for Highlight.js by Yauheni Pakala
<script src="https://cdn.jsdelivr.net/npm/highlightjs-line-numbers.js/dist/highlightjs ... CharBuffer/wrap buf 0 s)))) ... for (auto i = 0; i < 0xFFFF; i++).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop 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
Top GitHub Comments
Ah-ha-ha! Nice! Thanks guys! I do want my code blocks to wrap on Google Blogger, instead of having the scroll-bar, so looking at these posts here I was able to determine I needed to add the following to force it to wrap my code with highlight.js syntax highlighting!
Add this between the
<head> </head>
tags at the top of the blogger theme to affect the whole website, or just to the top of a given blog post to affect that page only:pre-wrap
forces the lines to wrap when necessary, while otherwise preserving code-formatting white-space. See here: https://www.w3schools.com/cssref/pr_text_white-space.asp.Following your suggestion, I did some more fiddling with the CSS and was able to fix the problem by overriding the
.hljs
style, just after including the highlight.js stylesheet. Probably not the only or best fix, but this was the only one I’ve been able to get right. My knowledge of the Blogger API or CSS in general is limited, so the reasons it worked are also not quite clear to me.For future reference, in case you are interested on further investigating the matter to perhaps incorporate that to the library, this is how my highlight.js include is (at the end of
<head>
):Many thanks for the help and for the great work you did in this project. Cheers.