Linux (28) Python (13) Raspberry Pi (5) Bugs (3) Install (3) C (2) Brainf**k (1) HTML (1) Maths (1) Sorts (1)

Monday, 29 May 2017

How to format code within web pages

When displaying code within web pages it can be hard to read if it hasn't been separated from the other text and images on the page. To get around this problem I use the google code-prettify JavaScript.
This allows code to be displayed like this:
echo "Hello, World!"

To implement this within your HTML you need to add the following lines of HTML:
At the start of your page:

<script src="

Then whenever you want to display code:

<pre class="prettyprint">
echo "Hello, World!"

No comments:

Post a comment