Search code examples
javascriptcsspretty-print

Simple prettyprint program not working


I am trying to use prettyprint to format the UI of my code but I am not getting any formatting done.

HTML:

<html>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css" rel="stylesheet">
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
</head>
<body onload="prettyPrint()">   
<pre class="prettyprint">   
  &lt;div&gt; This is a div &lt;/div&gt;   
  &lt;a href="http://www.google.com"&gt;Bollywood &lt;/a &gt;   
</pre>  
</body>
</html>

References:

  1. https://github.com/google/code-prettify
  2. https://github.com/google/code-prettify/blob/master/docs/getting_started.md
  3. https://rawgit.com/google/code-prettify/master/styles/index.html

Can someone please help me out?

I want the default layout in the 3rd link provided. 

Solution

  • Try this:

    <html>
    <head>
      <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css">
      <style type="text/css"></style><link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/google/code-prettify/master/loader/prettify.css">
    </head>
    <body>
    
      <pre class="prettyprint linenums">
        &lt;div&gt; This is a div &lt;/div&gt;   
        &lt;a href="http://www.google.com"&gt;Bollywood &lt;/a &gt;   
      </pre>
    
    </body>
    </html>
    

    An online demo is available here.

    The desired theme must be included as a css file (for example, this css file).