Long strings and blocks of text
End a line inside a string with \ to carry the string on to the next line. The new line and the next line's indentation aren't part of the string, so a long string can follow the code's indentation:
<let name="name" value="'Kyle'" />
<echo>Hello { $name }. KScript reads your whole script, checks it, and only then runs it.</echo>$name = 'Kyle'
echo "Hello { $name }. KScript reads your whole script, checks it, \
and only then runs it."That prints one line. It works in "double-quoted" and 'single-quoted' strings, and keeps any spaces before the \. Write \\ for a backslash of your own at the end of a line of text. kscript fmt uses it to wrap a string that runs past print_width (the wrap_strings rule).
For text that should keep its new lines, such as a query, a template or an equation, use a block fenced with three backticks, as in Markdown:
<echo>Hi { $name },
your order has shipped.</echo>
<let name="query">```sql
SELECT * FROM users
WHERE active = 1
```</let>
<let name="repo">```<Repo>
{ "name": "kscript", "stars": 12 }
```</let>echo ```
Hi { $name },
your order has shipped.
```
$query = ```sql
SELECT * FROM users
WHERE active = 1
```
$repo = ```<Repo>
{ "name": "kscript", "stars": 12 }
```- The block runs from the opening fence to a line that starts with the same number of backticks. Use four (or more) when the text holds three.
- The closing fence's indentation is taken off every line, so the block sits at the code's indentation and keeps any indentation inside it. A line indented less than the closing fence is an error. The new lines just inside the fences aren't part of the text.
- In an expression, an empty header or
mdormarkdownproduces amarkdownvalue.latexortexproduces alatexvalue. ImportKScript.Documentfor document methods, or read the original text with.text. kscriptand other file extensions such asps1produce aformatted_filewith.extensionand.text. Use->save('filename')to write it, or pass a complete filename to choose the exact path.csvproduces acsvvalue: CSV text that is checked where it is written, read with->cells(). See CSV.textandstringproduce plain strings. Existinghtml,xml,css,scss,ks.css,ks.scss,js,javascript,ts,typescript,json,jsonc,sql,yamlandymlfences also produce strings in expressions. A typed component return uses the tag to choose its renderer.- VS Code highlights known fence languages in place. A compatible editor formatter can format a fence during Format Document. Use
textorstringfor literal text that should keep its spacing. - A type in angle brackets parses the block:
```<json>is the parsed JSON, and```<Repo>maps it onto atype, with the same checks (andShapeerrors) as->convert(from: json, as: Repo). - As an element's text (after
echo,Paragraph,Math, ...) a block is the same as"text":{ }interpolates where the element interpolates, andMathkeeps its braces. No escapes apply inside a block. - Code can carry on after the closing fence on the same line:
``` )or```->trim().