Skip to content

Commit 67e6990

Browse files
authored
Enhance .kmd format documentation
Updated the .kmd file format documentation to include cross-reference support and format version information.
1 parent 1368df1 commit 67e6990

File tree

1 file changed

+158
-14
lines changed

1 file changed

+158
-14
lines changed

docs/file-format.md

Lines changed: 158 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Technical details about Korppi's native document format.
88

99
The `.kmd` (Korppi Markdown Document) format is a ZIP-based container that stores:
1010

11-
- Markdown content
11+
- Markdown content with cross-reference support
1212
- Version history (timeline)
1313
- Comments and annotations
1414
- Document metadata
@@ -23,6 +23,7 @@ A `.kmd` file is a ZIP archive with this structure:
2323
```
2424
document.kmd (ZIP archive)
2525
├── content.md # Main markdown content
26+
├── format.json # Format version info
2627
├── meta.json # Document metadata
2728
├── patches/ # Timeline patches
2829
│ ├── index.json # Patch list
@@ -33,16 +34,85 @@ document.kmd (ZIP archive)
3334

3435
---
3536

37+
## format.json
38+
39+
Format version information for compatibility:
40+
41+
```json
42+
{
43+
"kmd_version": "0.1.0",
44+
"min_reader_version": "0.1.0"
45+
}
46+
```
47+
48+
| Field | Description |
49+
|-------|-------------|
50+
| `kmd_version` | Version of Korppi that created this file |
51+
| `min_reader_version` | Minimum version required to read this file |
52+
53+
---
54+
3655
## content.md
3756

38-
The main document content in plain Markdown format.
57+
The main document content in Markdown format with support for cross-references.
58+
59+
### Basic Markdown
3960

4061
```markdown
4162
# My Document
4263

