Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Customizing highlight.js

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #205075
    inktrap
    Participant

    Hi, guys. I don’t know the first thing about javascript and need some help. Could somebody please take a look at
    https://highlightjs.org/usage/ and http://highlightjs.readthedocs.org/en/latest/api.html and tell me what kind of script I need to make it work on inline code tags?

    #205080
    nkrisc
    Participant

    What isn’t working? According to the instructions it will find any code in <pre><code></code></pre> tags.

    Did you follow the instructions and include it?

    <link rel="stylesheet" href="/path/to/styles/default.css">
    <script src="/path/to/highlight.pack.js"></script>
    <script>hljs.initHighlightingOnLoad();</script>
    
    #205081
    inktrap
    Participant

    I’d like it to work on &lt;code&gt; alone so I can highlight inline snippets of code.
    The documentation clearly says that it’s possible to use any tags instead of &lt;pre&gt;&lt;code&gt;.

    #205090
    nkrisc
    Participant

    You mean like this?

    http://codepen.io/nkrisc/pen/XbYoBx

    I don’t know if there’s a better way to do this with the library but I’m not going to look through all the documentation.

    #205124
    inktrap
    Participant

    And where do I put it? Right now I have this in my header, like the example on their site

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/github.min.css"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/highlight.min.js"></script>
    <script>hljs.initHighlightingOnLoad();</script>
    
    #205130
    nkrisc
    Participant

    You’ll need to make sure all code tags are rendered before it runs so either put it at the end of the body or in the head but wrapped to make sure the DOM is ready.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.