Tools

Every tool on this page implements the same five specifications and reports the same error codes.

Depending on the use:

Use Tool
Try the language without installing anything The playground
Write documents regularly The VS Code extension
Validate from a script, a Makefile or CI The stxt command line
Read or generate STXT from a program A library: TypeScript, Java or Python

Playground

play.stxt.dev is an editor in the browser: several documents at once, their schemas or templates next to them, syntax and validation errors while editing, grammar-driven autocompletion and hover with the definition of each node.

  • No installation and no account; the work is kept in the browser itself.
  • It includes a seed of example documents.
  • The whole workspace can be shared with a link that carries the content inside.

VS Code extension

The official extension is STXT Language (stxt-lang.stxt). It is installed from the extensions view, searching for stxt, or from the terminal:

code --install-extension stxt-lang.stxt

Features:

  • Syntax errors in real time, and schema errors; a namespace no level defines is flagged with SCHEMA_NOT_FOUND as a warning.
  • Semantic highlighting.
  • Completion with the nodes the schema allows and the values of an ENUM.
  • Hover information: the description given by the definition, the type and, in an ENUM, its values.
  • Go to definition (F12): from a node to the Node: of its schema, or to its line inside the Structure of its template.
  • Document formatting.
  • Schema and template resolution from the .stxt/ directories of the project, the user and the system, as described in the discovery reference.

Command line

The stxt command is published on npm as @stxt-lang/cli and requires Node 20 or newer.

npm install -g @stxt-lang/cli
stxt --version

Without installing, through npx:

npx @stxt-lang/cli validate --recursive docs/

The commands:

Command What it does
stxt validate Parses and validates one or more files or directories; no output when all pass
stxt format Reformats (--tabs / --spaces); --check for CI, --write to save
stxt describe Prints the logical tree of a document as JSON (STXT-TREE-SPEC)
stxt schemas Shows which schemas and templates apply in a directory, and from which level
stxt install Installs a definition into ./.stxt, ~/.stxt or the system level

The exit code distinguishes document errors (1) from command misuse (2). No command rewrites files without an explicit option. The options, outputs and exit codes are in the command-line reference.

Libraries

There are three official implementations: TypeScript/JavaScript, Java and Python. All three pass the conformance kit, which also serves to check a port to another language.

TypeScript / JavaScript

@stxt-lang/core on npm. It is the parser the extension, the command line and the playground use. The guide is in the TypeScript library.

npm install @stxt-lang/core

A minimal example:

import { Parser, InlineNode } from '@stxt-lang/core';

const result = new Parser().parseResult(text);
for (const error of result.getErrors()) {
	console.error(`line ${error.line} [${error.code}]: ${error.message}`);
}
const root = result.getNodes()[0];
if (root instanceof InlineNode) {
	console.log(root.getChild('Title')?.getText());
}

Java

dev.stxt:stxt-core on Maven Central. Java 17 or newer; automatic module dev.stxt. The guide is in the Java library.

<dependency>
    <groupId>dev.stxt</groupId>
    <artifactId>stxt-core</artifactId>
    <version>1.0.3</version>
</dependency>

Or with Gradle:

implementation 'dev.stxt:stxt-core:1.0.3'

Python

stxt on PyPI. Pure Python, 3.10 or newer. The guide is in the Python library.

pip install stxt

A minimal example:

from stxt import Parser, InlineNode

result = Parser().parse_result(text)
for error in result.get_errors():
    print(f"line {error.line} [{error.code}]: {error.message}")
root = result.get_nodes()[0]
if isinstance(root, InlineNode):
    print(root.get_child("Title").get_text())

Source code

The whole ecosystem lives in the stxt-lang organization on GitHub, under the MIT license:

Repository Contents
stxt-lang This site: the specifications, the conformance kit and the example corpus
stxt-js @stxt-lang/core, the TypeScript library
stxt-java dev.stxt:stxt-core, the Java library
stxt-python stxt, the Python library
stxt-cli @stxt-lang/cli, the command line
stxt-vscode The VS Code extension
stxt-play The playground

Questions and ideas about the language go to the discussions of the organization; bugs, to the issues of the repository of the tool concerned.