Make sure the links are not correct locally

I'm having trouble getting Google Code Prettify to work properly. This example works using the provided remote files:

<html> <head> <title>Google Code Prettify testing</title> <script data-brackets-id='140' src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"> </script> </head> <body> <h1>Google Code Prettify testing</h1> <pre class="prettyprint" style="font-size: 12pt;"> &lt;script type="text/javascript"&gt; // This is a comment var myString = "Hello, World!"; var myInt = 42; function helloWorld(world) { for (var myInt; --myInt &gt;= 0;) { alert(myString); } } &lt;/script&gt; &lt;style&gt; p { color: pink } b { color: blue } u { color: "umber" } &lt;/style&gt; </pre> </body> </html> 

Result:

prettify-testing1

This comes from remote Prettify hosting. Note that some elements in <script> are for styling and behavior only. The following works fine:

 <html> <head> <title>Prettify Default Test</title> <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script> </head> 

It just displays the default appearance and behavior (note that this is a different browser)

prettify-testing5


However, when I downloaded and saved the files locally, I write this:

 <html> <head> <title>Google Code Prettify testing</title> <link href="google-code-prettify/src/prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="google-code-prettify/js-modules/run_prettify.js"></script> </head> <body onload="prettyPrint()"> <h1>Google Code Prettify testing</h1> <pre class="prettyprint" style="font-size: 12pt;"> &lt;script type="text/javascript"&gt; // This is a comment var myString = "Hello, World!"; var myInt = 42; function helloWorld(world) { for (var myInt; --i &gt;= 0;) { alert('Hello ' + String(world)); } } &lt;/script&gt; &lt;style&gt; p { color: pink } b { color: blue } u { color: "umber" } &lt;/style&gt; </pre> </body> </html> 

And, as follows, none of the formatting is portable:

prettify-testing2

Below is a snapshot of the folder structure. I checked to be sure that it was exactly specified in the code ...

prettify.css

prettify-testing3

run_prettify.js

prettify-testing4

Can you offer any advice as to why he is acting this way?

+6
source share
1 answer

The reason your formatting doesn't work is because you have the wrong path for the run_prettify.js file. You have all your prettify files stored in google-code-prettify / src /, while you are trying to establish a link to which does not exist, for example js-modules.

I tested this locally, using the exact source that you provided with the same folder structure to replicate your environment, and came up with the same result when formatting only black font. As soon as I changed it to "google-code-prettify / src /", it worked fine.

Again, to fix this, change the path:

 <script type="text/javascript" src="google-code-prettify/js-modules/run_prettify.js"></script> 

to

 <script type="text/javascript" src="google-code-prettify/src/run_prettify.js"></script> 

The only problem you may encounter is that some browsers (especially IE) may block the display of certain content in your browser. If you are on a network that forcibly blocks certain content from displaying or requesting permission before displaying blocked content, you may need to select โ€œShow blocked contentโ€ or something similar before it shows how you want.

Hope this helps!

EDIT: This is not necessary for you - but it can help other members of the community with a similar situation, but I decided that I also refer to the Getting Started section, which refers to the requirements for servicing your own JS and CSS files, as well as ways to start and run.

https://code.google.com/p/google-code-prettif/wiki/GettingStarted#Serving_your_own_JS_&_CSS

+3
source

Source: https://habr.com/ru/post/980900/


All Articles