Reference

CodeBlock

A block of code with a bar above it: a file name, a copy button (.copy), and line numbers (.lines). language: colours it, as on Code; highlight: marks lines; files: makes it a tab for each file.

CodeBlock(_ code: String, highlight: [Number], files: [CodeFile], language: String, …)

Before 5.0

language

title

copy

lines

Home.wf
page Home(path: "/", title: "Home") { state count = 0 Heading("Welcome").h1 Button("+1").primary { on click { count = count + 1 } } }

Example

wf

CodeBlock(""" page Home(path: "/", title: "Home") \{ state count = 0 Heading("Welcome").h1 Button("+1").primary \{ on click \{ count = count + 1 \} \} \} """, language: "wf", title: "Home.wf", highlight: [2, 4]).copy.lines

A tab a file

wf

CodeBlock(files: [ { name: "Home.wf", code: #"page Home(path: "/") { Text("Hi") }"#, language: "wf" }, { name: "styles.css", code: ".hero { padding: 2rem; }", language: "css" }, ]).copy

A shell command

wf

CodeBlock("wf init shop -t spa\ncd shop && wf serve", language: "bash").copy

Props

Props of CodeBlock
PropTypeUnsetMeaning

code

String (positional)

—

The code, shown as written in a block that scrolls sideways

highlight:

[Number]

none

The lines to mark, counted from 1: [3, 4]; each gets a tint and a bar in the primary colour

files:

[CodeFile]

none

A tab for each file, each its own code block: [{ name: "App.wf", code: app, language: "wf" }, …]; .copy and .lines apply to each

language:

String

none: plain

Colours the code as this language: wf (or wfx), json, bash (sh, shell) or css; any other is shown plain

title:

String

none: no bar unless .copy (with files:, Files)

The file name or the language, in the bar above the code; with files:, the tab list's accessible name

copy:

Bool

false

A button in the bar that copies the code and says Copied. Written as a flag, .copy, or copy: true.

lines:

Bool

false

Line numbers in a column beside the code, hidden from screen readers. Written as a flag, .lines, or lines: true.

Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.

Flags and cases

A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.

.copy

.lines

Events

Every element also takes the props, the events and the attribute families listed on every element.

Slots

It takes no slots.

Parts

The parts of CodeBlock are written under its name, inside it. Each is described here, with what it takes.

CodeBlock.Bar

The bar above the code.

CodeBlock.Bar { … }

CodeBlock.Lines

The line numbers.

CodeBlock.Lines(_ text: String)
Props of CodeBlock.Lines
PropTypeUnsetMeaning

text

String (positional)

none

The numbers, one a line

Drawn for it

What CodeBlock draws itself, by the class a stylesheet can select. They are not written.

Drawn for it
PartClassMeaning

CodeBlock.Marks

—

The marks over the lines highlight: names.

CodeBlock.Mark

—

One line's mark.

Renders with the class wf-code-block, stable across releases, so a stylesheet may target it.