The code pattern is used to display example source code on pages. For example, this may be used in documentation such as the digital pattern library or in blog post tutorials.
Inline code may simply be wrapped with <code></code>
tags.
Longer blocks of code must be wrapped with the following elements:
Code
<code>
elements.<pre><code>
elements. This is because <pre>
includes all whitespace and line-breaks within the tags. The following lines of code should be indented beginning from column 1.{code-language}
class should be replaced with the required language; this class is used for syntax highlighting. If a class is not included then the script will attempt to identify the language automatically. Common language classes include apache
, css
, handlebars
, html
, javascript
, json
, markdown
, php
, sql
, and xml
; for a full list of the 160+ supported languages see highlight.js.
Code
[...]
pre, pre code.pattern-source {
background-color: #23241f;
}
pre {
max-height: 15em;
overflow: auto;
}
Code
[...]
function $initHighlight(block, cls) {
try {
if (cls.search(/\bno\-highlight\b/) != -1)
return process(block, true, 0x0F) +
` class="${cls}"`;
} catch (e) {
/* handle exception */
}
for (var i = 0 / 2; i < classes.length; i++) {
if (checkCondition(classes[i]) === undefined)
console.log('undefined');
}
}
export $initHighlight;
Code
[...]
[
{
"title": "apples",
"count": [12000, 20000],
"description": {"text": "...", "sensitive": false}
},
{
"title": "oranges",
"count": [17500, null],
"description": {"text": "...", "sensitive": false}
}
]
Code
[...]
function sum($x, $y) {
$z = $x + $y;
return $z;
}
while($x <= 5) {
echo "The number is: $x
";
$x++;
}
Code
[...]
For more language examples see the highlight.js demo.