# Ledu book format

How a book for the Ledu reader is laid out: the folder, the manifest, the section files and
every block a section can hold. Follow it and the book opens in the Ledu app on iPhone and iPad,
with audio, exercises, review cards and stroke animations working.

- Format: **schema 2**, feature level (**formatVersion**) **10**
- JSON Schemas: [book](https://ledu.app/schema/v2/book.schema.json),
  [section](https://ledu.app/schema/v2/section.schema.json),
  [lexicon](https://ledu.app/schema/v2/lexicon.schema.json)
- Starter kit (sample book, schemas, validator, AI brief): https://ledu.app/developers/ledu-book-kit.zip
- This page as one Markdown file: https://ledu.app/developers/book-format.md

The schemas check the shape of each file. The validator in the starter kit also checks what a
schema cannot: ids, asset paths, base-language text and exercise answers. A book is ready when the
validator prints `0 error(s)`.

---

## 1. Ideas in one minute

- A **book** is a folder (a *package*). Its `book.json` is the manifest: what the book is called,
  its cover, its languages and its table of contents.
- The table of contents lists **sections**. Each section is one JSON file of **blocks**, read
  top to bottom: a heading, a paragraph, a word list, a dialogue, an exercise and so on.
- Sections sit directly in the book (`sections`) or inside **chapters** (`chapters`), one level
  deep. Chapters can carry a **group** (a unit) for a second level in the contents.
- A book teaches a **target** language to a reader of a **base** language. Base-language text is a
  **localized map** (`{"en": "…", "zh-Hans": "…"}`); target-language text is a plain string in a
  field named `fa`.
- Audio, images and stroke data are files inside the package, named by paths relative to the
  package folder.

## 2. The package folder

```
my-book/
  book.json             manifest (required)
  cover.png             cover, 2:3 portrait, 1024×1536 px recommended (required)
  sections/             or lessons/: section files named in book.json
    intro.json
    lesson-1.json
  audio/                mp3 clips named by the sections
  images/               png / jpg / webp named by the sections
  strokes/              stroke data for writing blocks (only books that teach writing)
  lexicon.json          word senses (only books with passage blocks)
```

Folder names other than `strokes/` are free: a path in a section is all the reader follows.
Keep every path relative, with forward slashes and no `..`. Use lower-case file names without
spaces.

## 3. Shared value types

| Name | Shape | Notes |
|---|---|---|
| **Localized** | `{"en": "Hello", "zh-Hans": "你好", "zh-Hant": "你好", "fr": "Bonjour"}` | Base-language text. Keys are locale codes; must include the book's `language.base`. The reader shows the user's language when present, else the base. Recognized keys today: `en`, `fr`, `zh-Hans`, `zh-Hant`. |
| **Target text** | `"fa": "سلام"` | Text in the language being taught. The field is called `fa` in every book, whatever the language (the format began with Farsi). |
| **pron** | `"pron": "salām"` | Romanization or reading guide for the target text. Optional, but expected for beginners. |
| **gloss** | Localized | The meaning of target text in the base language. |
| **audio** | `"audio": "audio/l1/salam.mp3"` | Path to an mp3 in the package. Optional everywhere it appears, except where an exercise needs it. |
| **Sentence item** | `{"fa", "pron"?, "gloss", "audio"?, "speaker"?, "speakerTarget"?}` | One line of target text. Used by `sentences`, `phraseList`, `practiceWords`, `readLadder` and others. |
| **id** | string | Every block has an `id`, unique within its section file. Ids are used for bookmarks, search, progress and review; keep them stable between versions of a book. |

## 4. `book.json`: the manifest

```json
{
  "schema": 2,
  "meta": {
    "id": "c7a8a5e2-3f0b-4c39-9a51-0f3c2d6b1e10",
    "name": "spanish-first-steps",
    "displayName": { "en": "Spanish · First Steps" },
    "subtitle": { "en": "Greetings and introductions" },
    "cover": "cover.png",
    "type": "course",
    "access": "free",
    "direction": "ltr",
    "language": { "target": "es", "base": "en" },
    "level": "A1",
    "version": "1.0.0"
  },
  "features": { "flashcards": true },
  "chapters": [
    {
      "id": "sfs-l01",
      "name": "lesson-1",
      "title": { "en": "Lesson 1 · Hola" },
      "group": { "id": "u1", "name": "unit-1", "title": { "en": "Unit 1 · Meeting people" } },
      "sections": [
        { "id": "sfs-l01-learn", "name": "learn", "title": { "en": "Learn" }, "file": "lessons/lesson-1-learn.json", "audio": true },
        { "id": "sfs-l01-practice", "name": "practice", "title": { "en": "Practice" }, "file": "lessons/lesson-1-practice.json" }
      ]
    }
  ]
}
```

### Top level

| Field | Required | Meaning |
|---|---|---|
| `schema` | yes | Always `2`. |
| `meta` | yes | What the book is (below). |
| `sections` **or** `chapters` | exactly one | The table of contents. A flat list of sections, or chapters that each hold sections. Never both. |
| `features` | no | Optional reader features, each `false` when absent: `flashcards` lets readers save words to their own review decks; `titleOnlyHeader` shows only Back and the title in the reader header. |
| `style` | no | Optional book styling. `literature` supplies named reader presets for `verse` blocks; `blocks` defines the book's own looks for any block kind (both below). |
| `formatVersion` | no | Written by Ledu at publish time ([versions](https://ledu.app/developers/validation/#versions-and-compatibility)). Leave it out. |

### Literature styles

Feature level 6 supports native frames and writing rules, with no background images or CSS.
Store presets in `book.json`; they travel with every normal edition or sample download.
Readers choose a preset in **Reading style**. That choice is saved per edition independently
of original/simplified text and horizontal/vertical layout. An unset or removed choice uses
the publisher's `default` preset. Books without these presets keep their existing rendering.

```json
"style": {
  "literature": {
    "default": "classic",
    "presets": [{
      "id": "classic",
      "name": {"zh-Hans": "古籍双框", "zh-Hant": "古籍雙框"},
      "font": "serif", "fontSize": 26, "columnSpacing": 1.55,
      "lineSpacing": 12, "stanzaSpacing": 24, "contentInset": 18,
      "metadata": "leading", "titleFontSize": 34, "chapterFontSize": 18,
      "border": {"outerWidth": 2, "innerWidth": 0.5, "gap": 5, "radius": 0},
      "rules": {"width": 0.5, "opacity": 0.6},
      "colors": {
        "light": {"paper": "#F9F5E9", "ink": "#24221D", "decoration": "#A79A83"},
        "dark": {"paper": "#24231F", "ink": "#EDE6D5", "decoration": "#9D927F"}
      }
    }]
  }
}
```

`default` must name one of 1–20 presets; ids are unique lower-case slugs. Every preset needs
`id` and a localized `name` including the edition's base locale. Other fields are optional:

| Field | Values / range | Default |
|---|---|---|
| `font` | `system`, `serif`, `rounded`, `monospaced` | `system` |
| `fontSize` | 12–48 points, scaled by the reader's text size and Dynamic Type | 22 |
| `titleFontSize`, `chapterFontSize` | Opening vertical heading: 12–72 / 10–48 points, scaled by Dynamic Type (feature level 7) | 1.3 × / 0.7 × `fontSize` |
| `notesFontSize` | Modern notes: 10–32 points, capped at 0.85 × body size, scaled by Dynamic Type (feature level 8) | 0.7 × `fontSize` |
| `notesSeal` | One character in a native red seal beside the notes heading horizontally, above it vertically (feature level 9) | none |
| `columnSpacing` | 1.15–3 × font line height | 1.45 |
| `lineSpacing`, `stanzaSpacing` | 0–40 / 0–80 points | 8 / 24 |
| `contentInset` | 8–48 points; increased as needed to clear the border | 18 |
| `metadata` | `above`, `side` (vertical title/source at lower left), `leading` (opening vertical column, feature level 7) | `above` |
| `border` | `outerWidth`, `innerWidth`: 0–6; `gap`: 2–16; `radius`: 0–32 points | No frame; omitted widths 0, gap 5, radius 0 |
| `rules` | `width`: 0–3 points; `opacity`: 0–1 | No rules; inside a rules object: width 0.5, opacity 0.55 |
| `colors` | Optional `light`, `dark`, `sepia` objects, each with optional `paper`, `ink`, `decoration` in `#RRGGBB` | Reader theme colours |

Rules separate vertical columns or underline authored horizontal lines. Long vertical passages
scroll horizontally from the right; their characters and stanza breaks remain intact. Side
metadata moves above/below at accessibility text sizes or on narrow panels. Missing colour
fields use the reader theme, including system dark mode. `paper` fills both the content block
and the surrounding reading area, including the bottom safe area, for one continuous background.
Fonts use available system families;
unavailable Chinese serif fonts fall back to the platform's Chinese glyphs. Use a preset without `border` and
`rules` for an undecorated alternative. Add further presets in a book update without changing
the app; new rendering capabilities still require an app/format update.

With `metadata: "leading"`, the verse title and its source/chapter share the first, rightmost
column, using `titleFontSize` and `chapterFontSize`. One full blank column separates them from
the poem. The heading scrolls with the text and wraps into more columns if needed at large text
sizes; no characters are clipped. The duplicate reader title above the controls is hidden in
this vertical layout. Horizontal layout keeps its title above the poem and source below it.

### Book colours

A book can set its own colours for each reading theme under `style.palette`. The reader still
chooses the theme; the book says what that theme looks like in this book.

```json
"style": {
  "palette": {
    "light": { "accent": "#8A4B2A", "accentTint": "#F6E9DD", "bg": "#FFFBF5" },
    "dark":  { "accent": "#D9A27E", "accentTint": "#3A2A20" }
  }
}
```

Each of `light`, `dark` and `sepia` maps a colour name to `#RRGGBB`. Names: `bg` (page),
`surface` (cards and boxes), `textPrimary`, `textMuted`, `accent`, `accentDark`, `accentTint`,
`accentDeep`. A name the book leaves out keeps Ledu's colour. Sepia without its own set uses
`light`; dark without its own set keeps Ledu's colours, so a book that only sets `light` stays
readable at night. Check that text colours stay readable on the backgrounds you choose in every
theme you set.

The colours apply to the whole book: the page, headings, cards and every block. A block preset
(below) can change them again for one kind of block. A reader that does not know `palette`
shows Ledu's colours, so it needs no higher `formatVersion`.

### Text styles

A book can restyle its text under `style.roles`: a role name, then what to change. Anything the
book leaves out keeps Ledu's look.

```json
"style": {
  "roles": {
    "body":      { "size": 18, "lineHeight": 1.5 },
    "h2":        { "size": 26, "color": "@accentDeep" },
    "caption":   { "italic": true },
    "secondary": { "size": 15, "weight": "medium" }
  }
}
```

| Field | Meaning |
|---|---|
| `size` | Point size at the standard text size, 8–72. It grows and shrinks with the reader's text-size setting and the device's Dynamic Type size. |
| `weight` | `regular`, `medium`, `semibold` or `bold`. |
| `italic`, `mono`, `underline` | `true` to set the text in italics, in a fixed-width face, or underlined. |
| `lineHeight` | Line height as a multiple of the size, 1–2.5. |
| `color` | `#RRGGBB`, or `@` and a colour name from *Book colours*. A plain `#RRGGBB` is the same in every theme; prefer a colour name. |
| `lockSize` | `true` keeps the size fixed whatever the reader's text size. Use sparingly: it works against readers who need larger text. |
| `lockColor` | `true` keeps the colour as in the light theme in every theme. |

Roles that set the **size and face** of text:

| Role | Used for | Ledu's size |
|---|---|---|
| `h1`, `h2`, `h3` | `heading` blocks | 28, 22, 18 |
| `body` | `text` blocks and explanations | 16 |
| `sectionTitle` | the largest titles inside a block | 22, bold |
| `title` | card and block titles | 20 |
| `number` | large numbers | 20 |
| `label` | bold labels and small headings | 17, semibold |
| `control` | buttons and tappable labels | 15, semibold |
| `line` | lines of text inside cards, lists and tables | 15 |
| `secondary` | supporting lines, such as a translation under a sentence | 13 |
| `caption` | captions and small labels | 12 |
| `fine` | the smallest print | 11 |

These last nine are a scale shared by every block: changing `secondary` changes every
supporting line in the book, whichever block it sits in.

Roles that set a **colour** (`color`, `lockColor`): the ones above, and `quote`, `link`,
`highlight`, `target`, `gloss`, `pron`, `speaker`, `marker`, `example`, `instruction`,
`componentTitle`, `tableHeader`, `tableRowAlt`, the vocabulary card (`vocabCardBg`,
`vocabPanelTop`, `vocabPanelBg`, `vocabCurrentBg`, `vocabBorder`, `vocabWord`, `vocabPron`,
`vocabGloss`), the code block (`codeText`, `codeFile`, `codeLang`) and exercise cards
(`exerciseCard`, `exerciseSelected`, `exerciseCorrect`, `exerciseWrong`, `exerciseRevealed`).

Limits today: most target-language text (sentences, words, letters) is drawn at Ledu's own
sizes and does not yet follow `size`; a book cannot yet bring its own typeface. Text styles
never change a block's layout. A reader that does not know `roles` shows Ledu's look, so they
need no higher `formatVersion`.

### Block presets

A book can define its own looks for any block kind under `style.blocks`: the kind, then a
preset name. A block uses one by naming it in its `style`. The name `default` applies to every
block of that kind that names no style (or one that is not defined).

```json
"style": {
  "blocks": {
    "callout": {
      "default": { "colors": { "light": { "accent": "#8A4B2A", "accentTint": "#F6E9DD" },
                               "dark":  { "accent": "#D9A27E", "accentTint": "#3A2A20" } } },
      "warm":    { "frame": { "background": "@accentTint", "border": "@accent", "radius": 12 } }
    },
    "box": { "ruled": { "look": "double" } }
  }
}
```

| Field | Meaning |
|---|---|
| `look` | A built-in style of the kind to draw with (such as `double` for `box`). |
| `colors` | `light`, `dark` and `sepia` sets; each maps a colour name to `#RRGGBB`. Names: `bg`, `surface`, `textPrimary`, `textMuted`, `accent`, `accentDark`, `accentTint`, `accentDeep`. Sepia without its own set uses `light`; dark without its own set keeps Ledu's colours. |
| `frame` | A panel around the block: `background` and `border` (`#RRGGBB` or `@` and a colour name), `borderWidth` 0–4, `radius` 0–32, `padding` 0–32. |

Blocks inside a container (a `box`, `callout` or `collapsible`) are drawn in the container's
preset colours; a nested block's own preset replaces only the colours it names. A frame and a
`style` name apply to their own block only.

Presets change colours and the frame only, never the block's layout or content. A reader that
does not know presets shows the default look, so they need no higher `formatVersion`. Some
blocks still draw part of themselves in fixed colours that `colors` does not reach.

### `meta`

| Field | Required | Meaning |
|---|---|---|
| `id` | yes | Permanent unique id, 8+ characters. Use a UUID; never change it. |
| `name` | yes | Package name: lower case, digits and hyphens (`^[a-z0-9-]+$`). Same as the folder name. |
| `displayName` | yes | Localized title. |
| `subtitle` | no | Localized subtitle. |
| `cover` | yes | Path to the cover image. |
| `editionCovers` | no | Authoring-only map such as `{"zh-Hans":"cover-sc.png","zh-Hant":"cover-tc.png"}`. Every published edition must have an entry when this map is present. Publishing sets `cover` to that image and removes the map and unused artwork; the default `cover` remains required in the master package. |
| `thumbnail` | no | Path to a smaller cover. Ledu makes sized copies of the cover itself, so this is rarely needed. |
| `type` | yes | `course` (lessons), `syllabary` (a kana-style chart book), `positionalScript` (letters that change shape by position, such as Arabic or Persian), `reference` (look-up material). |
| `access` | yes | `free` or `paid`. Sections can override it (below). |
| `direction` | yes | Reading direction of the target language: `ltr` or `rtl`. |
| `language.target` | yes | BCP-47 code of the language taught: `es`, `ja`, `fa`, `ar` … |
| `language.base` | yes | Locale code of the explanations: `en`, `zh-Hans` … Every localized map must contain it. |
| `version` | no | Semantic version of this edition (`1.0.0`). Raise it for every new upload. |
| `level` | no | CEFR-style level, such as `A1`. |
| `seriesGroup` | no | Series name, to group the book with its siblings. |
| `category`, `tags` | no | Free strings for the catalogue. |
| `publishedAt`, `sku` | no | Set by Ledu when the book is published. Leave them out. |

### Section reference (inside `sections` or a chapter's `sections`)

| Field | Required | Meaning |
|---|---|---|
| `id` | yes | Unique in the book, stable across versions. |
| `name` | yes | Short slug, such as `listen`. |
| `title` | yes | Localized. |
| `file` | yes | Path to the section file. No `#`. |
| `audio` | no | `true` when the section has audio (the reader then offers playback controls). |
| `icon` | no | Name of an icon. |
| `preview` | no | `true` makes the section readable before a paid book is bought. |
| `access` | no | `free` or `paid`, overriding the book. |
| `video` | no | Reserved. |

### Chapter

| Field | Required | Meaning |
|---|---|---|
| `id`, `name`, `title` | yes | As for a section. |
| `sections` | yes | Section references. |
| `group` | no | `{id, name, title}`: the unit this chapter belongs to. Consecutive chapters with the same group id are shown together. |
| `access` | no | `free` or `paid` for the whole chapter. |
| `available` | no | `false` shows the chapter as coming soon. |
| `icon`, `downloadable`, `hasVideo` | no | Reserved. |

## 5. Section files

```json
{
  "schema": 2,
  "id": "sfs-l01-learn",
  "name": "learn",
  "blocks": [
    { "kind": "heading", "id": "h1", "level": 2, "text": { "en": "Saying hello" } },
    { "kind": "text", "id": "t1", "text": { "en": "Spanish has one word for hello at any time of day." } }
  ]
}
```

| Field | Required | Meaning |
|---|---|---|
| `schema` | yes | `2`. |
| `id` | yes | The section id from `book.json`. |
| `name` | yes | The section name from `book.json`. |
| `blocks` | yes | The content, in reading order. |

Every block has `kind` and `id`. Container blocks (`box`, `callout`, `collapsible`) hold more
blocks in their own `blocks` array.

**Styles.** Any block may also carry `style`, a name for the look it should have, such as
`{ "kind": "box", "style": "double", … }`. Each kind has a default look and may offer more; a
reader that does not know the name draws the default, so a new style never hides content and
needs no higher `formatVersion`. Styles today: `box` has `double` (a double-line border; the
older `"variant": "double"` still works), and `callout` takes any name defined under
`style.callouts` in `book.json`, falling back to its `variant`. A book can also define its
own named looks for any kind (*Block presets*, under `book.json`).

## 6. Block reference

`L` means a Localized map. `?` marks an optional field. Field names are case-sensitive.

### 6.1 Text and structure

| kind | Fields | Shows |
|---|---|---|
| `heading` | `text` L, `level`? 1–3 | A heading. |
| `text` | `text` L, **or** `runs` | A paragraph. See *Rich text* below. |
| `quote` | `text` L, `cite`? L | A quotation. |
| `list` | `items`: `[{text: L}]` or `[{blocks: [...]}]`, `ordered`? | A bulleted or numbered list. |
| `divider` | `variant`? | A rule between parts. |
| `box` | `blocks`, `variant`? | A plain panel around blocks. |
| `callout` | `variant` (`note` or `key`), `blocks`, `title`? L | A highlighted panel: `note` for an aside, `key` for the point to remember. |
| `collapsible` | `title` L, `blocks`, `defaultOpen`? | A panel the reader opens. |
| `table` | `columns`, `rows` | A table (below). |
| `image` | `src`, `alt`?, `caption`? L, `width`?, `height`?, `bleed`? | A picture. `bleed: true` runs it edge to edge. |
| `audio` | `src`, `label`? L, `inline`? | A play button for one clip. |
| `lessonLink` | `chapterID`?, `sectionID`?, `title`? L | A link to another part of the book. |
| `code` | `code`, `language`?, `filename`? | Preformatted code. |
| `terms` | `items`: `[{term: L, def: L}]` | A glossary of base-language terms. |
| `nextBook` | `work`, `title` L, `button` L, `text`? L | A card at the end of a book pointing to the next one (`work` is its package name). |

**Rich text.** Instead of `text`, a `text` block can carry `runs`: for each locale a list of runs,
each `{ "t": "words", "marks": [...] }`.

```json
{ "kind": "text", "id": "t2", "runs": {
  "en": [
    { "t": "Say " },
    { "t": "hola", "marks": [{ "kind": "gloss", "target": "hola", "base": { "en": "hello" }, "pron": "OH-lah" }] },
    { "t": " to anyone. It is ", "marks": [] },
    { "t": "never", "marks": ["bold"] },
    { "t": " rude." }
  ] } }
```

Marks: `bold`, `italic`, `underline`, `highlight`, `code`, `{"kind": "link", "href": "https://…"}`,
and `{"kind": "gloss", "target", "base": L, "pron"?}` (a tappable word with its meaning).

**Tables.** `columns` is a list of `{id, title: L, width?, align?}`; `width` is `"auto"`, `"flex"` or
a number of points; `align` is `leading`, `center` or `trailing`. `rows` is a list of rows, each a
list of cells `{text: L}` or `{blocks: [...]}`, with `audio`? and `span`? `{col, row}`.

### 6.2 Target-language lines

| kind | Fields | Shows |
|---|---|---|
| `vocab` | `entries`: `[{fa, pron, gloss, type, marked?, audio?, image?, imageFill?, emoji?, extra?, pitch?}]` | Word cards. `type` is the part of speech label (`noun`, `verb` …). `marked` is the word with vowel marks or kana reading. `extra: true` marks a word that is not core. `pitch` is a Japanese pitch-accent number. Words here feed review. |
| `sentences` | `items`: sentence items, `numbered`? | Example sentences with audio. |
| `phraseList` | `items`: sentence items | A phrasebook list. |
| `practiceWords` | `items`: sentence items, `highlight` | Words to read aloud; `highlight` is the letter or part to colour in each. |
| `dialogue` | `turns`: `[{fa, gloss, pron?, audio?, speaker?: L, speakerTarget?}]`, `title`? L, `titleTarget`? | A scripted conversation. |
| `chat` | `turns`: `[{fa, gloss, pron?, audio?, speaker?: L, speakerTarget?, me?, colloquial?: {fa, pron?, audio?}}]`, `labels`?: `{book: L, spoken: L}` | The same conversation as chat bubbles. `me: true` puts the turn on the reader's side. With `colloquial` forms and `labels`, the reader can switch between the written and the spoken register. |
| `colloquial` | `items`: `[{formal: {fa, pron?, audio?}, colloquial: {fa, pron?, audio?}}]`, `title`? L, `note`? L | Written form next to everyday spoken form. |
| `conjTable` | `rows`: `[{fa, gloss, pron?, person?}]`, `caption`? L | A conjugation table. |
| `rootCard` | `label`, `text` L, `pron`? | A word root or stem with its meaning. |
| `pronGuide` | `items`: `[{glyph, ipa, hint?: L, word?, pron?, gloss?: L, note?: L}]` | How each sound is written and said. |
| `readLadder` | `rows`: `[{label: L, items: sentence items}]`, `hint`? L | Reading practice from easy to hard. |

### 6.3 Grammar

| kind | Fields | Shows |
|---|---|---|
| `note` | `body` L, `label`?, `examples`? | A grammar note. |
| `rule` | `body` L, `label`?, `examples`? | A grammar rule. |
| `legend` | `items`: `[{title, body: L, examples?}]`, `title`? L | A set of short explanations (`title` is a plain string, often target text). |

An **example** is `{fa, gloss, pron?, highlight?: {fa?, pron?}, parts?}`. `highlight` colours the
part of the line the note is about. `parts` labels the line by role, each `{t, role}`; `t` must
appear in `fa` in order, and `role` is one of `topic`, `subject`, `frequency`, `time`,
`companion`, `place`, `object`, `predicate`, `verb`.

### 6.4 Lesson flow

| kind | Fields | Shows |
|---|---|---|
| `lessonOpener` | `goals`: `[L]`, `title`? L, `letters`?: `[string]`, `meta`? L | The start of a lesson: what the reader will be able to do, letters it introduces, time and steps (`meta`). |
| `quickCheck` | `question` L, `choices`: `[{fa} or {text: L}]` (2+), `answer` (index from 0), `explain`? L | One question with instant feedback. Nothing is recorded. |
| `goalCheck` | `goals`: `[L]`, `title`? L, `progress`? L | The lesson's goals as a checklist at the end. `progress` may use `{done}` and `{total}`. |
| `exercise` | see 6.5 | A scored exercise. |

### 6.5 Exercises

Every exercise: `{kind: "exercise", id, exerciseType, instruction: L, prompt, answer,
feedback?: {explain: L}, scoring?: {points (default 1), attempts (default 3)}}`.

A **choice item** is `{id, fa}` (target text) or `{id, text: L}` (base text), with an optional
`audio`. Order segments are always `{id, fa}`. The prompt may also
carry `fa` and `pron` (a target sentence), `text` L, `gloss` L, `hint` L and `audio`.

| exerciseType | prompt | answer | Rule |
|---|---|---|---|
| `choice` | `choices` | `choiceIds`: `[id]` | Each id is one of the choices. |
| `listenSelect` | `audio`, `choices` | `choiceIds` | Needs `audio`. |
| `dictation` | `audio`, `hint`? L | `accepted`: `[string]` | Needs `audio` and at least one accepted answer. |
| `match` | `left`, `right`: choice items | `pairs`: `[[leftId, rightId]]` | Every left id is paired exactly once. |
| `order` | `segments`: `[{id, fa}]` | `order`: `[id]` | The order is all segment ids, each once. |
| `fillBlank` | `template` with `{{1}}`, `{{2}}` …, `wordBank`?, `text`? L | `blanks`: `[[accepted, …], …]` | Slots numbered 1..n with no gaps; one non-empty list per slot. The first accepted answer is the one shown. |

```json
{ "kind": "exercise", "id": "p3", "exerciseType": "fillBlank",
  "instruction": { "en": "Complete the sentence." },
  "prompt": { "template": "Me {{1}} Ana.", "wordBank": ["llamo", "llama", "llaman"], "text": { "en": "My name is Ana." } },
  "answer": { "blanks": [["llamo"]] },
  "scoring": { "points": 1, "attempts": 3 } }
```

### 6.6 Passages (formatVersion 2)

A `passage` is a longer text where every word can be tapped for its meaning and every sentence
plays and highlights its audio.

```json
{ "kind": "passage", "id": "story", "title": { "en": "At the café" },
  "paragraphs": [ { "sentences": [
    { "fa": "Hola, ¿qué tal?", "pron": "", "gloss": { "en": "Hi, how are you?" }, "audio": "audio/story-1.mp3",
      "words": [ { "t": "Hola", "s": "hola" }, { "t": "qué", "s": "que-what" }, { "t": "tal", "s": "tal" } ] }
  ] } ] }
```

- Each word `{t, s?, f?}`: `t` is the word as written, found in the sentence's `fa` in order;
  `s` is a `senseId` in `lexicon.json`; `f` is a short form note (`"past, I"`). A number or a word
  left untagged has no `s`.
- A book with any passage needs `lexicon.json` at the package root:

```json
{ "schema": 1, "entries": [
  { "senseId": "hola", "fa": "hola", "pron": "OH-lah", "gloss": { "en": "hello" }, "type": "interjection", "audio": "audio/w-hola.mp3", "lesson": 1 }
] }
```

Each entry: `senseId` (unique), `fa`, `pron`, `gloss` L, `type`, and optional `marked`, `audio`,
`lesson` (the lesson number that teaches it) and `extra`. Two meanings of one spelling are two
senses.

### 6.7 Scripts and writing

For books that teach an alphabet or characters.

| kind | Fields | Shows |
|---|---|---|
| `grid` | `layout`, `rows`, `details`? | A tappable chart of letters or kana (below). |
| `letterForms` | `cells`: `[{glyph, cellId?, label?: L, word?: sentence item}]`, `highlight` | The shapes of one letter, each with an example word. |
| `writingForms` | `word`, `separateLabel` L, `joinedLabel` L, `letters`: `[{isolated, form, colorRole, label: L}]` | A word shown letter by letter, then joined. `colorRole`: `isolated`, `initial`, `medial`, `final`. |
| `vowelMarks` | `forms`: `[{glyph, sound, name: L, audio?}]`, `words`?: `[{marked, plain, sound, gloss: L, audio?}]` | Short-vowel marks, shown large. |
| `strokeGuide` | `glyph`, `cellId`? | One character with its stroke order. |
| `strokeGuideRow` | `cells`: `[{glyph, cellId?, label?: L}]` | Several characters in a row, each with stroke order. |
| `writingAnimation` | `glyph`, `cellId`?, `autoplay`?, `loop`? | A character drawing itself. |
| `articulation` | `src`, `text` L, `title`? L | A mouth diagram with how to make the sound. |
| `mathAnim` | `name`, `caption`? L | Reserved for animations built into the app. |

**Grid.** `layout` is
`{rows: {header: bool, title?: L}, columns: {header: bool, items: [{id, title: L}]}, cellAspect: "square" | "wide", direction?: "ltr" | "rtl"}`.
Each row is `{id, header?: {label: L, subLabel?, audio?, tap?}, cells: [{id?, glyph, subLabel?, native?, audio?, tap?}]}`.
`tap` is `{"action": "audio"}`, `{"action": "detail", "ref": "<key in details>"}` or
`{"action": "link", "href": "…"}`. `details` maps a ref to `{title?: L, blocks: [...]}`, a page
opened from the cell.

**Stroke data.** Writing blocks find their strokes in `strokes/<cellId>.json` (or the glyph when
there is no `cellId`), with an optional `strokes/<cellId>.svg` outline:

```json
{ "cellId": "a-iso", "glyph": "a", "recordedAt": "2026-01-01T00:00:00Z",
  "strokes": [ { "points": [ { "x": 0.75, "y": 0.62, "t": 0.0 }, { "x": 0.70, "y": 0.62, "t": 0.05 } ] } ] }
```

`x` and `y` run from 0 to 1 across a square cell (origin top left); `t` is seconds from the
start of that stroke. Strokes are drawn in list order.

### 6.8 Japanese: furigana (formatVersion 3)

Readings over kanji are written inside target text with Unicode interlinear annotation:
`U+FFF9` base `U+FFFA` reading `U+FFFB`. For example `"￹日本￺にほん￻に いきます。"`.

In a book whose target language is `ja`:

- Every kanji in `fa` text carries its reading, unless it is in a vocabulary entry, whose
  reading goes in `marked` instead.
- Do not put annotation in `template`, `wordBank`, `speakerTarget` or passage text, which are
  shown as plain text. Use kana there.

### 6.9 Chinese verse (formatVersion 5)

A `verse` block preserves authored lines and stanzas. Each title and line carries both
`original` and `simplified` strings. Both survive publishing into either Chinese edition.
The original string is the publisher's transcription of its identified source, including
variant characters and editorial punctuation. Supply and review the simplified text separately.

```json
{
  "kind": "verse",
  "id": "guanju",
  "title": { "original": "關雎", "simplified": "关雎" },
  "stanzas": [{
    "id": "stanza-1",
    "lines": [{
      "id": "line-1",
      "text": { "original": "關關雎鳩，在河之洲。", "simplified": "关关雎鸠，在河之洲。" }
    }]
  }]
}
```

`title` and `source` are optional. `source` is a localized map for source attribution.
From feature level 10, optional `sourceForms: {"original": "國風 · 周南", "simplified": "国风 · 周南"}`
lets the subtitle follow the title/body text toggle. Both forms survive edition packaging;
when absent, the edition-localized `source` remains the fallback. In horizontal reading the
subtitle sits immediately below the title, before the poem.
Every stanza has a stable unique `id` and a nonempty `lines` array. Line IDs are unique within
the poem. Both text strings are nonempty and contain no embedded line breaks. Stanza and line
arrays define reading order. The excerpt above illustrates the structure for authoring.

Set `meta.direction` to `ltr` and `meta.language.base` to the edition's `zh-Hans` or `zh-Hant`.
Chinese reader controls, contents, search and bookmark sheets follow that base locale. The
reader independently selects original or simplified text, and horizontal or vertical reading.
A book of classical text sets `"plainText": true` in `style.literature`. Its readers then see
the lines of a verse without punctuation by default, as classical Chinese was written, and get
a control that turns the punctuation on; keep the punctuation in the source text. Without
`plainText` (the default, and right for every other language) verse always shows its
punctuation and line breaks as written, and there is no control. Pause, stop,
quotation and title marks are hidden; brackets and a variant slash are kept. Without punctuation
the lines of a stanza run on as one paragraph, and only the break between stanzas remains, so
use a new stanza wherever a blank line must stay. Titles, sources and
notes always show their punctuation. These preferences are saved per edition. Vertical verse reads top to bottom, with successive
columns running right to left. Native vertical glyph forms position punctuation and brackets.
Long lines wrap into additional columns. Controls remain horizontal; subtitle placement follows
the selected literature preset.
Search indexes both transcriptions against the same block and section IDs.

Feature level 8 adds optional `notes` to a verse:

```json
"notes": {
  "title": {"zh-Hans": "注释", "zh-Hant": "註釋"},
  "text": {"zh-Hans": "河边鸟鸣引出对伴侣的思念。", "zh-Hant": "河邊鳥鳴引出對伴侶的思念。"}
}
```

Both maps are required and nonempty when `notes` is present. Notes follow the edition language,
independently of the poem's original/simplified selection. They appear after one blank line
(one blank column in vertical reading), in smaller type with a bold heading. `notesFontSize`
customizes that type size within the bounds above. Notes participate in search, proofing and
paid-book sample packaging. Original poem lines and stable IDs remain unchanged.

Notes may carry subheadings. Put each subheading in `text` as a paragraph of its own (paragraphs
are separated by one blank line) and list it in the optional `subtitles` array, one localized
map per subheading:

```json
"notes": {
  "title": {"zh-Hans": "导读", "zh-Hant": "導讀"},
  "text": {"zh-Hans": "此文出自杜甫的《春望》。\n\n白话解读\n\n国都沦陷，山河还在。", "zh-Hant": "…"},
  "subtitles": [{"zh-Hans": "白话解读", "zh-Hant": "白話解讀"}]
}
```

A paragraph that equals a listed subtitle is set in the same bold type as the notes heading. An
app that does not know `subtitles` shows the paragraph in ordinary type, so it needs no higher
feature level.

Notes may also carry `verticalText`, a second localized map with the same keys as `text`. The
reader shows it in place of `text` when the verse is read vertically. Use it where the
horizontal notes hold text that sets badly in a vertical column: a Chinese classic gives a
reading as pinyin in brackets in `text` (`雎鳩（jū jiū）`), which would lie on its side in a
column. In `verticalText` each character carries its own pinyin as an annotation, written like
furigana: `U+FFF9` character `U+FFFA` pinyin `U+FFFB`, one character per annotation
(`￹雎￺jū￻￹鳩￺jiū￻`). The reader keeps the characters in line down the column and sets each
pinyin upright to the left of its character, ending at the character. Search and proofing use
`text`. An app that does not know `verticalText` shows `text` in both directions, so it needs
no higher feature level.

Reader toolbar buttons change text form and reading direction with one tap. The style icon
cycles through publisher presets in order, wrapping to the first; VoiceOver announces the
edition-localized current value. No popup is needed for these three controls.

## 7. Rules the validator checks

Beyond the schemas:

1. Every section file named in `book.json` exists, and the cover exists.
2. Every asset path (`audio`, `src`, `image`) points to a file in the package. Full `https://`
   URLs are allowed but not recommended: books must work offline.
3. Every localized map contains the base locale.
4. Block ids are unique in each section file.
5. Exercise answers match their prompts ([Exercises](https://ledu.app/developers/exercises/)).
6. Passage words appear in their sentence in order and name a sense in `lexicon.json`; sense
   ids are unique and their audio exists.
7. Example `parts` use a known role and appear in the line in order.
8. Japanese books follow the [furigana rules](https://ledu.app/developers/scripts/#japanese-furigana-formatversion-3).

Run it from the starter kit:

```bash
pip install jsonschema
python3 validate_books.py path/to/my-book
```

## 8. Writing a good book

- **Target text is never translated in place.** `fa` holds the language taught; meanings go in
  `gloss`. Romanization goes in `pron`, never in `fa`.
- **Give every target line audio** where you can: one mp3 per line, mono, 44.1 or 48 kHz,
  trimmed, normalized to similar loudness. Name files by lesson (`audio/lesson-3/…`).
- **Keep ids stable.** Readers' progress, bookmarks and review cards follow block and section
  ids. Rename text freely; keep the ids.
- **One idea per block.** Prefer several small blocks to one large `text` block; the reader
  scrolls, searches and bookmarks by block.
- **Lesson rhythm that works:** `lessonOpener` → listen (`dialogue` or `chat`) → words
  (`vocab`) → grammar (`note`, `rule`, `legend`) → `quickCheck` along the way → `exercise`s
  → `goalCheck`.
- **Images** under 300 KB each where possible (jpg for scenes, png for diagrams). The cover is
  2:3 portrait.
- **Right-to-left books** set `direction: "rtl"`. The reader lays out target text right to left
  and base text in its own direction.

## 9. Versions and compatibility

- `schema` changes only for breaking changes. A reader that knows schema 2 cannot open
  schema 3.
- `formatVersion` (feature level) rises by one whenever a block kind, text mark or exercise
  type is added. Ledu works out the lowest level each book needs when it is published, so a book
  that uses nothing new stays readable on older app versions. Level 1 is everything not listed
  below; level 2 adds `passage`; level 3 adds furigana; level 4 adds public paid-book samples;
  level 5 adds Chinese `verse` blocks; level 6 adds literature style presets; level 7 adds
  opening vertical title/chapter columns with independent font sizes; level 8 adds
  edition-localized modern notes following each verse; level 9 adds a native notes seal;
  level 10 adds `verse.sourceForms` so subtitles follow the transcription toggle.
- A block kind the reader does not know is shown as a short "needs a newer version" note; the rest
  of the section still reads.
- Unknown fields are ignored, so a `"$schema"` key pointing at the schema URL is allowed (and lets
  editors such as VS Code check the file as you type).

## 10. Getting a book into Ledu

1. Build the package and run the validator until it prints `0 error(s)`.
2. Ask for a publisher account at https://ledu.app/publishers/request/.
3. Send the package. Ledu checks it again, opens it in the app on real devices and sends you a
   preview code so you can read it in the Ledu app before anyone else.
4. When you approve it, Ledu publishes it. Each later upload raises `meta.version`.

## 11. Public reading previews

Publishers can enable a free excerpt of a paid edition in Projects → Public preview.
Choose the first N pages or lessons. A page is one section in contents order. Lessons are
`lesson-N` chapters when that naming convention is used, otherwise chapters in contents order.
The setting is `"sample": {"unit": "pages", "count": 3}` or
`"sample": {"unit": "lessons", "count": 1}` in the work's publishing settings.
Omit the setting or set it to `null` to disable it for the next release.

The publisher builds both archives together. The full manifest records `sampleSelection` so
the choice belongs to that immutable release. The sample manifest has `"sample": true` and
format level 4, with only the selected section references. Its package contains those sections,
their media and the lexicon entries they use. It preserves the full edition's ID and version,
which lets a purchase carry reading progress forward.

The catalogue's `sample` metadata contains `sizeBytes`, `sha256`, `pageCount`, `lessonCount`
and `minFormat`. Readers obtain the sample through `POST /v1/download` with `sample: true`.
This grants a signed link to `books/<edition>/<version>/sample.aar`. A public sample is available
while the paid edition is listed. The full archive follows purchase verification.
