Code Blocks
Code block appearance can be specialized per coding language. This is how they will appear in your portal.
Code blocks are a way of sharing code in DITA. Some of the variations we design for are:
- How is the color palette applied to the code block?
- Is there a way to copy the contents of the code block?
- Are there line numbers shown in the code block?
- Does the code block have a border?
- How is the typography colored in the code block?
The presentation varies by coding language.
HTML
XML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Href Attribute Example</title>
<link href="https://my-style.css" rel="stylesheet" />
<!-- This is a comment -->
</head>
<style>
body {
margin; 0;
padding: 0;
}
</style>
<body>
<h1>Href Attribute Example</h1>
<p class="something-special">
<a href="https://www.documentation_improvement.com">The documentation_improvement Web Page</a> is the company landing portal.
</p>
</body>
</html>
XML
Codeblock example for troubleshooting
CODE
<sitemap>
<!-- Sitemap title -->
<title>Sitemap</title>
<!-- A sitesection that renders as a tile on the home page -->
<sitesection>
<!-- Site section details container -->
<topicmeta>
<navtitle>Basic Site Section</navtitle>
</topicmeta>
<!-- Referenced DITA content -->
<topicref href="content/concept_a.dita">
<topicref href="content/task_a.dita"/>
<topicref href="content/reference_a.dita"/>
</topicref>
<topicref href="content/concept_b.dita">
<topicref href="content/task_b.dita"/>
<topicref href="content/reference_b.dita"/>
</topicref>
</sitesection>
</sitemap>
CSS
Codeblock example for troubleshooting
JSON
.class {
font-size: 0.85rem;
font-weight: 600;
font-family: monospace;
}
h1 .header {
font-size: 1.5rem;
font-family: Arial;
}
JavaScript
JAVASCRIPT
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');
}
return (
<div>
<web-component>{block}</web-component>
</div>
)
}
export $initHighlight;
Java
CODE
/**
* @author John Smith <john.smith@example.com>
*/
package l2f.gameserver.model;
public abstract strictfp class L2Char extends L2Object {
public static final Short ERROR = 0x0001;
public void moveTo(int x, int y, int z) {
_ai = null;
log("Should not be called");
if (1 > 5) { // why?
return;
}
}
}
JSON
JSON
{
"title": "Content Portal",
"sectionFilter": {"type": "sitesection"},
"supportedBrowserMinimumVersions": {
"chrome": "60",
"firefox": "63",
"safari": "11",
"edge": "79",
"opera": "47"
},
"prerenderToc": true,
"cacheExpiry": 900,
"prettifyPre": true,
"prettifyCode": true,
"prettifyCodeLang": 'bash',
"keywords": [
"node",
"express",
"static"
],
"toc": {
"allowFilter": false,
"contentScrollConfig": {
"block": "start",
"behavior": "auto"
}
},
"footer": {
"logoSrc": "",
"logoAlt": "",
"copyright": "message.footer.copyright",
"links": []
},
"search": {
"ref": "href",
"fields": [
"href",
"shortDescription",
"title"
],
"sections": [
"sitesection"
],
"facets": [
"Information_Type",
"Area"
]
},
}
Shell
CODE
#!/bin/bash
# Assigning a value to a variable
name="John"
age=21
echo $name $age
Powershell
CODE
$myVariable = "Hello, World!"$number = 42Arrays are ordered collections of values, which can be accessed by their index (starting at 0). Here is an example:$fruits = @("apple", "banana", "orange")$fruits[0] # Will output "apple"
Bash
CODE
# This script prints a greeting message
echo "Hello, World!"
Log
CODE
# This script prints a greeting message
echo "Hello, World!"
No Language
CODE
/**
* @author John Smith <john.smith@example.com>
*/
package l2f.gameserver.model;
public abstract strictfp class L2Char extends L2Object {
public static final Short ERROR = 0x0001;
public void moveTo(int x, int y, int z) {
_ai = null;
log("Should not be called");
if (1 > 5) { // why?
return;
}
}
}