title | description | summary | date | lastmod | draft | weight | toc | seo | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Code Blocks |
2023-12-22 20:30:04 +0100 |
2023-12-22 20:30:04 +0100 |
false |
430 |
true |
|
A code block is indicated by a block with three backticks ```
at the start and end. You can indicate the programming language being used after the opening backticks.
if ([1, "one", 2, "two"].includes(value)) {
console.log("Number is either 1 or 2."); // comment
}
```js
if ([1, "one", 2, "two"].includes(value)) {
console.log("Number is either 1 or 2."); // comment
}
```
Code blocks can be rendered inside a window-like frame. A frame that looks like a terminal window will be used for shell scripting languages (e.g. bash
or sh
). Other languages display inside a code editor-style frame if they include a title.
A code block’s optional title can be set with a title="..."
attribute following the code block’s opening backticks and language identifier.
if ([1, "one", 2, "two"].includes(value)) {
console.log("Number is either 1 or 2."); // comment
}
```js {title="count.js"}
if ([1, "one", 2, "two"].includes(value)) {
console.log("Number is either 1 or 2."); // comment
}
```
The default:
npm install @hyas/doks-core@latest
```bash
npm install @hyas/doks-core@latest
```
With a title
attribute:
npm install
```bash {title="Installing dependencies…"}
npm install
```
No frame:
npm install @hyas/doks-core@latest
```bash {frame="none"}
npm install @hyas/doks-core@latest
```
if ([1, "one", 2, "two"].includes(value)) {
console.log("Number is either 1 or 2."); // comment
}
```js {lineNos=true lineNoStart=32}
if ([1, "one", 2, "two"].includes(value)) {
console.log("Number is either 1 or 2."); // comment
}
```
if ([1, "one", 2, "two"].includes(value)) {
console.log("Number is either 1 or 2."); // comment
}
```js {hl_lines=2}
if ([1, "one", 2, "two"].includes(value)) {
console.log("Number is either 1 or 2."); // comment
}
```
With line numbers:
// GetTitleFunc returns a func that can be used to transform a string to
// title case.
//
// The supported styles are
//
// - "Go" (strings.Title)
// - "AP" (see https://www.apstylebook.com/)
// - "Chicago" (see https://www.chicagomanualofstyle.org/home.html)
//
// If an unknown or empty style is provided, AP style is what you get.
func GetTitleFunc(style string) func(s string) string {
switch strings.ToLower(style) {
case "go":
return strings.Title
case "chicago":
return transform.NewTitleConverter(transform.ChicagoStyle)
default:
return transform.NewTitleConverter(transform.APStyle)
}
}
```go {linenos=true,hl_lines=[8,"15-17"],linenostart=199}
// GetTitleFunc returns a func that can be used to transform a string to
// title case.
//
// The supported styles are
//
// - "Go" (strings.Title)
// - "AP" (see https://www.apstylebook.com/)
// - "Chicago" (see https://www.chicagomanualofstyle.org/home.html)
//
// If an unknown or empty style is provided, AP style is what you get.
func GetTitleFunc(style string) func(s string) string {
switch strings.ToLower(style) {
case "go":
return strings.Title
case "chicago":
return transform.NewTitleConverter(transform.ChicagoStyle)
default:
return transform.NewTitleConverter(transform.APStyle)
}
}
```