KScript docs
EN

document fields and methods

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

Fields

FieldTypeDescription
.sectionsnumberHow many sections it has.
.titlestringThe document's title ('' without one).

From KScript.Document

These need <import package="KScript.Document" />import KScript.Document. See KScript.Document.

#document->bytes(as: pdf|docx|html) → base64 KScript.Document

The document rendered as pdf, docx or html, as a base64 value, ready for @response($doc->bytes(as: pdf), type: 'application/pdf') without a file.
ParameterTakes
as requiredone of these words: pdf|docx|html
Example
<echo>{ @document('# Invoice')->bytes(as: pdf).bytes > 0 }</echo>
echo @document('# Invoice')->bytes(as: pdf).bytes > 0

#document->find(text: string) → number KScript.Document

The zero-based match offset in the document's source, or -1.
ParameterTakes
text requiredstring
Example
<echo>{ @document('# Notes')->find('Notes') }</echo>
echo @document('# Notes')->find('Notes')

#document->insert(content, at?: int) → document KScript.Document

Returns a document with same-format source or plain text added at the given offset.
ParameterTakes
content requiredany value
at optionalint

Arguments can be named: ->insert(…, at: …).

Example
<echo>{ @document('# Notes')->insert(' and ideas')->convert(to: markdown) }</echo>
echo @document('# Notes')->insert(' and ideas')->convert(to: markdown)

#document->pages() → number KScript.Document

How many pages the PDF has.
Example
<echo>{ $doc->pages() } pages</echo>
echo "{ $doc->pages() } pages"

#document->replace(search: string, replacement: string) → document KScript.Document

Returns a document made from the source with every literal match replaced.
ParameterTakes
search requiredstring
replacement requiredstring

Arguments can be named: ->replace(…, replacement: …).

Example
<echo>{ @document('# Notes')->replace('Notes', 'Outline')->convert(to: markdown) }</echo>
echo @document('# Notes')->replace('Notes', 'Outline')->convert(to: markdown)

#document->save(path: string, as?: pdf|docx|'latex'|'markdown'|html) KScript.Document

Saves the document. The filename extension selects the format unless as is given.
ParameterTakes
path requiredstring
as optionalone of these words: pdf|docx|'latex'|'markdown'|html

Arguments can be named: ->save(…, as: …).

Example
<echo>{ @document('# Notes')->save('notes', as: pdf) }</echo>
echo @document('# Notes')->save('notes', as: pdf)

#document->words() → number KScript.Document

How many words the text has, not counting maths and code.
Example
<echo>{ $doc->words() } words</echo>
echo "{ $doc->words() } words"

Methods from any