[Specification](https://komalang.org/spec/) · Chapter 7 / 7

# Conformance

Conformance covers syntax and meaning, checked by a conformance suite. How a page is drawn is described, not tested pixel by pixel.

## What conformance promises

Conformance promises syntax and meaning. Rendering is described in prose, and pixel-equal output is not promised.

- Syntax: the same source produces the same Koma AST with the same positions. The promised shape is the node kinds (`type`) and fields in [Syntax tree nodes](https://komalang.org/spec/semantics/#ast-nodes)'s table, the kinds of `sourceLine` (`type`), and the positions (`position`) of [unist](https://komalang.org/spec/semantics/#unist). `data` (the Internal column of [Syntax tree nodes](https://komalang.org/spec/semantics/#ast-nodes)'s table; `data.openFence`, `data.line` and `data.close` are the scanner's records) and the internals of the implementation that builds the tree are not promised.
- When the tree's shape is promised: a version promises the tree's shape and positions only when all three hold: the kinds of `sourceLine` are listed in [Syntax tree nodes](https://komalang.org/spec/semantics/#ast-nodes), a test compares the spec's tables with the types in `src/core/lang/ast/tree.ts`, and `data` and the other internals are marked as outside the promise. A version where they do not all hold promises only meaning and diagnostics, and the tree's shape moves to the next version. All three hold now. That depends on the unit test that compares the tables with the types and with trees read from the bundled examples ([Syntax tree nodes](https://komalang.org/spec/semantics/#ast-nodes)) staying green.

- Diagnostics: the same source produces diagnostics with the same codes, severities and ranges (see the list of diagnostics in Semantics).
- Meaning: the same source produces the same placement and sizes ([Placement](https://komalang.org/spec/semantics/#placement), [Who decides size](https://komalang.org/spec/semantics/#size), [Columns and rows](https://komalang.org/spec/semantics/#split)).

- The conformance suite: a set of `.koma` inputs, each with its expected syntax tree, diagnostics and placement in numbers, cut from the unit tests that name a spec ID and use no DOM, and filed by rule ID.
- Rendering: how HTML, PDF and PowerPoint look ([HTML elements and reading order](https://komalang.org/spec/semantics/#html-elements) and the official themes' looks) is informative prose, outside the conformance suite.

- Writers: tools that tidy or edit also keep the standard form ([The standard form](#standard-form)) and the source they did not change ([Saving without change](#round-trip), [Rewriting only what changed](#minimal-rewrite), [Writing back from the app](#write-back)).
- Versions: how the language's version changes follows the compatibility policy below.

## Writers

### The standard form

The standard form is the set way of writing `.koma` that only explicit tidying writes.

#### How to write

Tidy with `koma format --write`, `koma check --write`, or the app's Tidy. Saving and reading never tidy. `koma check` reports source not in the standard form as `not-formatted`. For example, tidying turns `[box.card x=10%: content]` into three lines: `[box .card x=10%:`, ` content`, `]`.

#### Details

- Tidying is one API (`formatKoma`), run only on an explicit action. Existing documents are never rewritten in bulk.
- **Tags and structural lines**: an element's tag ends with `:` ([Tag and content](https://komalang.org/spec/elements/#tag-and-content)). A line without `:` is text or a held-back element shape, so tidying never adds `:` and leaves the line as written (that would change its meaning; the user adds it with the `missing-colon` fix). The words of a tag are separated by one space, attributes are reordered in the order of [Order of attributes](https://komalang.org/spec/elements/#attribute-order), the `:` is attached to the tag's last word, and one space comes before the content. Attribute values lose the quotes of a value of a kind, gain quotes on unquoted text of no kind, and lists are written `(a, b)` ([The kinds of a value](https://komalang.org/spec/lexical/#value-kinds), [Lists of values](https://komalang.org/spec/lexical/#lists)). Trailing spaces on bracketed structural lines are removed. `===`, `---` and `+++` are made three characters, while the reserved characters after them and the inside of YAML (including the value of `css:`) stay as written. Only bracketed structural lines are indented, two spaces per depth.

- **Multi-line elements**: a multi-line opening that ends with `:` keeps it, and one without it never gets it. A multi-line element's body is aligned, from the line after the opening, to the structural indentation of depth × two spaces, the same as its child elements. Attributes split over several lines are left alone.
  - A closing `]` of a multi-line element at the end of a body line is moved to a closing line of its own, keeping the body's spaces and meaning. When the meaning cannot be kept, the line stays as it was.
  - Body text following a multi-line element's opening line moves to the next line, keeping the meaning and the body's spaces, with the structural spaces of its depth. When the meaning cannot be kept, the line stays as it was.

- **One-line elements**: an element whose tag has no `key=value` attribute and whose content is a single run of ordinary text stays on one line (`[title: …]`, `[box.tint: a word]`, `[callout: a word]`; a tag with only an `#id` or classes counts as having no attributes). An element with content whose tag has even one `key=value` attribute is not kept on one line, even when its content is one line: the opening line ends with `:`, the content goes on the next line indented one level, and `]` stands on its own line at the original indentation (three lines: `[table src="…":`, the text, `]`). An empty one-line element puts `]` right after the `:`, with no space (`[image src="…":]`, `[title:]`); reading accepts `: ]` with the same meaning. An empty element written over several lines, such as body, stays as it is. Content with Markdown structure such as emphasis, links, images or math is expanded into separate opening, content and closing lines. Only the structural indentation a line lacks is added; extra is never removed. A one-line element is written with the syntactic one space after the colon and the body exactly as read; spaces in the body are not collapsed.
- **Comments** ([Page boundaries](https://komalang.org/spec/structure/#page-break)): a `;` without a following space gets one, making `; comment`. A `;` line with nothing after it, a line that already has a space (or tab), and a line of several `;` such as `;;` stay as written. Indentation, as in the body, only gets the missing structural spaces. Comments inside notes are not tidied. Keep note opener attributes, inline speech directions, and the whitespace around them ([Elements](https://komalang.org/spec/elements/#element)) as written.

- **Blank lines**: one blank line goes right before each page break and settings opening line that standard reading recognises. None is added at the start of the file, and none inside closing markers or protected areas.
  - One blank line goes before and after a `+++` page break. When the page's `---` settings follow the `+++` directly, the same applies: `+++`, a blank line, then the settings. One blank line also goes right after the closing `===` or `---`. Closed notes ([Elements](https://komalang.org/spec/elements/#element)) get one blank line before the opening `"""` line and after the closing `"""` line, and closed memos ([Memos](https://komalang.org/spec/elements/#memo)) the same around their `:::` lines; none is added at the start or end inside notes, or at the start or end of the file, and unclosed notes keep their surroundings as written. No blank line is added where it would change how the body reads. Existing extra blank lines are not removed. No close or blank line is guessed into an unfinished or invalid YAML block or at the end. An unclosed `---` right after a `+++` is left as written.

- **What is kept**: every character other than safe opening boundaries, the body's structural indentation and the normalisation of the emphasis recognised by [Text inside elements](https://komalang.org/spec/text/#inline-markup); root comments, unknown information, notes and blank lines; Markdown hard breaks; code, math and relative indentation apart from structural indentation and the line split of displayed math; line ends and the byte order mark. A candidate that would change the meaning, such as a new element arising from the body, is not applied. On a page with an unclosed element, structural lines are protected, and from the unclosed opening on, the source is not changed either, since matching with later closing brackets could change. Unclosed or misplaced YAML or CSS and notes stay isolated and reported; tidying never completes them, guesses, or turns them into body text.
- **Tabs**: elements are indented two spaces per depth. A line indented with a tab is not read as an element but drawn as text. A line that would be an element at that depth if the tab were read as two spaces is reported as `tab-indent` (warning), with one fix that turns the tab into spaces. Tabs inside the body, fences, `[code:]`, `[math:]`, `[diagram:]`, settings, CSS and notes are not reported. Tidying leaves the line as written.

- **Displayed math**: written with the opening `$$` and the closing `$$` each on its own line. A line holding only `$$ formula $$` (also as a one-line element's content or an opening line's content) becomes three lines: `$$`, the formula, `$$`. The formula's characters are unchanged, and all three lines take the original line's indentation (or, if it is short, the structural indentation of its depth, by the rule above). The document's line ends are used. Math already in three lines, `$…$` in text, an unclosed `$$`, and a line not read as math (starting `$$ formula` with its close on a later line) stay as written.
- **Selections**: tidying a selection first widens the lines it touches to the whole elements that hold them.

- **Invariants**: before and after tidying, the tree read (apart from source positions, the order of a tag's attributes and how the same value is spelled: quoted or not), the reports (apart from `invalid-unquoted-scalar`, which is only about spelling) and the drawing are the same, and tidying again changes nothing.
- `not-formatted` in `koma check` is measured against this form.

### Saving without change

A file read and saved without changes is byte for byte the same as the original.

#### How to write

Nothing is needed from the writer: the source, with its line ends, byte order mark, spaces and comments, stays as it is.

### Rewriting only what changed

Koma rewrites only the range of characters a change is about.

#### How to write

Nothing is needed from the writer. The formatting of everything else (blank lines, indentation, how attributes are written) is unchanged.

### Writing back from the app

App writeback changes only the source ranges touched by explicit operations. Preserve comments, whitespace, abbreviated forms and unknown attributes. Move geometry updates only the written axes. Refuse an insertion at the end of an unclosed code or math block and explain how to close it.

## Versions and compatibility

Compatibility policy: during 0.x, a minor version (0.1 to 0.2) may change what notation means, and a patch version (0.1.0 to 0.1.1) never does. Each change comes with a one-off migration script and release notes, and older notation is not read for compatibility. When the notation is settled the version becomes 1.0.0, and meanings no longer change. The first release is 0.1.0; until then the development version number stays.
