Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with highlight.js and Bootstrap

Here is the HTML, pretty straight forward:

<script>hljs.initHighlightingOnLoad();</script>
<div class="container">
    <section>
        <pre>
            <code>
                function() {
                    console.log("test");
                }
            </code>
        </pre>
    </section>
</div>

And I tried some CSS, but it didn't change anything:

code {
    text-align: left;
}
pre {
    padding-top: 0;
    padding-bottom: 0;
}

You can see how it looks like in this fiddle. I want the code on the left, and what is up that giant padding between the top <pre> and <code>? Thanks!
UPDATE: Here is a working version, although the HTML doesn't look too good. Does anyone have a better idea?

like image 606
Gofilord Avatar asked Jun 19 '14 19:06

Gofilord


People also ask

What is the use of highlight js?

Highlight. js tries to automatically detect the language of a code fragment. The heuristics is essentially simple: it tries to highlight a fragment with all the language definitions and the one that yields most specific modes and keywords wins.

What is highlight pack js?

Highlight. js is a syntax highlighter written in JavaScript. It works in the browser as well as on the server. It works with pretty much any markup, doesn't depend on any framework and has automatic language detection.


1 Answers

This is because of the pre tag. It takes the given content as preformatted. This means it shows the tabs and spaces the way they are used in your document. Remove the tabs and spaces in front of your JS code and it works fine.

<pre>
// code example goes here without any indentation
</pre>
like image 157
shadowhorst Avatar answered Sep 29 '22 08:09

shadowhorst