Code Blocks

1 min read

Terminal/Console

Passing the option noPromptLines="3-4,5".

cd project
cp -R \
dist \
public/
rm -rf dist
yarn start

No options, but you can check that the indentation in regards to the left prompt is aligned when the line wraps.

# fetch a token:
curl https://auth.sphere.io/oauth/token --basic --user "{client_id}:{client_secret}" -X POST -d "grant_type=client_credentials&scope=manage_project:{project_key}"
# now access the API:
curl -sH "Authorization: Bearer ACCESS_TOKEN" https://api.sphere.io/PROJECT_KEY/products

Passing the option title="Fetching an access token"

Fetching an access tokenTerminal
# fetch a token:
curl https://auth.sphere.io/oauth/token --basic --user "{client_id}:{client_secret}" -X POST -d "grant_type=client_credentials&scope=manage_project:{project_key}"
# now access the API:
curl -sH "Authorization: Bearer ACCESS_TOKEN" https://api.sphere.io/PROJECT_KEY/products

Javascript

Passing the option highlightLines="1-2,5-7,11..16.

// Constructor
var anObject = new Object();
// Object literal
var objectA = {};
var objectA2 = {};
var objectB = { index1: 'value 1', index2: 'value 2' };
// filter object properties
var allowed = ['index2'];
var filtered = Object.keys(objectB)
.filter(key => allowed.includes(key))
.reduce((obj, key) => {
obj[key] = objectB[key];
return obj;
}, {});

Python

s = "Python syntax highlighting"
print s

C

Person person = new Person {
Name = "John Doe",
Age = 39
};
// Equal to
Person person = new Person();

Java

public class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Prints the string to the console.
}
}

JSON

{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": 123.45,
"Sort": true,
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": null
}
}
}
}
}

PHP

<?php
function myAge(int $birthYear):string {
// calculate the age by subtracting the birth year from the current year.
$yearsOld = date('Y') - $birthYear;
// return the age in a descriptive string.
return $yearsOld . ' year' . ($yearsOld != 1 ? 's' : '');
}
echo 'I am currently ' . myAge(1995) . ' old.';

Shell

#!/bin/bash
# use $jpg in place of each filename given, in turn
for jpg; do
# construct the PNG version of the filename by replacing .jpg with .png
png="${jpg%.jpg}.png"
# output status info to the user running the script
echo converting "$jpg" ...
# use the convert program (common in Linux) to create the PNG in a temp file
if convert "$jpg" jpg.to.png ; then
# if it worked, rename the temporary PNG image to the correct name
mv jpg.to.png "$png"
# ...otherwise complain and exit from the script
else
echo 'jpg2png: error: failed output saved in "jpg.to.png". adksjflkasd fkljasd lfkja lksdjf lkasdjf lkasdjf lkajsd fkljas dlkfj asdflk' >&2
exit 1
# the end of the "if" test construct
fi
# the end of the "for" loop
done
# tell the user the good news
echo all conversions successful
exit 0

Swift

struct Player {
var name: String
var highScore: Int = 0
var history: [Int] = []
init(_ name: String) {
self.name = name
}
}
var player = Player("Tomas")

No language set

No language indicated, so no syntax highlighting.
But let's throw in a <b>tag</b> which should remain unparsed

Last section

This section is only useful as an anchor link target.