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>/.

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
});

Edit this page on GitHub