Code Blocks
1 min read
Terminal/Console
Passing the option noPromptLines="3-4,5"
.
cd projectcp -R \dist \public/rm -rf distyarn 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="2,5-7,11..16
.
// Constructorvar anObject = new Object();// Object literalvar objectA = {};var objectA2 = {};var objectB = { index1: 'value 1', index2: 'value 2' };// filter object propertiesvar 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 toPerson 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
<?phpfunction 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 turnfor jpg; do# construct the PNG version of the filename by replacing .jpg with .pngpng="${jpg%.jpg}.png"# output status info to the user running the scriptecho converting "$jpg" ...# use the convert program (common in Linux) to create the PNG in a temp fileif convert "$jpg" jpg.to.png ; then# if it worked, rename the temporary PNG image to the correct namemv jpg.to.png "$png"# ...otherwise complain and exit from the scriptelseecho 'jpg2png: error: failed output saved in "jpg.to.png". adksjflkasd fkljasd lfkja lksdjf lkasdjf lkasdjf lkajsd fkljas dlkfj asdflk' >&2exit 1# the end of the "if" test constructfi# the end of the "for" loopdone# tell the user the good newsecho all conversions successfulexit 0
Swift
struct Player {var name: Stringvar highScore: Int = 0var 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.