Code Blocks

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
}
```

Frames and titles

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.

File name tab

count.js
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
}
```

Terminal window

The default:

npm install @hyas/doks-core@latest
```bash
npm install @hyas/doks-core@latest
```

With a title attribute:

Installing dependencies…
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
```

Line numbers

32if ([1, "one", 2, "two"].includes(value)) {
33  console.log("Number is either 1 or 2."); // comment
34}
```js {lineNos=true lineNoStart=32}
if ([1, "one", 2, "two"].includes(value)) {
  console.log("Number is either 1 or 2."); // comment
}
```

Highlight

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:

199// GetTitleFunc returns a func that can be used to transform a string to
200// title case.
201//
202// The supported styles are
203//
204// - "Go" (strings.Title)
205// - "AP" (see https://www.apstylebook.com/)
206// - "Chicago" (see https://www.chicagomanualofstyle.org/home.html)
207//
208// If an unknown or empty style is provided, AP style is what you get.
209func GetTitleFunc(style string) func(s string) string {
210  switch strings.ToLower(style) {
211  case "go":
212    return strings.Title
213  case "chicago":
214    return transform.NewTitleConverter(transform.ChicagoStyle)
215  default:
216    return transform.NewTitleConverter(transform.APStyle)
217  }
218}
```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)
  }
}
```