0

I'm really new to web development and I'm kind of lost here.

I'm using Bootstrap, and I'm trying to display java code (in a file called test.java) that's on my local machine on the webpage. The file is displayed, but it doesn't get syntax coloured. Please help!

I have in the header:

for prettify:

<link rel="stylesheet" type="text/css" href="../localfile/prettify.css"/>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
<script src="../localfile/prettify.js"></script>

and for jQuery:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

And this is the script

<script type="text/javascript">
 $(document).ready(function() {
     jQuery(function($) {
         $.get('test.java', function(data) {
             $('#sourceCodeDestination').html(data);
             prettyPrint();
         }, "text");
     });
 });
</script>

and this for the div:

<div class="panel-body" >
       <pre id="sourceCodeDestination" class="prettyprint linenums lang-java">
        </pre>
</div>
wirey00
  • 33,517
  • 7
  • 54
  • 65
  • `$.get` wont work on the local file system, you need a web server setup – tymeJV Oct 01 '14 at 21:02
  • I looked around and found that it could work on Firefox. It does display the file content, but the problem is that it's not syntax coloured. – aalbert3234 Oct 01 '14 at 21:17
  • not an answer but `$(document).ready(function() ` and `jQuery(function ($) {` pretty much mean the same thing – wirey00 Oct 01 '14 at 21:22

1 Answers1

0

I finally figured out what the problem was after reading the answer to this question, here.

So, I changed the script to this and it works just fine. I just removed the prettyprinted class before calling prettyPrint.

    <script type="text/javascript">

      jQuery(function ($) {  $.get('test.java', function(data) {
      $('#sourceCodeDestination').html(data);
      $('#sourceCodeDestination').removeClass("prettyprinted");
        prettyPrint();  
    }, "text");
 });

</script>
Community
  • 1
  • 1