4364
This is the actual markdown content of your document.
4465
```
4566

67+
### Cross-References
68+
69+
Korppi supports Pandoc-compatible cross-reference syntax for figures, sections, and tables.
70+
71+
#### Section Labels
72+
73+
Add `{#sec:label}` at the end of any heading:
74+
75+
```markdown
76+
# Introduction {#sec:intro}
77+
78+
## Methods {#sec:methods}
79+
80+
As described in @sec:intro, we use certain methods.
81+
```
82+
83+
#### Figure Labels
84+
85+
Add `{#fig:label}` after an image to create a numbered figure:
86+
87+
```markdown
88+
![Sales chart showing quarterly data](chart.png){#fig:sales}
89+
90+
As shown in @fig:sales, revenue increased.
91+
```
92+
93+
#### Table Labels
94+
95+
Add `{#tbl:label}` on a new line after a table:
96+
97+
```markdown
98+
| Quarter | Revenue |
99+
|---------|---------|
100+
| Q1 | $1.2M |
101+
| Q2 | $1.4M |
102+
103+
{#tbl:quarterly}
104+
105+
See @tbl:quarterly for the data.
106+
```
107+
108+
### Reference Syntax Summary
109+
110+
| Type | Label Syntax | Reference Syntax | Output |
111+
|------|--------------|------------------|--------|
112+
| Section | `{#sec:label}` | `@sec:label` | Section N |
113+
| Figure | `{#fig:label}` | `@fig:label` | Figure N |
114+
| Table | `{#tbl:label}` | `@tbl:label` | Table N |
115+
46116
---
47117

48118
## meta.json
@@ -51,23 +121,71 @@ Document metadata:
51121

52122
```json
53123
{
54-
"id": "uuid-here",
124+
"uuid": "550e8400-e29b-41d4-a716-446655440000",
55125
"title": "My Document",
56126
"created_at": "2024-12-07T12:00:00Z",
57127
"modified_at": "2024-12-07T15:30:00Z",
58-
"author": {
59-
"name": "Jane Doe",
60-
"color": "#ff5733"
128+
"authors": [
129+
{
130+
"id": "author-uuid",
131+
"name": "Jane Doe",
132+
"email": "jane@example.com",
133+
"joined_at": "2024-12-07T12:00:00Z",
134+
"role": "owner"
135+
}
136+
],
137+
"settings": {
138+
"language": "en-US",
139+
"spell_check": true
61140
},
62-
"version": "0.1.0"
141+
"sync_state": {
142+
"last_export": "2024-12-07T14:00:00Z",
143+
"pending_patches": 0
144+
}
63145
}
64146
```
65147

148+
### Fields
149+
150+
| Field | Type | Description |
151+
|-------|------|-------------|
152+
| `uuid` | string | Unique document identifier |
153+
| `title` | string | Document title |
154+
| `created_at` | string | ISO 8601 creation timestamp |
155+
| `modified_at` | string | ISO 8601 last modified timestamp |
156+
| `authors` | array | List of document authors |
157+
| `settings` | object | Document settings |
158+
| `sync_state` | object | Synchronization state |
159+
160+
### Author Object
161+
162+
| Field | Type | Description |
163+
|-------|------|-------------|
164+
| `id` | string | Unique author identifier |
165+
| `name` | string | Display name |
166+
| `email` | string? | Email address (optional) |
167+
| `joined_at` | string? | When author joined (optional) |
168+
| `role` | string? | Role: "owner", "editor", "viewer" (optional) |
169+
170+
### Settings Object
171+
172+
| Field | Type | Default | Description |
173+
|-------|------|---------|-------------|
174+
| `language` | string | "en-US" | Document language |
175+
| `spell_check` | boolean | true | Enable spell checking |
176+
177+
### Sync State Object
178+
179+
| Field | Type | Description |
180+
|-------|------|-------------|
181+
| `last_export` | string? | Last export timestamp (optional) |
182+
| `pending_patches` | number | Number of unsynced patches |
183+
66184
---
67185

68186
## patches/
69187

70-
The timeline patches directory contains:
188+
The timeline patches directory contains version history:
71189

72190
### index.json
73191

@@ -150,6 +268,29 @@ This file enables:
150268

151269
---
152270

271+
## Export Formats
272+
273+
Korppi can export to several formats:
274+
275+
### DOCX Export
276+
277+
Export to Microsoft Word format with:
278+
279+
- Headings preserved with proper styles
280+
- Bold, italic, and strikethrough formatting
281+
- Ordered and unordered lists
282+
- Tables with headers
283+
- Code blocks with monospace font
284+
- Block quotes
285+
- **Cross-references resolved** (e.g., `@fig:sales` → "Figure 1")
286+
- **Figure labels stripped** from output
287+
288+
### Markdown Export
289+
290+
Plain markdown with all cross-reference syntax preserved.
291+
292+
---
293+
153294
## Working with .kmd Files
154295

155296
### Extracting Content
@@ -178,17 +319,18 @@ unzip document.kmd -d extracted/
178319

179320
### Version Compatibility
180321

181-
- `.kmd` files note their version in `meta.json`
322+
- `.kmd` files note their version in `format.json`
182323
- Newer Korppi versions read older formats
183324
- Format upgrades happen automatically on save
325+
- Version checks prevent data loss from incompatible readers
184326

185327
### Markdown Compatibility
186328

187-
The `content.md` file is standard GitHub Flavored Markdown and can be:
329+
The `content.md` file is extended GitHub Flavored Markdown:
188330

189-
- Opened in any text editor
190-
- Rendered by GitHub, GitLab, etc.
191-
- Processed by pandoc, mkdocs, etc.
331+
- **Standard GFM** features work in any markdown renderer
332+
- **Cross-references** (`@type:label`) are Korppi/Pandoc-specific
333+
- **Labels** (`{#type:label}`) are stripped on export to other formats
192334

193335
---
194336

@@ -200,7 +342,8 @@ You can create a `.kmd` file with minimal structure:
200342
# Create minimal structure
201343
mkdir mydoc
202344
echo "# Hello" > mydoc/content.md
203-
echo '{"id":"123","title":"Hello","version":"0.1.0"}' > mydoc/meta.json
345+
echo '{"kmd_version":"0.1.0","min_reader_version":"0.1.0"}' > mydoc/format.json
346+
echo '{"uuid":"123","title":"Hello","created_at":"2024-01-01T00:00:00Z","modified_at":"2024-01-01T00:00:00Z","authors":[]}' > mydoc/meta.json
204347

205348
# Package as .kmd
206349
cd mydoc && zip -r ../hello.kmd . && cd ..
@@ -212,3 +355,4 @@ cd mydoc && zip -r ../hello.kmd . && cd ..
212355

213356
- [Export Options](export.html) - Exporting to other formats
214357
- [Timeline](timeline.html) - Understanding patches
358+
- [Cross-References](cross-references.html) - Using figures, sections, and tables

0 commit comments

Comments
 (0)