KScript docs
EN

markdown 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
.extensionstringThe source file extension without the dot.
.textstringThe source text of the fenced value.

From KScript.Document

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

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

The zero-based source offset of the first literal match, or -1.
ParameterTakes
text requiredstring
Example
<let name="notes" value="```markdown
  # Notes

  Some *ideas* for the launch.
  ```" />
<echo>{ $notes->find('ideas') }</echo>
$notes = ```markdown
  # Notes

  Some *ideas* for the launch.
  ```
echo $notes->find('ideas')

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

Returns a copy with text or source of the same format inserted at a zero-based offset. With no offset, appends.
ParameterTakes
content requiredany value
at optionalint

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

Example
<let name="notes" value="```markdown
  # Notes

  Some *ideas* for the launch.
  ```" />
<echo>{ $notes->insert(' More soon.').text }</echo>
$notes = ```markdown
  # Notes

  Some *ideas* for the launch.
  ```
echo $notes->insert(' More soon.').text

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

How many pages the PDF has.
Example
<let name="notes" value="```markdown
  # Notes

  Some *ideas* for the launch.
  ```" />
<echo>{ $notes->pages() } pages</echo>
$notes = ```markdown
  # Notes

  Some *ideas* for the launch.
  ```
echo "{ $notes->pages() } pages"

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

Returns a copy with every literal match replaced.
ParameterTakes
search requiredstring
replacement requiredstring

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

Example
<let name="notes" value="```markdown
  # Notes

  Some *ideas* for the launch.
  ```" />
<echo>{ $notes->replace('ideas', 'plans').text }</echo>
$notes = ```markdown
  # Notes

  Some *ideas* for the launch.
  ```
echo $notes->replace('ideas', 'plans').text

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

Writes the document to a file. The filename extension (or as:) picks the format: .md keeps the source, and .pdf, .docx, .tex or .html renders it. With no extension, .md.
ParameterTakes
path requiredstring
as optionalone of these words: pdf|docx|'latex'|'markdown'|html

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

Example
<let name="notes" value="```markdown
  # Notes

  Some *ideas* for the launch.
  ```" />
<do>$notes->save('notes.pdf')</do>
<do>$notes->save('notes.docx')</do>
$notes = ```markdown
  # Notes

  Some *ideas* for the launch.
  ```
$notes->save('notes.pdf')
$notes->save('notes.docx')

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

How many words the text has, not counting maths and code.
Example
<let name="notes" value="```markdown
  # Notes

  Some *ideas* for the launch.
  ```" />
<echo>{ $notes->words() } words</echo>
$notes = ```markdown
  # Notes

  Some *ideas* for the launch.
  ```
echo "{ $notes->words() } words"

Methods from any