Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

highlight.js inline mode possible?

I was able to make a code-block with highlight.js like this:

<pre>
  <code class="haskell">
    {-# OPTIONS_GHC -Wall #-}
    euclid :: Int -> Int -> Int
    euclid a b
      | a == 0    = b
      | b == 0    = a
      | a > b     = euclid (a-b) b
      | otherwise = euclid a (b-a)
  </code>
</pre>

Works fine! But now I also want to have some code lines in my text, inline. Like this:

<p> Info text inline code testing <code class="haskell">{-# OPTIONS_GHC -Wall #-}</code> maybe it works</p>

Doesn't work... You can check them out at my Site

How to make inline code with highlight.js ?

like image 529
Martin Fischer Avatar asked Sep 27 '15 21:09

Martin Fischer


People also ask

How do you highlight in Javascript?

js code to highlight the text. There are many built-in functions in mark. js but we are using two functions for our requirement that is mark() and unmark() function respectively. Here mark() is used to highlight the search text and unmark() is used to remove highlighting the text that is highlighted before.

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.


1 Answers

You just need a little CSS to make it inline. How you do it is up to you, but you could make it inline if it's within a p tag.

p > code.hljs { display: inline; }

Example: https://jsfiddle.net/ykyLcvnw/1/

like image 180
Tom Bowers Avatar answered Sep 21 '22 13:09

Tom Bowers