Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a simple example with highlight.js?

I am trying to make a simple example with highlight.js but I can not make it work. I am not familiar with highlight.js. Here is my code and I dont know what`s wrong in it. Any idea! Thanks in advance.

<!DOCTYPE html>
<head>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/styles/default.min.css">
<script src="https://code.jquery.com/jquery-2.2.2.min.js" integrity="sha256-36cp2Co+/62rEAAYHLmRCPIych47CvdM+uTBJwSzWjI=" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/highlight.min.js"></script>
<script type='text/javascript'>
hljs.initHighlightingOnLoad();
$(document).ready(function() {
   $('#myBlock').each(function(i, e) {hljs.highlightBlock(e)});
});
</script>
</head>
<body>
<div id="myBlock">
<pre><code class="php">
require_once 'Zend/Uri/Http.php';

abstract class URI extends BaseURI
{

  /**
   * Returns a URI
   *
   * @return  URI
   */
  static public function _factory($stats = array(), $uri = 'http')
  {
      $uri = explode(':', $uri, 2);
      $schemeSpecific = isset($uri[1]) ? $uri[1] : '';
      $desc = 'Multi
line description';

      // Security check
      if (!ctype_alnum($scheme)) {
          throw new Zend_Uri_Exception('Illegal scheme');
      }

      return [
        'uri' => $uri,
        'value' => null,
      ];
  }
}
</code></pre>
</div>
</body>
</html>
like image 580
Rajmond Burgaj Avatar asked Mar 23 '16 19:03

Rajmond Burgaj


1 Answers

You need to change the way you read the css and javascript files a bit:

The css file:

<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/styles/default.min.css">

The javascript file:

<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/highlight.min.js"></script>

Yes, I know, you used the way it was on the original site, but it seems they made a mistake, when they wrote the example codes.

like image 102
Igorovics Avatar answered Sep 29 '22 06:09

Igorovics