21
I use Google Prettify to display mainly HTML, CSS and JavaScript code, that is after all what goes into a website. This however, can be a bit of a problem.
I feel like I’ve been writing this section for ages. You would think there would be hundreds of websites that explained clearly how to do this sort of thing — buggered if I could find ’em though.
After all I’ve written on this subject, this is probably the most useful bit, I just show you how to do it. You get a screen shot, the HTML and a few words for each of the following:
HTML without numbers and no text wrapping (horizontal scrollbars)
HTML with numbers and text wrapping (no scrollbars)
HTML with false numbering and no text wrapping (horizontal scroll bar)
HTML with a fixed height fragment (vertical and horizontal scrolling)
CSS with numbers and no text wrapping
ANSI C
VB
HTML Simple single line code fragment
HTML Simple multi-line fragment
HTML Inline fragment
That should cover it.
Appearance
<nav> <!-- TOP NAVIGATION BAR -->
<div class="top-nav">
<div class="rg-row">
<a class="nav-wide" href="#"><span class="top-nav-icon">l</span><span class="top-nav-text">Prev. section</span></a>
<a class="nav-wide" href="#"><span class="top-nav-icon">u</span><span class="top-nav-text">Prev. chapter</span></a>
<a class="nav-wide nav-home" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a>
<a class="nav-narrow js--sc-top" href="#"><span class="top-nav-icon">t</span><span class="top-nav-text">Top</span></a>
<a class="nav-narrow" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a>
<a class="nav-wide" href="#"><span class="top-nav-text">Next chapter</span><span class="top-nav-icon">d</span></a>
<a class="nav-wide" href="#"><span class="top-nav-text">Next section</span><span class="top-nav-icon">r</span></a>
</div>
</div>
</nav> <!-- END OF TOP NAVIGATION -->
Options
| Options | |||
|---|---|---|---|
<pre class="prettyprint lang-html" id="js--cXX-YY"> |
|||
| Element | Required Class | Function | |
| <pre> | perttyprint | Triggers the Google Prettify software | |
| lang-html | Sets the display language to HTML | ||
Notes
The fragment will be as high as required (depends on content); if any line extends beyond the edge of the code-area container, a horizontal scrollbar will automatically appear.
HTML
<div class="code-extract"> <!-- Start of code fragment --> <div class="code-header">filename.ext</div> <!-- Code file name --> <div class="code-area"> <!-- Start of code extract holder --> <pre class="prettyprint lang-html" id="js--cXX-YY"> <nav> <!-- TOP NAVIGATION BAR --> <div class="top-nav"> <div class="rg-row"> <a class="nav-wide" href="#"><span class="top-nav-icon">l</span><span class="top-nav-text">Prev. section</span></a> <a class="nav-wide" href="#"><span class="top-nav-icon">u</span><span class="top-nav-text">Prev. chapter</span></a> <a class="nav-wide nav-home" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a> <a class="nav-narrow js--sc-top" href="#"><span class="top-nav-icon">t</span><span class="top-nav-text">Top</span></a> <a class="nav-narrow" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a> <a class="nav-wide" href="#"><span class="top-nav-text">Next chapter</span><span class="top-nav-icon">d</span></a> <a class="nav-wide" href="#"><span class="top-nav-text">Next section</span><span class="top-nav-icon">r</span></a> </div> </div> </nav> <!-- END OF TOP NAVIGATION --> </pre> </div> <!-- End of code extract holder --> <div class="code-caption">Code xx.yy   Caption</div> <!-- Code caption --> </div> <!-- End of code fragment -->
Appearance
<nav> <!-- TOP NAVIGATION BAR -->
<div class="top-nav">
<div class="rg-row">
<a class="nav-wide" href="#"><span class="top-nav-icon">l</span><span class="top-nav-text">Prev. section</span></a>
<a class="nav-wide" href="#"><span class="top-nav-icon">u</span><span class="top-nav-text">Prev. chapter</span></a>
<a class="nav-wide nav-home" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a>
<a class="nav-narrow js--sc-top" href="#"><span class="top-nav-icon">t</span><span class="top-nav-text">Top</span></a>
<a class="nav-narrow" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a>
<a class="nav-wide" href="#"><span class="top-nav-text">Next chapter</span><span class="top-nav-icon">d</span></a>
<a class="nav-wide" href="#"><span class="top-nav-text">Next section</span><span class="top-nav-icon">r</span></a>
</div>
</div>
</nav> <!-- END OF TOP NAVIGATION -->
Options
| Options | |||
|---|---|---|---|
<pre class="prettyprint linenums wrap lang-html" id="js--cXX-YY"> |
|||
| Element | Required Class | Function | |
| <pre> | perttyprint | Triggers the Google Prettify software | |
| linenums | Activates automatic line numbering (starts at 1) | ||
| wrap | Turns on text wrapping | ||
| lang-html | Sets the display language to HTML | ||
Notes
The fragment will be as high as required (depends on content); if any line extends beyond the edge of the code-area container, a horizontal scrollbar will automatically appear.
HTML
<div class="code-extract"> <!-- Start of code fragment --> <div class="code-header">filename.ext</div> <!-- Code file name --> <div class="code-area"> <!-- Start of code extract holder --> <pre class="prettyprint linenums wrap lang-html" id="js--cXX-YY"> <nav> <!-- TOP NAVIGATION BAR --> <div class="top-nav"> <div class="rg-row"> <a class="nav-wide" href="#"><span class="top-nav-icon">l</span><span class="top-nav-text">Prev. section</span></a> <a class="nav-wide" href="#"><span class="top-nav-icon">u</span><span class="top-nav-text">Prev. chapter</span></a> <a class="nav-wide nav-home" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a> <a class="nav-narrow js--sc-top" href="#"><span class="top-nav-icon">t</span><span class="top-nav-text">Top</span></a> <a class="nav-narrow" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a> <a class="nav-wide" href="#"><span class="top-nav-text">Next chapter</span><span class="top-nav-icon">d</span></a> <a class="nav-wide" href="#"><span class="top-nav-text">Next section</span><span class="top-nav-icon">r</span></a> </div> </div> </nav> <!-- END OF TOP NAVIGATION --> </pre> </div> <!-- End of code extract holder --> <div class="code-caption">Code xx.yy   Caption</div> <!-- Code caption --> </div> <!-- End of code fragment -->
Special requirements
The fragment will be as high as required (depends on content); if any line extends beyond the edge of the code-area container, a horizontal scrollbar will automatically appear.
Appearance
<nav> <!-- TOP NAVIGATION BAR -->
<div class="top-nav">
<div class="rg-row">
<a class="nav-wide" href="#"><span class="top-nav-icon">l</span><span class="top-nav-text">Prev. section</span></a>
<a class="nav-wide" href="#"><span class="top-nav-icon">u</span><span class="top-nav-text">Prev. chapter</span></a>
<a class="nav-wide nav-home" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a>
<a class="nav-narrow js--sc-top" href="#"><span class="top-nav-icon">t</span><span class="top-nav-text">Top</span></a>
<a class="nav-narrow" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a>
<a class="nav-wide" href="#"><span class="top-nav-text">Next chapter</span><span class="top-nav-icon">d</span></a>
<a class="nav-wide" href="#"><span class="top-nav-text">Next section</span><span class="top-nav-icon">r</span></a>
</div>
</div>
</nav> <!-- END OF TOP NAVIGATION -->
Options
| Options | |||
|---|---|---|---|
<pre class="prettyprint linenums:287 lang-html" id="js--cXX-YY"> |
|||
| Element | Required Class | Function | |
| <pre> | perttyprint | Triggers the Google Prettify software | |
| linenums:nn | Starts line numbering at the value nn, 287 in example | ||
| lang-html | Sets the display language to HTML | ||
Notes
The fragment will be as high as required (depends on content); if any line extends beyond the edge of the code-area container, a horizontal scrollbar will automatically appear.
HTML
<div class="code-extract"> <!-- Start of code fragment --> <div class="code-header">filename.ext</div> <!-- Code file name --> <div class="code-area"> <!-- Start of code extract holder --> <pre class="prettyprint linenums:287 lang-html" id="js--cXX-YY"> <nav> <!-- TOP NAVIGATION BAR --> <div class="top-nav"> <div class="rg-row"> <a class="nav-wide" href="#"><span class="top-nav-icon">l</span><span class="top-nav-text">Prev. section</span></a> <a class="nav-wide" href="#"><span class="top-nav-icon">u</span><span class="top-nav-text">Prev. chapter</span></a> <a class="nav-wide nav-home" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a> <a class="nav-narrow js--sc-top" href="#"><span class="top-nav-icon">t</span><span class="top-nav-text">Top</span></a> <a class="nav-narrow" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a> <a class="nav-wide" href="#"><span class="top-nav-text">Next chapter</span><span class="top-nav-icon">d</span></a> <a class="nav-wide" href="#"><span class="top-nav-text">Next section</span><span class="top-nav-icon">r</span></a> </div> </div> </nav> <!-- END OF TOP NAVIGATION --> </pre> </div> <!-- End of code extract holder --> <div class="code-caption">Code xx.yy   Caption</div> <!-- Code caption --> </div> <!-- End of code fragment -->
Special requirements
The fragment will be as high as required (depends on content); if any line extends beyond the edge of the code-area container, a horizontal scrollbar will automatically appear.
Appearance
<nav> <!-- TOP NAVIGATION BAR -->
<div class="top-nav">
<div class="rg-row">
<a class="nav-wide" href="#"><span class="top-nav-icon">l</span><span class="top-nav-text">Prev. section</span></a>
<a class="nav-wide" href="#"><span class="top-nav-icon">u</span><span class="top-nav-text">Prev. chapter</span></a>
<a class="nav-wide nav-home" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a>
<a class="nav-narrow js--sc-top" href="#"><span class="top-nav-icon">t</span><span class="top-nav-text">Top</span></a>
<a class="nav-narrow" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a>
<a class="nav-wide" href="#"><span class="top-nav-text">Next chapter</span><span class="top-nav-icon">d</span></a>
<a class="nav-wide" href="#"><span class="top-nav-text">Next section</span><span class="top-nav-icon">r</span></a>
</div>
</div>
</nav> <!-- END OF TOP NAVIGATION -->
Options
| Options | |||
|---|---|---|---|
<pre class="prettyprint linenums lang-html" id="js--cXX-YY" style="max-height: 5.3rem"> |
|||
| Element | Required Class | Function | |
| <pre> | perttyprint | Triggers the Google Prettify software | |
| linenums | Activates automatic line numbering (starts at 1) | ||
| lang-html | Sets the display language to HTML | ||
| style="max-height: 5.3rem" | A style attribute must be applied to <pre> specifying the height of the fragment (e.g. 5.3rems) | ||
Notes
The fragment height will be limited to the max-height setting in the style attribute. Both horizontal and vertical scrollbars will be applied as required.
HTML
<div class="code-extract"> <!-- Start of code fragment --> <div class="code-header">filename.ext</div> <!-- Code file name --> <div class="code-area"> <!-- Start of code extract holder --> <pre class="prettyprint linenums lang-html" id="js--cXX-YY" style="max-height: 5.3rem"> <nav> <!-- TOP NAVIGATION BAR --> <div class="top-nav"> <div class="rg-row"> <a class="nav-wide" href="#"><span class="top-nav-icon">l</span><span class="top-nav-text">Prev. section</span></a> <a class="nav-wide" href="#"><span class="top-nav-icon">u</span><span class="top-nav-text">Prev. chapter</span></a> <a class="nav-wide nav-home" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a> <a class="nav-narrow js--sc-top" href="#"><span class="top-nav-icon">t</span><span class="top-nav-text">Top</span></a> <a class="nav-narrow" href="#"><span class="top-nav-text">Home</span><span class="top-nav-icon">h</span></a> <a class="nav-wide" href="#"><span class="top-nav-text">Next chapter</span><span class="top-nav-icon">d</span></a> <a class="nav-wide" href="#"><span class="top-nav-text">Next section</span><span class="top-nav-icon">r</span></a> </div> </div> </nav> <!-- END OF TOP NAVIGATION --> </pre> </div> <!-- End of code extract holder --> <div class="code-caption">Code xx.yy   Caption</div> <!-- Code caption --> </div> <!-- End of code fragment -->
Appearance
.list-num { /* TEXT STYLE - Numbered list */
font-family: "conc-i3-r";
margin-left: 5rem;
/* font-feature-settings: 'liga' 1, 'ss01' 0; */
}
.list-num li p {
font-family: "eqty-ta-r";
padding-left: 1rem;
margin-bottom: 0.85rem;
}
Options
| Options | |||
|---|---|---|---|
<script src="21-global/05-js/run_prettify.js?autoload=true&lang=css"></script><pre class="prettyprint linenums lang-css" id="js--cXX-YY"> |
|||
| Element | Required Class | Function | |
| <pre> | perttyprint | Triggers the Google Prettify software | |
| linenums | Activates automatic line numbering (starts at 1) | ||
| lang-css | Sets the display language to CSS | ||
| <sript> | &lang=css | &lang=css must be added to load the CSS file. | |
Notes
The fragment will be as high as required (depends on content); if any line extends beyond the edge of the code-area container, a horizontal scrollbar will automatically appear.
HTML
<div class="code-extract"> <!-- Start of code fragment -->
<div class="code-header">filename.ext</div> <!-- Code file name -->
<div class="code-area"> <!-- Start of code extract holder -->
<pre class="prettyprint linenums lang-css" id="js--cXX-YY">
.list-num { /* TEXT STYLE - Numbered list */
font-family: "conc-i3-r";
margin-left: 5rem;
/* font-feature-settings: 'liga' 1, 'ss01' 0; */
}
.list-num li p {
font-family: "eqty-ta-r";
padding-left: 1rem;
margin-bottom: 0.85rem;
} </pre>
</div> <!-- End of code extract holder -->
<div class="code-caption">Code xx.yy   Caption</div> <!-- Code caption -->
</div> <!-- End of code fragment -->
Appearance
#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
// Reads character input from the user
scanf("%c", &c);
// %d displays the integer value of a character
// %c displays the actual character
printf("ASCII value of %c = %d", c, c);
return 0;
}
Options
| Options | |||
|---|---|---|---|
<pre class="prettyprint linenums lang-c" id="js--cXX-YY"> |
|||
| Element | Required Class | Function | |
| <pre> | perttyprint | Triggers the Google Prettify software | |
| linenums | Activates automatic line numbering (starts at 1) | ||
| lang-c | Sets the display language to C (all varieties) | ||
Notes
The fragment will be as high as required (depends on content); if any line extends beyond the edge of the code-area container, a horizontal scrollbar will automatically appear.
HTML
<div class="code-extract"> <!-- Start of code fragment -->
<div class="code-header">filename.ext</div> <!-- Code file name -->
<div class="code-area"> <!-- Start of code extract holder -->
<pre class="prettyprint linenums lang-c" id="js--cXX-YY">
#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
// Reads character input from the user
scanf("%c", &c);
// %d displays the integer value of a character
// %c displays the actual character
printf("ASCII value of %c = %d", c, c);
return 0;
}
</pre>
</div> <!-- End of code extract holder -->
<div class="code-caption">Code xx.yy   Caption</div> <!-- Code caption -->
</div> <!-- End of code fragment -->
Appearance
Sub Main()
On Error GoTo Failed
Dim app As Netica.Application
app = New Netica.Application
app.Visible = True
Dim net_file_name As String
net_file_name = System.AppDomain.CurrentDomain.BaseDirectory() & "..\..\..\ChestClinic.dne"
Dim net As Netica.Bnet
net = app.ReadBNet(app.NewStream(net_file_name))
net.Compile()
Dim TB As Netica.BNode
TB = net.Nodes.Item("Tuberculosis")
Dim belief As Double
belief = TB.GetBelief("present")
MsgBox("The probability of tuberculosis is " & belief)
End Sub
Options
| Options | |||
|---|---|---|---|
<script src="21-global/05-js/run_prettify.js?autoload=true&lang=vb"></script><pre class="prettyprint linenums lang-css" id="js--cXX-YY"> |
|||
| Element | Required Class | Function | |
| <pre> | perttyprint | Triggers the Google Prettify software | |
| linenums | Activates automatic line numbering (starts at 1) | ||
| lang-vb | Sets the display language to VB | ||
| <sript> | &lang=vb | &lang=vb must be added to load the vb file. | |
Notes
The fragment will be as high as required (depends on content); if any line extends beyond the edge of the code-area container, a horizontal scrollbar will automatically appear.
HTML
<div class="code-extract"> <!-- Start of code fragment -->
<div class="code-header">filename.ext</div> <!-- Code file name -->
<div class="code-area"> <!-- Start of code extract holder -->
<pre class="prettyprint linenums lang-vb" id="js--cXX-YY">
Sub Main()
On Error GoTo Failed
Dim app As Netica.Application
app = New Netica.Application
app.Visible = True
Dim TB As Netica.BNode
TB = net.Nodes.Item("Tuberculosis")
Dim belief As Double
belief = TB.GetBelief("present")
MsgBox("The probability of tuberculosis is " & belief)
End Sub
</pre>
</div> <!-- End of code extract holder -->
<div class="code-caption">Code xx.yy   Caption</div> <!-- Code caption -->
</div> <!-- End of code fragment -->
Appearance
<div class="top-nav"></div> <div class="top-nav"></div> <div class="top-nav"></div>
Options
| Options | |||
|---|---|---|---|
<pre class="prettyprint lang-html"> |
|||
| Element | Required Class | Function | |
| <pre> | perttyprint | Triggers the Google Prettify software | |
| lang-html | Sets the display language to HTML | ||
Notes
The code-header and code-caption div elements are not required for simple code fragments.
HTML
<div class="code-extract"> <!-- Start of code fragment -->
<div class="code-area"> <!-- Start of code extract holder -->
<pre class="prettyprint lang-html"><div class="top-nav"></div></pre>
</div> <!-- End of code extract holder -->
</div> <!-- End of code fragment -->
Appearance
<div class="top-nav"></div>
Options
| Options | |||
|---|---|---|---|
<pre class="prettyprint lang-html"> |
|||
| Element | Required Class | Function | |
| <pre> | perttyprint | Triggers the Google Prettify software | |
| lang-html | Sets the display language to HTML | ||
Notes
The code-header and code-caption div elements are not required for simple code fragments.
HTML
<div class="code-extract"> <!-- Start of code fragment -->
<div class="code-area"> <!-- Start of code extract holder -->
<pre class="prettyprint lang-html"><div class="top-nav"></div>
<div class="top-nav"></div>
<div class="top-nav"></div></pre>
</div> <!-- End of code extract holder -->
</div> <!-- End of code fragment -->
Appearance
An inline fragment: <div class="top-nav"></div> it fits within the paragraph text.
Options
| Options | |||
|---|---|---|---|
<code class="prettyprint lang-html"> |
|||
| Element | Required Class | Function | |
| <code> | perttyprint | Triggers the Google Prettify software | |
| lang-html | Sets the display language to HTML | ||
Notes
Inline fragments use the <code> element in place of the <pre> element.
The code-header and code-caption div elements are not required for inline code fragments.
HTML
<p class="hyp">This is inline fragment: <code class="prettyprint lang-html"><div class="top-nav"></div></code>, it fits within the paragraph text.</p>