Prism Syntax Highlighter
The recommended way to mark up a code block(both for semantics and for Prism) is a <pre>
element with a element <code>
inside, like so:
<pre>
<code class="language-css">
p {
color: #1abc9c
}
</code>
</pre>
p {
color: #1abc9c
}
Use the following code to use HTML syntax highlighter.
<pre>
<code class="language-markup">
HTML CODE ...
</code>
</pre>
<div class="card">
<div class="card-header">
<h5>Hello card</h5>
<span> lorem ipsum dolor sit amet, consectetur adipisicing elit</span>
<div class="card-header-right">
<i class="icofont icofont-rounded-down"></i>
<i class="icofont icofont-refresh"></i>
<i class="icofont icofont-close-circled"></i>
</div>
</div>
<div class="card-block">
<p>
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
</p>
</div>
</div>
Use the following code to use HTML syntax highlighter.
<pre>
<code class="language-css">
CSS CODE ...
</code>
</pre>
a:active{
color:#1abc9c;
}
p{
font-size:13px;
}
.btn-primary{
color: #1abc9c;
background-color: #fff;
}
.label-primary {
background-color: #1abc9c;
}
.badge-primary {
background-color: #1abc9c;
}
.bg-primary {
background-color: #1abc9c !important;
color: #fff;
}
.panel-primary {
border-color: #1abc9c;
}
Line number at the beginning of code lines.
Obviously, this is supposed to work only for code blocks (<pre><code>
) and not for inline code. Add class line-numbers to your desired <pre>
and line-numbers plugin will take care.
Optional: You can specify the data-start (Number) attribute on the <pre>
element. It will shift the line counter.
<pre class="line-numbers">
<code class="language-css">
p {
color: red;
}
</code>
</pre>
(function() {
if (typeof self==='undefined' || !self.Prism || !self.document) {
return;
}
});
Highlights specific lines and/or line ranges.
You specify the lines to be highlighted through the data-line attribute on the <pre>
element, in the following simple format:
<pre data-line="2, 4, 8-10">
<code class="language-css">
p {
color: red
}
</code>
</pre>
pre.line-numbers {
position: relative;
padding-left: 3.8em;
counter-reset: linenumber;
}
pre.line-numbers > code {
position: relative;
}
.line-numbers .line-numbers-rows {
position: absolute;
pointer-events: none;
top: 0;
font-size: 100%;
left: -3.8em;
width: 3em;
/* works for line-numbers below 1000 lines */
letter-spacing: -1px;
border-right: 1px solid #999;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
Converts URLs and emails in code to clickable links. Parses Markdown links in comments.
URLs and emails will be linked automatically, you don’t need to do anything. To link some text inside a comment to a certain URL, you may use the Markdown syntax:
<pre>
<code class="language-css">
@font-face {
src: url(http://lea.verou.me/logo.otf);
}
</code>
</pre>
@font-face {
src: url(http://lea.verou.me/logo.otf);
font-family: 'LeaVerou';
}
Show hidden characters such as tabs and line breaks.
(function() {
if ( typeof self !=='undefined' && !self.Prism || typeof global !=='undefined' && !global.Prism) {
return;
}
Prism.hooks.add('before-highlight', function(env) {
var tokens=env.grammar;
tokens.tab=/\t/g;
tokens.crlf=/\r\n/g;
tokens.lf=/\n/g;
tokens.cr=/\r/g;
tokens.space=/ /g;
});
});
Fetch external files and highlight them with Prism. Used on the Prism website itself.
Use the data-src attribute on empty <pre>
elements, like so:
<pre data-src="bootstrap-growl.min.js"></pre>
You don’t need to specify the language, it’s automatically determined by the file extension. If, however, the language cannot be determined from the file extension or the file extension is incorrect, you may specify a language as well (with the usual class name way).
Please note that the files are fetched with XMLHttpRequest. This means that if the file is on a different origin, fetching it will fail, unless CORS is enabled on that website.