Line indents not displaying in code blocks
PhalanxHead opened this issue · 2 comments
Description
When rendering a standard HTML page, any indentation in the code block is removed, and the entire code segment is displayed with the same column index.
In Essence, I expect:
fn main() {
println!("Hello, World!");
if(true) {
println!("It is me!");
}
}
But I'm getting
fn main() {
println!("Hello, World!");
if(true) {
println!("It is me!");
}
}
To Reproduce
Copy the sample at the end into a raw html file and open it in your browser.
Expected behavior
The code block should preserve formatting, including indentation.
Desktop:
- OS: Windows 11
- Browser: Edge, Firefox
- Version: Edge 98.0.1108.62, Firefox 97.0.1
- highlight.js version: 11.4.0
Additional context
Presumably, by putting <code>
segments into a HTML table, it is removing whitespace.
I've edited my code blocks to replace any double spaces with  
, but this is not optimal for copying code back out.
Sample indicating bugged page
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/styles/default.min.css">
<style>
/* for block of numbers */
.hljs-ln-numbers {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
text-align: center;
color: #ccc;
border-right: 1px solid #CCC;
vertical-align: top;
padding-right: 5px;
/* your custom style here */
}
/* for block of code */
.hljs-ln-code {
padding-left: 10px;
}
</style>
</head>
<body>
<main>
<h1>This is a sample document</h1>
<p>This will display the alignment issues</p>
<pre><code>
fn main() {
println!("Hello, World!");
if(true) {
println!("It is me!");
}
}
</code></pre>
</main>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/languages/rust.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js"></script>
<script>
hljs.highlightAll();
hljs.initLineNumbersOnLoad();
</script>
Thanks for the report!
Try to use full described HTML page with <!DOCTYPE html>
& <html>
.
The example above works in any browser:
https://jsbin.com/quhubay/edit?html,output
Oh wow I feel like such a noob 🤣
Can you tell I'm usually a backend developer? :p