Overview
You will learn
- How console fences separate commands from output and copy commands only
- How diff markers (
// [!code ++]/--/focus/highlight) annotate changes - How
placeholders: autoturns<YOUR_…>tokens into fillable chips - How
treefences render project structure, and how:::walkthroughpairs code with notes
Prerequisites
- A BTP trial account (you will need
<YOUR_SUBACCOUNT_ID>below) - Node.js 18+ installed
Steps
Console blocks separate command lines from output. Tag your fence console, shell-session, or terminal-session. Lines starting with $, >, or PS> are commands; all other lines are output. The copy button copies commands only, without prompts.
cf login -a https://api.cf.eu10.hana.ondemand.comAPI endpoint: https://api.cf.eu10.hana.ondemand.comEmail: user@example.comPassword: ••••••••cf target -s devAPI endpoint: https://api.cf.eu10.hana.ondemand.com (v3)Org: myorg Space: devcf appsGetting apps in org myorg / space dev...name requested state processestutorials-srv started web:1/1
Copying this block yields three lines: the three cf commands, prompts stripped.
Multi-line continuation works too:
cf create-service hana hdi-shared \my-hdi-containerCreating service instance my-hdi-container...
Use inline markers to highlight what changed. Add // [!code ++], // [!code --], // [!code focus], or // [!code highlight] as trailing comments (adjust for your language).
function greet(name) {
function greet(name = 'World') {
const msg = `Hello, ${name}!`
console.log(msg)
return msg
}
Copying this fence produces only the final version (the added line; removed line excluded):
function greet(name = 'World') {
const msg = `Hello, ${name}!`
console.log(msg)
return msg
}Use {copy=raw} to get the original source with markers for teaching diffs:
export const VERSION = '1.0.0'
export const VERSION = '1.1.0'
Focus mode dims non-focused lines until the reader hovers the block:
entity Books : managed {
key ID : UUID;
title : String(111);
author : Association to Authors;
}This tutorial has placeholders: auto in its frontmatter. Any token matching <YOUR_…>, <MY_…>, or TUTVARxTHREE_UPPERCASEx becomes a fillable chip. Fill it once and every occurrence updates.
Target your BTP subaccount:
cf target -o TUTVARxYOUR_ORG_NAMEx -s TUTVARxYOUR_CF_SPACExOr in YAML config:
services:
hana:
subaccount:
space: The tokens TUTVARxYOUR_ORG_NAMEx, TUTVARxYOUR_CF_SPACEx, and TUTVARxYOUR_SUBACCOUNT_IDx are all automatically detected. Readers who fill one field see it updated everywhere.
Unfilled tokens display and copy as their original text (e.g. TUTVARxYOUR_SUBACCOUNT_IDx).
Show project structure with a tree fence. Use + / ~ / - state prefixes and # text annotations.
The copy button returns the plain ASCII source.
A :::walkthrough directive pairs a code fence with a numbered list. Each list item starts with {N} or {N-M} to reference line numbers. Clicking a note highlights the corresponding lines.
import cds from '@sap/cds'
const srv = await cds.connect.to('CatalogService')
const { Books } = srv.entities
srv.on('READ', Books, async (req) => {
const results = await srv.read(Books)
.where({ stock: { '>': 0 } })
return results
})- {1} Import the CAP runtime SDK.
- {3} Connect to the catalog service — returns a proxy to the remote service.
- {4} Destructure the
Booksentity from the service definition. - {6-9} Register a
READhandler that filters to in-stock books only.
Line references out of bounds (e.g. {40} in a 9-line fence) fail the build with a clear error.
Next Steps
Now you know how to use all five code-block enhancements. For full reference, see the authoring docs in the tutorials-ims repository and the related variables personalisation feature.
Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.