KScript docs
EN

Install and editors

Reading the docs

kscript docs opens these docs in your browser. They are built into kscript, so they work offline and match the version you have:

CommandWhat it does
kscript docsOpen the docs.
kscript docs replaceOpen them with a search for "replace".

Docs without kscript running

To read the docs somewhere kscript docs can't run, such as a computer without KScript, a USB stick or your own web server, export them. --export-to writes the whole site into a folder as plain files:

CommandWhat it does
kscript docs --export-to kscript-docsWrite the docs into kscript-docs.
kscript docs --export-to kscript-docs --syntax xmlWith the examples shown as XML first.

Open kscript-docs/index.html in a browser. Every page is its own .html file and every link is relative, so the folder works straight from the disk, with no server and no network, and keeps working when you copy or upload it. Search works too: its index comes in assets/search.js. Exporting into the same folder again replaces the pages and leaves any other files there alone.

To put several versions on one website, export each into a folder named after its version, side by side (docs/0.55.0/, docs/0.54.0/). --versions url turns the version in the header into a picker that reads a list such as {"latest": "0.55.0", "versions": ["0.55.0", "0.54.0"]} and opens the same page in the version picked, and --stylesheet url loads a stylesheet of your own after the docs' own, so they match the rest of the site. The KScript website publishes every release's docs this way at /docs/<version>/.

Docs for your website

A copy you put on a website is read as published documentation, not as a local tool. --published makes it one: the playground is left out, with every link to it, pages end without an "Edit this page on GitHub" link, and the home page doesn't talk about how the copy was made. kscript docs on your computer keeps all of them.

--hide leaves out pages and reference entries, with every link to them and their search entries, as a list separated by commas:

Shell
kscript docs --export-to public/docs --published --hide /guide/roadmap,/reference/methods/*,/reference/ai#cmd-chat
In --hide Leaves out
/guide/roadmap (or guide/roadmap) that page, and its topic pages
/reference/methods/* every page under the path
/reference/ai#cmd-chat one reference entry: the anchor in its address
playground the playground
edit-links the "Edit this page on GitHub" links

To add your own content, such as illustrations or a note about your support, or to replace a page, put the settings in a JSON file and pass it with --config:

JSON
{
  "published": true,
  "hide": ["/guide/roadmap"],
  "pages": { "/guide/install": "install.md" },
  "before": { "/guide/language": "language-intro.md" },
  "after": { "/": "support.md" },
  "files": "docs-files",
  "versions": "/docs/versions.json",
  "stylesheet": "/assets/docs-theme.css",
  "syntax": "kscript"
}
  • pages replaces a page with your Markdown (a guide's topic pages go with it).
  • before adds Markdown under a page's title, and after at its end. Their headings join the page's "On this page".
  • files is a folder copied into the top of the copy, for the pictures and other files your Markdown uses: docs-files/illustrations/flow.svg is ![How a script runs](/illustrations/flow.svg).
  • Paths in the file are found from the file's own folder. The command line adds to the file: --hide adds to hide, and --published, --versions, --stylesheet and --syntax win over the file.

A path that matches no page or entry is an error, and nothing is written, so a typo never leaves a page in by accident.

The examples can still be read, copied and switched between .kscript and XML, but they can't run, because running them needs kscript docs. So the Run boxes and the playground's editor are left out, and each runnable example leaves a hidden placeholder where its box was:

HTML page
<div class="kscript-example" data-example="guide-getting-started-1">
  <!-- the example's code, to read -->
  <template class="kscript-try" data-example="guide-getting-started-1" data-format="kscript"
            data-kscript="echo 'Hello'" data-xml="&lt;echo&gt;Hello&lt;/echo&gt;"></template>
</div>

data-example names the example: the page's file and its number on that page, so it stays the same from one export to the next. data-format is the format the example was written in, data-kscript and data-xml hold its code in each format, and data-input and data-title are there when the example has them. A <template> is never shown, so the placeholders change nothing until a script of your own uses them. To run the examples with your own runner, add a script to the pages that swaps each one for it:

js
document.querySelectorAll('template.kscript-try').forEach(placeholder => {
  const example = placeholder.closest('.kscript-example');
  // The example's code in the reader's format, falling back to the one it was written in.
  const format = document.documentElement.dataset.format;
  const code = placeholder.dataset[format] ?? placeholder.dataset[placeholder.dataset.format];
  example.replaceWith(myRunner(code, format));   // myRunner is yours: an editor and a Run button
});