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
?
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.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With