diff --git a/src/lib/editor/extensions/CLAUDE.md b/src/lib/editor/extensions/CLAUDE.md
index 116480a..3461b33 100644
--- a/src/lib/editor/extensions/CLAUDE.md
+++ b/src/lib/editor/extensions/CLAUDE.md
@@ -28,7 +28,7 @@ Five topics are large enough to have their own deep-dive — read the file befor
- **`textDirection.ts`** — a block's own base direction (`dir` attr; ODF `style:writing-mode`, Word `w:bidi`), overriding the page's (`storage/writingMode.ts`). The HTML `dir` is the whole rendering — it resolves the bidi run order and `text-align: start` follows it, so an unaligned block flips. Both importers suppress the direction the page already has: it is inheritance, not formatting. Set in `ParagraphDialog.svelte`, where LibreOffice keeps it.
- **`formattingMarks.ts`** (`FormattingMarks`) — decorations marking spaces (`·`) and tabs (`→`) when `.paper.show-formatting-marks` is set.
- **`bulletList.ts`** / **`orderedList.ts`** — the TipTap lists plus a marker-type attr: `setBulletChar` (innermost list, `null` = default cycle) and the ordered numbering cycle (`utils/orderedListTypes.ts`, multilevel targets the outermost list).
-- **`listStyle.ts`** — the named list style (`listStyleName` on the outermost list; nested lists inherit) and the walk resolving every list's effective marker (`data-eff-list-style`, `data-bullet`+`--bullet`, indent, label alignment) from node attr > style level > depth cycle; `setListStyle` assigns (clearing the subtree's direct marker attrs), `listStyleNameAt` feeds the dropdowns — see `src/lib/styles/CLAUDE.md`.
+- **`listStyle.ts`** — the named list style (`listStyleName` on the outermost list; nested lists inherit) and the walk resolving every list's effective marker (`data-eff-list-style`, `data-bullet`+`--bullet`, indent, label alignment) from node attr > style level > depth cycle — the style level decides the depth's kind, so a number level numbers a `
` (counter-offset via `counter-reset`, since `` ignores `start`); `setListStyle` assigns (clearing the subtree's direct marker attrs and retyping each list to its level's kind), `listStyleNameAt` feeds the dropdowns — see `src/lib/styles/CLAUDE.md`.
- **`link.ts`** — hyperlink mark; owns `Mod-k`, which fires the event `Toolbar.svelte` listens for to open the link dialog. A `#name` href targets a bookmark: `Editor.svelte`'s `handleClick` scrolls to it instead of opening a tab. The `plain` attr (`data-plain`, `editor.css`) suppresses the editor's own blue: Word paints a link through its **Hyperlink character style**, which arrives as an ordinary mark, so every DOCX link is plain and one carrying no style is drawn like the text around it — while LibreOffice paints every ODF `text:a` styled or not (probed), so those never are. The DOCX exporter paints `#0563C1` only on a non-plain link, which is how a round trip tells its own links from a file's.
- **`comment.ts`** — an annotation on a range of text, a mark like `bookmark`: the whole comment (author, date, body, resolved) rides its attrs, so two runs of one comment merge back together and no second store is needed. `commentRanges(doc)` walks every range (an id split by a paragraph boundary yields several, which is why the commands walk all of them), `comments(doc)` keeps one per id for `CommentsPane.svelte`. A point comment — LibreOffice's, made with nothing selected, written with no `office:name` and no end element — attaches on import to the run before it, else the one after: the editor's comment is a mark and needs a range.
- **`trackChanges.ts`** — the `insertion`/`deletion` marks plus the recording plugin. `appendTransaction` marks whatever a transaction added, and `adjacentInsertion` reuses the id of the run just before it when the author matches, so a typed sentence is one change and not one per keystroke. A delete never reaches the document: `filterTransaction` rejects it and dispatches a mark pass instead (the author's own pending insertion is removed for real, as both word processors do). A **replacement** — typing or pasting over a selection — goes the same way (`replacedRange`), the new content landing after the struck-out text it replaces; recorded as the insertion alone, its other half was simply dropped and a reject lost the original. Every transaction of our own carries the `RECORDING` meta — accept/reject included, or its `tr.delete` would be read as a fresh user deletion and marked up again. **Loading a document carries it too** (`App.svelte`'s `loadContent`, both for a new document and for an import): a `setContent` is one transaction that inserts the whole file, so without the meta an opened document arrives wholly marked as the reader's own insertion, underlined in the author colour. Both word processors record what is typed after an open, never the file. `revisions(doc)` merges adjacent runs of one id, so an export writes one change per id. The **author's colour** is a decoration, not the mark: a mark cannot know the document's other authors, so a plugin walks the revisions, hands out `REVISION_AUTHOR_COLORS` (LibreOffice's own author palette) in order of first appearance and paints `pm-rev-ins`/`-del` + `pm-rev-a`. That span nests *inside* the mark's, so it carries the underline/strikethrough too — drawn by the ancestor it would take the fallback colour. Cached on the doc; the walk is the whole document and `decorations` runs on every view update. `acceptRevision(id)`/`rejectRevision(id)` apply every range of one change, which is what `RevisionsPane.svelte` lists as one row.
diff --git a/src/lib/editor/extensions/listStyle.ts b/src/lib/editor/extensions/listStyle.ts
index 9ab639c..b48059c 100644
--- a/src/lib/editor/extensions/listStyle.ts
+++ b/src/lib/editor/extensions/listStyle.ts
@@ -36,11 +36,17 @@ export function listStyleDecos(doc: ProseMirrorNode, sheet: StyleSheet): Decorat
const eff = effectiveListLevel(node.attrs, name === 'orderedList', nextStyle, nextDepth);
const attrs: Record = {};
const css: string[] = [];
- if (name === 'orderedList') {
+ // eff.kind decides what the depth renders — a style's number level numbers a
+ // (and a bullet level bullets an ), as the same file would render in LibreOffice.
+ if (eff.kind === 'number') {
const own = eff.listStyleType;
const type = own === 'multilevel' || (listMultilevel && !own) ? 'multilevel' : own ?? defaultOrderedTypeAt(listCycle);
attrs['data-eff-list-style'] = type;
- if (eff.startAt != null && eff.startAt !== 1 && (node.attrs.start ?? 1) === 1) attrs.start = String(eff.startAt);
+ if (eff.startAt != null && eff.startAt !== 1 && (node.attrs.start ?? 1) === 1) {
+ // A ignores the start attribute, so its offset rides the counter itself.
+ if (name === 'orderedList') attrs.start = String(eff.startAt);
+ else css.push(`counter-reset: list-item ${eff.startAt - 1}`);
+ }
nextMultilevel = type === 'multilevel';
} else if (!node.attrs.bulletChar && eff.bulletChar) {
// data-bullet too: editor.css keys the var()-reading marker rule on it.
@@ -51,7 +57,7 @@ export function listStyleDecos(doc: ProseMirrorNode, sheet: StyleSheet): Decorat
if (node.attrs.indent == null && eff.indent) css.push(`margin-left: calc(var(--sec-inset-left, 0px) + ${eff.indent}cm)`);
if (css.length) attrs.style = css.join(';');
if (Object.keys(attrs).length) decos.push(Decoration.node(pos, pos + node.nodeSize, attrs));
- nextCycle = childCycle(listCycle, eff.listStyleType as OrderedListType | null, name === 'orderedList');
+ nextCycle = childCycle(listCycle, eff.listStyleType as OrderedListType | null, eff.kind === 'number');
nextInList = true;
} else if (name === 'listItem') {
nextCycle = cycle;
@@ -123,7 +129,8 @@ export const ListStyle = Extension.create<{ sheet: () => StyleSheet }>({
return {
// The style goes on the outermost list (nested ones inherit); the subtree's own
// marker attrs are cleared so the style shows — assigning one replaces the
- // list's direct numbering, as in LibreOffice.
+ // list's direct numbering, as in LibreOffice — and each list node is retyped to
+ // its level's kind, so the document matches what an import of it would build.
setListStyle:
(name) =>
({ state, tr, dispatch }) => {
@@ -135,16 +142,26 @@ export const ListStyle = Extension.create<{ sheet: () => StyleSheet }>({
}
if (outer === -1) return false;
if (dispatch) {
- const pos = $from.before(outer);
- const node = $from.node(outer);
+ const style = name ? this.options.sheet().list[name] ?? null : null;
+ const typeFor = (node: ProseMirrorNode, depth: number) => {
+ const kind = style?.levels[depth - 1]?.kind;
+ return kind ? state.schema.nodes[kind === 'number' ? 'orderedList' : 'bulletList'] : node.type;
+ };
const clear = (attrs: Record) =>
({ ...attrs, bulletChar: null, listStyleType: null, markerAlign: null, indent: null });
- tr.setNodeMarkup(pos, undefined, { ...clear(node.attrs), listStyleName: name });
- node.descendants((child, offset) => {
- if (child.type.name === 'bulletList' || child.type.name === 'orderedList') {
- tr.setNodeMarkup(tr.mapping.map(pos + 1 + offset), undefined, { ...clear(child.attrs), listStyleName: null });
- }
- });
+ const pos = $from.before(outer);
+ const node = $from.node(outer);
+ tr.setNodeMarkup(pos, typeFor(node, 1), { ...clear(node.attrs), listStyleName: name });
+ const walk = (parent: ProseMirrorNode, base: number, depth: number) => {
+ parent.forEach((child, offset) => {
+ const isList = child.type.name === 'bulletList' || child.type.name === 'orderedList';
+ if (isList) {
+ tr.setNodeMarkup(tr.mapping.map(base + offset), typeFor(child, depth + 1), { ...clear(child.attrs), listStyleName: null });
+ }
+ walk(child, base + offset + 1, isList ? depth + 1 : depth);
+ });
+ };
+ walk(node, pos + 1, 1);
}
return true;
},
diff --git a/src/lib/export/CLAUDE.md b/src/lib/export/CLAUDE.md
index 39da430..51897d7 100644
--- a/src/lib/export/CLAUDE.md
+++ b/src/lib/export/CLAUDE.md
@@ -46,7 +46,7 @@ fallback download shows a one-time hint (`edentext-download-hint`) that the brow
- **`applyListItemStyles`** — per-item alignment/spacing/line-height for top-level lists (odf-kit's ListBuilder has no per-item options) via minted automatic styles.
- **`applyListIndents`** — a top-level list's whole-list `indent` (cm) added to its `L#` list-style per-level `fo:margin-left`/`text:list-tab-stop-position` (label-alignment mode ignores the paragraph margin, so the shift must live in the list style). Import reverses it in `convertList` (level-1 margin minus the 1.27cm base).
- **`applyNestedListTypes`** — odf-kit emits nested lists as bare `` sharing the top-level list style, so a nested list of a different kind/format (e.g. ordered inside bullets) gets its own minted 6-level list style.
-- **`applyListStyleNames`** — a list carrying an unoverridden `listStyleName` is repointed from its `L#` automatic style to the named `` `applyNamedStyles` writes into styles.xml (its nested lists stay bare and inherit); runs after every `L#`-keyed pass. The list collectors resolve attrs through `effectiveListLevel`, so an overridden styled list keeps a fully resolved `L#` clone — see `src/lib/styles/CLAUDE.md`. **DOCX**: `Numbering.refForStyle` shares one abstract per style (each list its own `w:num` instance, so numbering restarts) and `applyListStylesDocx` injects the `w:styleLink` + the `w:type="numbering"` style's real numId post-pack — the library can express neither. A list with a `start` attr keeps a private clone (the shared abstract starts every instance at the style's start). Probed: LibreOffice ignores DOCX numbering styles both ways (its import mints `WWNum#`, its export flattens to the look) — the identity is a Word capability; ODF carries it in both products.
+- **`applyListStyleNames`** — a list carrying an unoverridden `listStyleName` is repointed from its `L#` automatic style to the named `` `applyNamedStyles` writes into styles.xml (its nested lists stay bare and inherit); runs after every `L#`-keyed pass. The list collectors resolve attrs through `effectiveListLevel`, so an overridden styled list keeps a fully resolved `L#` clone; `applyListLevelKinds` runs first and switches an `L#` level element's species where the style's level kind differs from the node's (a `` depth the style numbers), format/char baked in — see `src/lib/styles/CLAUDE.md`. **DOCX**: `Numbering.refForStyle` shares one abstract per style (each list its own `w:num` instance, so numbering restarts) and `applyListStylesDocx` injects the `w:styleLink` + the `w:type="numbering"` style's real numId post-pack — the library can express neither. A list with a `start` attr keeps a private clone (the shared abstract starts every instance at the style's start). Probed: LibreOffice ignores DOCX numbering styles both ways (its import mints `WWNum#`, its export flattens to the look) — the identity is a Word capability; ODF carries it in both products.
- **`applyListStartValues`** — odf-kit drops an ordered list's `start` attr; a Word list continued across an intervening paragraph (same numId, split into separate `orderedList` nodes with `start` > 1 by the importer) gets `text:start-value` on its first `` so numbering keeps counting instead of restarting at 1.
- **`applyTableRowHeights`** — dragged row heights → `style:min-row-height` automatic table-row styles.
- **`collapseRunWhitespace`** — strips the bare `\n` separators odf-kit inserts between runs inside a paragraph (they'd otherwise collapse to spurious spaces mid-word).
diff --git a/src/lib/export/docx.ts b/src/lib/export/docx.ts
index 73e29db..2b29817 100644
--- a/src/lib/export/docx.ts
+++ b/src/lib/export/docx.ts
@@ -77,7 +77,7 @@ const DOC_FONT = 'Times New Roman';
// Effective bullet glyph of a list node: its bulletChar attr, else its named list
// style's level, else the default cycle.
function bulletCharOf(node: TiptapNode, depth0: number, style: ListStyleDef | null = null): string {
- const ch = effectiveListLevel(node.attrs ?? {}, false, style, depth0 + 1).bulletChar;
+ const ch = effectiveListLevel(node.attrs ?? {}, node.type === 'orderedList', style, depth0 + 1).bulletChar;
return ch ?? defaultBulletChar(depth0);
}
@@ -320,9 +320,11 @@ class Numbering {
const levels = this.map.get(reference)!;
const l = levels.find((lv) => lv.level === depth);
if (!l) return reference;
+ // The style level's kind decides what the depth renders, whatever the node species.
+ const eff = effectiveListLevel(node.attrs ?? {}, node.type === 'orderedList', style, depth + 1);
let format: string, text: string;
- if (node.type === 'orderedList') {
- const attr = effOrderedKey(node, style, depth);
+ if (eff.kind === 'number') {
+ const attr = eff.listStyleType;
const def = effectiveOrderedDefAt(attr === 'multilevel' ? 'decimal' : attr, cycle);
format = ORDERED_FORMAT[def.numFormat] ?? LevelFormat.DECIMAL;
text = `%${depth + 1}${def.numSuffix}`;
@@ -350,7 +352,7 @@ class Numbering {
// w:lvlJc: which end of the hanging indent the label is set against.
const eff = effectiveListLevel(node.attrs ?? {}, node.type === 'orderedList', style, depth + 1);
const alignment = eff.markerAlign === 'right' ? AlignmentType.RIGHT : AlignmentType.LEFT;
- if (node.type === 'orderedList') {
+ if (eff.kind === 'number') {
const attr = eff.listStyleType;
const chained = this.mlRefs.has(reference) && (depth === 0 || !attr || attr === 'multilevel');
const def = effectiveOrderedDefAt(attr === 'multilevel' ? 'decimal' : attr, cycle);
@@ -1909,7 +1911,7 @@ function listToParagraphs(
const indentCm = extraIndentCm + eff.indent;
num.ensureLevel(reference, depth, node, indentCm, cycle, style);
const levelLeftTwip = cmToTwip((depth + 1) * LIST_LEFT_STEP_CM + indentCm);
- const cChild = childCycle(cycle, eff.listStyleType, node.type === 'orderedList');
+ const cChild = childCycle(cycle, eff.listStyleType, eff.kind === 'number');
for (const item of node.content ?? []) {
if (item.type !== 'listItem') continue;
let numberedFirst = false;
diff --git a/src/lib/export/odt.ts b/src/lib/export/odt.ts
index b7b7f1f..70ee2d2 100644
--- a/src/lib/export/odt.ts
+++ b/src/lib/export/odt.ts
@@ -2096,6 +2096,13 @@ function effOrderedFmt(list: TiptapNode, cycle: OrderedCycle, style: ListStyle |
return { numFormat: def.numFormat, numSuffix: def.numSuffix };
}
+// What a list node at a depth renders under its style — the style's level decides the
+// kind (a number level numbers a ); only past the levels the species does.
+type LevelKind = 'bullet' | 'number';
+function effListKind(list: TiptapNode, style: ListStyle | null, depth: number): LevelKind {
+ return effectiveListLevel(list.attrs ?? {}, list.type === 'orderedList', style, depth).kind;
+}
+
// Per-level numbering for a list subtree — same DFS-first model as bulletCharVector,
// threading each list's cycle position down so nested defaults advance past their parent.
function orderedFmtVector(list: TiptapNode, startDepth: number, base: OrderedFmt[], startCycle: OrderedCycle, style: ListStyle | null = null): OrderedFmt[] {
@@ -2103,11 +2110,11 @@ function orderedFmtVector(list: TiptapNode, startDepth: number, base: OrderedFmt
const seen = new Set();
const walk = (node: TiptapNode, depth: number, cycle: OrderedCycle) => {
if (depth > vec.length) return;
- if (node.type === 'orderedList' && !seen.has(depth)) {
+ if (effListKind(node, style, depth) === 'number' && !seen.has(depth)) {
seen.add(depth);
vec[depth - 1] = effOrderedFmt(node, cycle, style, depth);
}
- const cChild = childCycle(cycle, effOrderedKey(node, style, depth), node.type === 'orderedList');
+ const cChild = childCycle(cycle, effOrderedKey(node, style, depth), effListKind(node, style, depth) === 'number');
for (const item of node.content ?? []) {
if (item.type !== 'listItem') continue;
for (const child of item.content ?? []) {
@@ -2119,6 +2126,84 @@ function orderedFmtVector(list: TiptapNode, startDepth: number, base: OrderedFmt
return vec;
}
+// A named style's level of the other kind than the L# clone's element (a whose
+// depth the style numbers, or the reverse): that level element must switch species,
+// with the effective format/char baked in — the passes below only patch matching kinds.
+type LevelKindFix = { kind: LevelKind; fmt: OrderedFmt; char: string; displayLevels: number };
+
+function collectListLevelKinds(doc: TiptapNode, result: (LevelKindFix | null)[][]): void {
+ for (const child of doc.content ?? []) {
+ if (child.type !== 'bulletList' && child.type !== 'orderedList') continue;
+ const style = listStyleOf(child);
+ const fixes: (LevelKindFix | null)[] = [];
+ if (style) {
+ const topOrdered = child.type === 'orderedList';
+ const fixAt = (kind: LevelKind, fmt: OrderedFmt, char: string, displayLevels: number): LevelKindFix | null =>
+ (kind === 'number') === topOrdered ? null : { kind, fmt, char, displayLevels };
+ const walk = (list: TiptapNode, depth: number, cycle: OrderedCycle) => {
+ if (depth > 6) return;
+ if (fixes[depth - 1] === undefined) {
+ const eff = effectiveListLevel(list.attrs ?? {}, list.type === 'orderedList', style, depth);
+ fixes[depth - 1] = fixAt(eff.kind, effOrderedFmt(list, cycle, style, depth), effBulletChar(list, depth, style),
+ eff.listStyleType === 'multilevel' && depth > 1 ? depth : 1);
+ }
+ const cChild = childCycle(cycle, effOrderedKey(list, style, depth), effListKind(list, style, depth) === 'number');
+ for (const item of list.content ?? []) {
+ if (item.type !== 'listItem') continue;
+ for (const inner of item.content ?? []) {
+ if (inner.type === 'bulletList' || inner.type === 'orderedList') walk(inner, depth + 1, cChild);
+ }
+ }
+ };
+ walk(child, 1, ROOT_ORDERED_CYCLE);
+ // Depths the document never reaches still follow the style, so the clone stays
+ // the full definition.
+ for (let d = 1; d <= 6; d++) {
+ if (fixes[d - 1] !== undefined) continue;
+ const lv = style.levels[d - 1];
+ if (!lv) { fixes[d - 1] = null; continue; }
+ const def = effectiveOrderedDefAt(style.multilevel ? 'decimal' : lv.numType ?? 'decimal', ROOT_ORDERED_CYCLE);
+ fixes[d - 1] = fixAt(lv.kind, { numFormat: def.numFormat, numSuffix: def.numSuffix }, lv.bulletChar ?? '•',
+ style.multilevel && lv.kind === 'number' && d > 1 ? d : 1);
+ }
+ }
+ result.push(fixes);
+ }
+}
+
+function applyListLevelKinds(odtBytes: Uint8Array, kinds: (LevelKindFix | null)[][]): Uint8Array {
+ if (kinds.every(fs => fs.every(f => f == null))) return odtBytes;
+
+ const files = unzipSync(odtBytes);
+ const contentBytes = files['content.xml'];
+ if (!contentBytes) return odtBytes;
+
+ let content = strFromU8(contentBytes);
+ kinds.forEach((fixes, i) => {
+ if (!fixes.some(Boolean)) return;
+ const re = new RegExp(`()([\\s\\S]*?)()`);
+ content = content.replace(re, (_m, open: string, body: string, close: string) =>
+ open +
+ body.replace(
+ /]*>([\s\S]*?)<\/text:list-level-style-\1>/g,
+ (m, _kind: string, lvlAttr: string, lvl: string, inner: string) => {
+ const fix = fixes[+lvl - 1];
+ if (!fix) return m;
+ if (fix.kind === 'number') {
+ const disp = fix.displayLevels > 1 ? ` text:display-levels="${fix.displayLevels}"` : '';
+ return `${inner}`;
+ }
+ return `${inner}`;
+ },
+ ) +
+ close,
+ );
+ });
+
+ files['content.xml'] = strToU8(content);
+ return rezipOdt(files);
+}
+
function collectOrderedListFormats(node: TiptapNode, result: (OlStyleFix | null)[]): void {
for (const child of node.content ?? []) {
if (child.type === 'bulletList') {
@@ -2199,10 +2284,10 @@ function applyListStartValues(odtBytes: Uint8Array, starts: (number | null)[]):
return rezipOdt(files);
}
-// Effective marker char of a bullet list at a 1-based depth: its bulletChar attr,
-// else the default cycle.
+// Effective marker char of a list at a 1-based depth: its bulletChar attr, else its
+// style level's char, else the default cycle.
function effBulletChar(list: TiptapNode, depth: number, style: ListStyle | null = null): string {
- const ch = effectiveListLevel(list.attrs ?? {}, false, style, depth).bulletChar;
+ const ch = effectiveListLevel(list.attrs ?? {}, list.type === 'orderedList', style, depth).bulletChar;
return ch ?? defaultBulletChar(depth - 1);
}
@@ -2214,7 +2299,7 @@ function bulletCharVector(list: TiptapNode, startDepth: number, base: string[],
const seen = new Set();
const walk = (node: TiptapNode, depth: number) => {
if (depth > vec.length) return;
- if (node.type === 'bulletList' && !seen.has(depth)) {
+ if (effListKind(node, style, depth) === 'bullet' && !seen.has(depth)) {
seen.add(depth);
vec[depth - 1] = effBulletChar(node, depth, style);
}
@@ -2407,12 +2492,39 @@ function applyListMarkerFormats(odtBytes: Uint8Array, formats: (MarkerFormat | n
// odf-kit emits nested lists as bare sharing the top-level L# style, so a
// nested list of a different kind/format/marker loses its look. Mint it its own
// 6-level list style (same pattern applyCellBlocks uses for cell lists).
-type ListDef = { ordered: boolean; multilevel: boolean; fmts: OrderedFmt[]; bulletChars: string[] };
+type ListDef = { kinds: LevelKind[]; multilevel: boolean; fmts: OrderedFmt[]; bulletChars: string[] };
-function listDefOf(node: TiptapNode, depth: number, cycle: OrderedCycle, baseChars: string[], baseFmts: OrderedFmt[], style: ListStyle | null = null): ListDef {
+// Per-level kind for a list subtree, same DFS-first model as the char/format vectors.
+function kindVector(list: TiptapNode, startDepth: number, base: LevelKind[], style: ListStyle | null): LevelKind[] {
+ const vec = [...base];
+ const seen = new Set();
+ const walk = (node: TiptapNode, depth: number) => {
+ if (depth > vec.length) return;
+ if (!seen.has(depth)) {
+ seen.add(depth);
+ vec[depth - 1] = effListKind(node, style, depth);
+ }
+ for (const item of node.content ?? []) {
+ if (item.type !== 'listItem') continue;
+ for (const child of item.content ?? []) {
+ if (child.type === 'bulletList' || child.type === 'orderedList') walk(child, depth + 1);
+ }
+ }
+ };
+ walk(list, startDepth);
+ return vec;
+}
+
+function listDefOf(node: TiptapNode, depth: number, cycle: OrderedCycle, baseChars: string[], baseFmts: OrderedFmt[], style: ListStyle | null = null, baseKinds?: LevelKind[]): ListDef {
const multilevel = effOrderedKey(node, style, depth) === 'multilevel';
+ const species: LevelKind = node.type === 'orderedList' ? 'number' : 'bullet';
+ // The top def mirrors its L# levels: homogeneous by species, unless a style made
+ // applyListLevelKinds convert them (then: visited eff kind, unvisited style kind).
+ const kinds = !baseKinds && !style
+ ? Array.from({ length: 6 }, () => species)
+ : kindVector(node, depth, baseKinds ?? Array.from({ length: 6 }, (_, i): LevelKind => style?.levels[i]?.kind ?? species), style);
return {
- ordered: node.type === 'orderedList',
+ kinds,
multilevel,
fmts: multilevel ? MULTILEVEL_FMTS : orderedFmtVector(node, depth, baseFmts, cycle, style),
bulletChars: bulletCharVector(node, depth, baseChars, style),
@@ -2427,11 +2539,11 @@ function collectNestedListFixes(doc: TiptapNode, result: (ListDef | null)[], rep
const walkList = (list: TiptapNode, governing: ListDef, isTop: boolean, depth: number, cycle: OrderedCycle, style: ListStyle | null) => {
let gov = governing;
if (!isTop) {
- const ordered = list.type === 'orderedList';
+ const kind = effListKind(list, style, depth);
let differs: boolean;
- if (ordered !== governing.ordered) {
+ if (kind !== governing.kinds[(depth - 1) % governing.kinds.length]) {
differs = true;
- } else if (!ordered) {
+ } else if (kind === 'bullet') {
differs = effBulletChar(list, depth, style) !== governing.bulletChars[(depth - 1) % governing.bulletChars.length];
} else if (governing.multilevel) {
// Attr-less lists inherit the chain; only an explicit style breaks out.
@@ -2442,11 +2554,11 @@ function collectNestedListFixes(doc: TiptapNode, result: (ListDef | null)[], rep
const g = governing.fmts[(depth - 1) % governing.fmts.length];
differs = f.numFormat !== g.numFormat || f.numSuffix !== g.numSuffix;
}
- const def = differs ? listDefOf(list, depth, cycle, governing.bulletChars, governing.fmts, style) : null;
+ const def = differs ? listDefOf(list, depth, cycle, governing.bulletChars, governing.fmts, style, governing.kinds) : null;
result.push(def);
if (def) gov = def; // restyled list governs its own descendants
}
- const cChild = childCycle(cycle, effOrderedKey(list, style, depth), list.type === 'orderedList');
+ const cChild = childCycle(cycle, effOrderedKey(list, style, depth), effListKind(list, style, depth) === 'number');
for (const item of list.content ?? []) {
if (item.type !== 'listItem') continue;
for (const child of item.content ?? []) {
@@ -2482,14 +2594,12 @@ function applyNestedListTypes(odtBytes: Uint8Array, fixes: (ListDef | null)[]):
const minted: string[] = [];
const nameByKey = new Map();
const styleFor = (fix: ListDef): string => {
- const key = fix.ordered
- ? `o|${fix.multilevel ? 'M' : ''}|${fix.fmts.map(f => f.numFormat + f.numSuffix).join('')}`
- : `b|${fix.bulletChars.join('')}`;
+ const key = `${fix.kinds.map(k => k[0]).join('')}|${fix.multilevel ? 'M' : ''}|${fix.fmts.map(f => f.numFormat + f.numSuffix).join('')}|${fix.bulletChars.join('')}`;
let name = nameByKey.get(key);
if (!name) {
name = `NL${nameByKey.size + 1}`;
nameByKey.set(key, name);
- minted.push(buildCellListStyle(name, fix.ordered, { fmts: fix.fmts, multilevel: fix.multilevel, bulletChars: fix.bulletChars }));
+ minted.push(buildCellListStyle(name, fix.kinds[0] === 'number', { fmts: fix.fmts, multilevel: fix.multilevel, bulletChars: fix.bulletChars, kinds: fix.kinds }));
}
return name;
};
@@ -2567,7 +2677,7 @@ function buildNamedListStyleXml(style: ListStyle): string {
function buildCellListStyle(
styleName: string,
ordered: boolean,
- opts: { fmts?: OrderedFmt[]; multilevel?: boolean; bulletChars?: string[] } = {},
+ opts: { fmts?: OrderedFmt[]; multilevel?: boolean; bulletChars?: string[]; kinds?: LevelKind[] } = {},
): string {
const fmts = opts.multilevel ? MULTILEVEL_FMTS : opts.fmts ?? MULTILEVEL_FMTS;
const bulletChars = opts.bulletChars ?? DEFAULT_BULLET_CYCLE;
@@ -2577,7 +2687,7 @@ function buildCellListStyle(
const marginLeft = `${(indent * 2).toFixed(3)}cm`;
const textIndent = `-${indent.toFixed(3)}cm`;
const labelAlign = ``;
- if (ordered) {
+ if (opts.kinds ? opts.kinds[(level - 1) % opts.kinds.length] === 'number' : ordered) {
const f = fmts[(level - 1) % fmts.length];
const disp = opts.multilevel && level > 1 ? ` text:display-levels="${level}"` : '';
levels += `${labelAlign}`;
@@ -4810,12 +4920,19 @@ export async function buildOdt(docJson: TiptapNode, margins: PageMargins = DEFAU
},
});
+ // Where a named style's level is of the other species than its L# clone's element
+ // (a the style numbers), switch those level elements first, so the format/char
+ // passes below patch elements of the right kind.
+ const levelKinds: (LevelKindFix | null)[][] = [];
+ collectListLevelKinds(raw, levelKinds);
+ let numberedOdt = applyListLevelKinds(odt as Uint8Array, levelKinds);
+
// Rewrite odf-kit's default numbering (1.) into per-level formats (depth cycle,
// explicit types, multilevel chains). Runs before applyListItemStyles, which only
// touches styles, not the definitions.
const olFormats: (OlStyleFix | null)[] = [];
collectOrderedListFormats(raw, olFormats);
- let numberedOdt = applyOrderedListFormats(odt as Uint8Array, olFormats);
+ numberedOdt = applyOrderedListFormats(numberedOdt, olFormats);
// A Word list continued across an intervening paragraph splits into separate nodes with
// a `start` attr; odf-kit drops it, so emit text:start-value on each such list's first item.
diff --git a/src/lib/styles/CLAUDE.md b/src/lib/styles/CLAUDE.md
index 42fb7f8..b34f299 100644
--- a/src/lib/styles/CLAUDE.md
+++ b/src/lib/styles/CLAUDE.md
@@ -12,7 +12,12 @@ LibreOffice's Listenformatvorlagen: a flat family of up-to-10-level definitions
list only — nested lists inherit, as an ODF `` does. Precedence per level:
node attr > style level > depth-cycle default, resolved by `effectiveListLevel` — the one
source the decoration walk (`listStyleDecos`, which also owns `data-eff-list-style` for
-plain lists) and both exporters share. The five built-ins are **probed LibreOffice
+plain lists) and both exporters share. **The style level decides the depth's kind**
+(`eff.kind`): a number level numbers a `` and a bullet level bullets an `` — in
+ODF the list style alone says what a depth renders, the editor's node species doesn't
+travel. `setListStyle` retypes the subtree to the levels' kinds; a Tab-nested list of
+the other species still renders (and exports) what the level says, and both importers
+build the species from the level, so a round trip normalizes it. The five built-ins are **probed LibreOffice
definitions** (List 1/2, Numbering 123/ABC/IVX; their margins are LO's own metric values).
Export writes the full named `` into styles.xml and points the list at it
**only when nothing overrides** — ODF list styles have no parent chain, so an overridden
diff --git a/src/lib/styles/listStyles.ts b/src/lib/styles/listStyles.ts
index 8c51213..ddbd96d 100644
--- a/src/lib/styles/listStyles.ts
+++ b/src/lib/styles/listStyles.ts
@@ -36,8 +36,12 @@ export function listLevelOf(style: ListStyle | null | undefined, depth: number):
// style level ?? null (= the depth-cycle default the walk resolves). Single source of
// truth for the decoration walk, both exporters and both importers' suppression.
export type EffectiveListLevel = {
- bulletChar: string | null;
- listStyleType: OrderedListType | null;
+ // What this depth renders. The node's own marker attr keeps its species; otherwise a
+ // defined style level decides — in ODF the list style alone says what a depth shows,
+ // whichever element the editor holds. Past the levels, the species' own cycle.
+ kind: 'bullet' | 'number';
+ bulletChar: string | null; // set only for kind 'bullet'; null = the depth-cycle char
+ listStyleType: OrderedListType | null; // set only for kind 'number'; null = cycle
indent: number;
markerAlign: 'right' | null;
startAt: number | null;
@@ -50,18 +54,28 @@ export function effectiveListLevel(
depth: number,
): EffectiveListLevel {
const level = listLevelOf(style, depth);
- // A level only speaks for its own kind: an ordered node over a bullet level (or the
- // reverse) keeps the cycle default rather than a marker of the wrong species.
- const matches = level != null && (level.kind === 'number') === ordered;
- const own = (key: string): unknown => (attrs ?? {})[key] ?? null;
+ const a = attrs ?? {};
+ const own = (ordered ? a.listStyleType : a.bulletChar) as string | null | undefined;
+ const kind: 'bullet' | 'number' = own || !level ? (ordered ? 'number' : 'bullet') : level.kind;
+ const styled = !own && level != null; // the style level governs this depth
+ let bulletChar: string | null = null;
+ let listStyleType: OrderedListType | null = null;
+ if (kind === 'bullet') {
+ bulletChar = own ? (own as string) : styled ? level?.bulletChar ?? '•' : null;
+ } else if (own) {
+ listStyleType = own as OrderedListType;
+ } else if (style?.multilevel) {
+ listStyleType = 'multilevel';
+ } else if (styled) {
+ listStyleType = level?.numType ?? 'decimal';
+ }
return {
- bulletChar: !ordered ? (own('bulletChar') as string | null) ?? (matches ? level.bulletChar ?? null : null) : null,
- listStyleType: ordered
- ? (own('listStyleType') as OrderedListType | null) ?? (style?.multilevel ? 'multilevel' : matches ? level.numType ?? null : null)
- : null,
- indent: typeof attrs?.indent === 'number' ? attrs.indent : (level?.indentCm ?? 0),
- markerAlign: (own('markerAlign') as 'right' | null) ?? (level?.markerAlign ?? null),
- startAt: matches && ordered ? level.startAt ?? null : null,
+ kind,
+ bulletChar,
+ listStyleType,
+ indent: typeof a.indent === 'number' ? a.indent : (level?.indentCm ?? 0),
+ markerAlign: (a.markerAlign as 'right' | null) ?? (level?.markerAlign ?? null),
+ startAt: kind === 'number' && styled ? level?.startAt ?? null : null,
};
}
diff --git a/src/styles/editor.css b/src/styles/editor.css
index 260b009..ef25b3c 100644
--- a/src/styles/editor.css
+++ b/src/styles/editor.css
@@ -688,26 +688,33 @@
}
/* Ordered numbering, keyed by data-eff-list-style — the effective numbering
- orderedList.ts's plugin resolves per from its attr + ancestor chain. The
- undecorated is the plain decimal fallback and must come first. */
+ listStyle.ts's plugin resolves per list from its attr + style + ancestor chain. A
+ carries it too where a named style's level numbers that depth. The undecorated
+ is the plain decimal fallback and must come first. */
.paper .tiptap ol > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, decimal) ". "; }
-.paper .tiptap ol[data-eff-list-style="decimal"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, decimal) ". "; }
-.paper .tiptap ol[data-eff-list-style="decimal-paren"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, decimal) ") "; }
-.paper .tiptap ol[data-eff-list-style="lower-alpha"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, lower-alpha) ". "; }
-.paper .tiptap ol[data-eff-list-style="lower-alpha-paren"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, lower-alpha) ") "; }
-.paper .tiptap ol[data-eff-list-style="upper-alpha"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, upper-alpha) ". "; }
-.paper .tiptap ol[data-eff-list-style="upper-alpha-paren"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, upper-alpha) ") "; }
-.paper .tiptap ol[data-eff-list-style="lower-roman"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, lower-roman) ". "; }
-.paper .tiptap ol[data-eff-list-style="lower-roman-paren"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, lower-roman) ") "; }
-.paper .tiptap ol[data-eff-list-style="upper-roman"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, upper-roman) ". "; }
-.paper .tiptap ol[data-eff-list-style="upper-roman-paren"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, upper-roman) ") "; }
+.paper .tiptap :is(ol, ul)[data-eff-list-style="decimal"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, decimal) ". "; }
+.paper .tiptap :is(ol, ul)[data-eff-list-style="decimal-paren"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, decimal) ") "; }
+.paper .tiptap :is(ol, ul)[data-eff-list-style="lower-alpha"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, lower-alpha) ". "; }
+.paper .tiptap :is(ol, ul)[data-eff-list-style="lower-alpha-paren"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, lower-alpha) ") "; }
+.paper .tiptap :is(ol, ul)[data-eff-list-style="upper-alpha"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, upper-alpha) ". "; }
+.paper .tiptap :is(ol, ul)[data-eff-list-style="upper-alpha-paren"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, upper-alpha) ") "; }
+.paper .tiptap :is(ol, ul)[data-eff-list-style="lower-roman"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, lower-roman) ". "; }
+.paper .tiptap :is(ol, ul)[data-eff-list-style="lower-roman-paren"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, lower-roman) ") "; }
+.paper .tiptap :is(ol, ul)[data-eff-list-style="upper-roman"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, upper-roman) ". "; }
+.paper .tiptap :is(ol, ul)[data-eff-list-style="upper-roman-paren"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before { content: counter(list-item, upper-roman) ") "; }
/* Legal/outline numbering (1., 1.1., 1.2.1. …): the plugin tags the multilevel list and
every attr-less member of its chain with data-eff-list-style="multilevel". */
-.paper .tiptap ol[data-eff-list-style="multilevel"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before {
+.paper .tiptap :is(ol, ul)[data-eff-list-style="multilevel"] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before {
content: counters(list-item, ".") ". ";
}
+/* A numbered depth keeps the ordered markers' font (the symbol-shim rule below
+ would set the digits in the serif fallback instead of the item's own font). */
+.paper .tiptap ul[data-eff-list-style] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before {
+ font-family: var(--marker-family, inherit);
+}
+
/* Default bullet markers per nesting depth — the same cycle the ODT/DOCX export writes
(DEFAULT_BULLET_CYCLE in bulletListTypes.ts). The bundled symbol shim comes first: it
holds only the glyphs Liberation Serif lacks (❖ ➢ ⇨ ✓ ▸ ◆), so those stay compact and
@@ -724,9 +731,11 @@
/* A list's own `bulletChar` beats the cycle at any depth — an attribute outranks the
descendant chain. A nested list without one keeps its depth's char, which is what both
- exports write, even though --bullet inherits into it. */
-.paper .tiptap ul[data-bullet] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before {
+ exports write, even though --bullet inherits into it. An carries data-bullet where
+ a named style's level bullets that depth; the shim font rides along for its glyphs. */
+.paper .tiptap :is(ul, ol)[data-bullet] > li > :is(p, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10)::before {
content: var(--bullet) ' ';
+ font-family: 'EdenText Symbols', var(--marker-family, var(--font-serif)), serif;
}
/* The PDF clone (the .paper itself) replaces every marker with a real span (pdf.ts). */
diff --git a/tests/docx-roundtrip.test.ts b/tests/docx-roundtrip.test.ts
index 615b8ac..bc4b3c6 100644
--- a/tests/docx-roundtrip.test.ts
+++ b/tests/docx-roundtrip.test.ts
@@ -1269,6 +1269,36 @@ describe('DOCX named list styles', () => {
expect(imported?.levels[2]).toMatchObject({ kind: 'number', numType: 'lower-alpha' });
});
+ it('the style level decides a depth\'s kind — a species-mismatched nest keeps the shared abstract', async () => {
+ sheet.list['Tab Test'] = { name: 'Tab Test', levels: [
+ { kind: 'bullet', bulletChar: '–' },
+ ...Array.from({ length: 8 }, () => ({ kind: 'number' as const, numType: 'decimal' as const })),
+ ] };
+ // A Tab-nested tree is bullet lists all the way down; the style numbers depth 2+.
+ const doc = { type: 'doc', content: [
+ { type: 'bulletList', attrs: { listStyleName: 'Tab Test' }, content: [
+ li(para('one'), { type: 'bulletList', content: [li(para('two'))] }),
+ ] },
+ ] };
+ const bytes = await buildDocx(doc as any, undefined, undefined, undefined, undefined, undefined, sheet);
+ const numbering = strFromU8(unzipSync(bytes)['word/numbering.xml']);
+ const abstract = numbering.match(/]*>(?:(?!<\/w:abstractNum>)[\s\S])*w:styleLink w:val="TabTest"[\s\S]*?<\/w:abstractNum>/)?.[0] ?? '';
+ expect(abstract, 'the style abstract carries w:styleLink').toBeTruthy();
+ // The nested did not fork away from the style reference: exactly one num over
+ // the style abstract, and no third abstract beyond the library's default bullet.
+ const absId = /w:abstractNumId="(\d+)"/.exec(abstract)![1];
+ const nums = numbering.match(new RegExp(`]*>\\s*`, 'g')) ?? [];
+ expect(nums.length, 'one instance for the one list').toBe(1);
+ expect((numbering.match(/ n.type === 'bulletList');
+ expect(top?.attrs?.listStyleName).toBe('Tab Test');
+ const nested = top?.content?.[0]?.content?.[1];
+ expect(nested?.type, 'the nested list comes back numbered').toBe('orderedList');
+ expect(nested?.attrs ?? null).toBeNull();
+ delete sheet.list['Tab Test'];
+ });
+
it('an overridden list keeps a private, fully resolved numbering and drops the name', async () => {
const doc = { type: 'doc', content: [
{ type: 'orderedList', attrs: { listStyleName: 'Numbering ABC', listStyleType: 'lower-roman' }, content: [li(para('broken out'))] },
diff --git a/tests/lo-roundtrip.test.ts b/tests/lo-roundtrip.test.ts
index 289b539..def2126 100644
--- a/tests/lo-roundtrip.test.ts
+++ b/tests/lo-roundtrip.test.ts
@@ -427,6 +427,11 @@ describe.skipIf(!SOFFICE)('LibreOffice round-trip (needs soffice on PATH)', () =
] },
P(null, T('between')),
{ type: 'bulletList', attrs: { listStyleName: 'List 2' }, content: [LI(P(null, T('dash')))] },
+ // A bullet tree under the same style: level 1 is a number level, so the style
+ // decides the kind and LibreOffice must render (and keep) the numbering.
+ { type: 'bulletList', attrs: { listStyleName: 'Prüfliste' }, content: [
+ LI(P(null, T('mix')), { type: 'bulletList', content: [LI(P(null, T('mixsub')))] }),
+ ] },
] };
mkdirSync('/tmp/lo-rt', { recursive: true });
writeFileSync('/tmp/lo-rt/ls.odt', await buildOdt(doc, margins, 'portrait', undefined, null, 'A4', sheet));
@@ -453,6 +458,10 @@ describe.skipIf(!SOFFICE)('LibreOffice round-trip (needs soffice on PATH)', () =
&& imported?.levels[0]?.markerAlign === 'right' && imported?.levels[1]?.bulletChar === '✓', imported?.levels?.slice(0, 2));
check('LO lists: the level indent survives the unit round-trip',
Math.abs((imported?.levels[0]?.indentCm ?? 0) - 0.5) < 0.02, imported?.levels[0]);
+ check('LO lists: the species-mismatched tree keeps the style',
+ lists[2]?.attrs?.listStyleName === 'Prüfliste', lists[2]?.attrs);
+ check('LO lists: its kinds come back as the levels say (number, then bullet)',
+ lists[2]?.type === 'orderedList' && lists[2]?.content?.[0]?.content?.[1]?.type === 'bulletList', lists[2]);
});
it('survives a `soffice` re-save of the record-changes flag', { timeout: 180000 }, async () => {
diff --git a/tests/roundtrip.test.ts b/tests/roundtrip.test.ts
index 9530b36..056af20 100644
--- a/tests/roundtrip.test.ts
+++ b/tests/roundtrip.test.ts
@@ -1741,6 +1741,40 @@ describe('Leg 14: named list styles (ODF)', () => {
check('the name is gone', !list?.attrs?.listStyleName, list?.attrs);
});
+ it('the style level decides a depth\'s kind, whatever species the editor holds', async () => {
+ sheet.list['Tab Test'] = { name: 'Tab Test', levels: [
+ { kind: 'bullet', bulletChar: '–' },
+ ...Array.from({ length: 9 }, () => ({ kind: 'number' as const, numType: 'decimal' as const })),
+ ] };
+ // A Tab-nested tree is bullet lists all the way down; the style numbers depth 2+.
+ const tree = (attrs: N | null): N => ({ type: 'bulletList', ...(attrs ? { attrs } : {}), content: [
+ LI(P(null, T('one')), { type: 'bulletList', content: [LI(P(null, T('two')))] }),
+ ] });
+
+ const clean = await buildOdt({ type: 'doc', content: [tree({ listStyleName: 'Tab Test' })] },
+ margins, 'portrait', undefined, null, 'A4', sheet);
+ const res = importOdt(clean);
+ const top = (res.content.content ?? []).find((n: N) => n.type === 'bulletList');
+ check('the clean list references the named style', top?.attrs?.listStyleName === 'Tab Test', top?.attrs);
+ const nested = top?.content?.[0]?.content?.[1];
+ check('the nested list comes back as the number level says', nested?.type === 'orderedList', nested);
+ check('without accreted attrs', !nested?.attrs, nested?.attrs);
+
+ // Overridden: the automatic clone's level 2 must switch species too.
+ const dirty = await buildOdt({ type: 'doc', content: [tree({ listStyleName: 'Tab Test', bulletChar: '➢' })] },
+ margins, 'portrait', undefined, null, 'A4', sheet);
+ const content = strFromU8(unzipSync(dirty)['content.xml']);
+ const clone = content.match(/[\s\S]*?<\/text:list-style>/)?.[0] ?? '';
+ check('the clone keeps the bullet level 1', /text:level="1" text:bullet-char="➢"/.test(clone), clone);
+ check('the clone numbers level 2', / n.type === 'bulletList');
+ check('the overridden look survives without the name',
+ dirtyTop?.attrs?.bulletChar === '➢' && !dirtyTop?.attrs?.listStyleName, dirtyTop?.attrs);
+ check('its nested list is numbered', dirtyTop?.content?.[0]?.content?.[1]?.type === 'orderedList',
+ dirtyTop?.content?.[0]?.content?.[1]);
+ delete sheet.list['Tab Test'];
+ });
+
it('a foreign named list style is read back (display name decoded)', async () => {
const stylesXml = `
diff --git a/tests/unit/list-style.test.ts b/tests/unit/list-style.test.ts
index 724810f..077b30d 100644
--- a/tests/unit/list-style.test.ts
+++ b/tests/unit/list-style.test.ts
@@ -28,11 +28,30 @@ describe('effectiveListLevel (attr ?? style level ?? cycle default)', () => {
expect(eff.markerAlign).toBe('right'); // untouched channel still comes from the style
});
- it('serves the bullet level to a bullet node only', () => {
+ it('the level kind wins over the node species (a number level numbers a )', () => {
expect(effectiveListLevel({}, false, style, 2).bulletChar).toBe('✓');
- // An ordered node over the bullet level keeps the cycle default (null).
- expect(effectiveListLevel({}, true, style, 2).listStyleType).toBeNull();
- expect(effectiveListLevel({}, false, style, 1).bulletChar).toBeNull();
+ // An ordered node over the bullet level renders that bullet, not a numbering.
+ const overBullet = effectiveListLevel({}, true, style, 2);
+ expect(overBullet.kind).toBe('bullet');
+ expect(overBullet.bulletChar).toBe('✓');
+ expect(overBullet.listStyleType).toBeNull();
+ // A bullet node over a number level renders the numbering — start value included.
+ const overNumber = effectiveListLevel({}, false, style, 1);
+ expect(overNumber.kind).toBe('number');
+ expect(overNumber.listStyleType).toBe('upper-roman-paren');
+ expect(overNumber.bulletChar).toBeNull();
+ expect(effectiveListLevel({}, false, style, 3).startAt).toBe(3);
+ });
+
+ it('a sparse level still names its marker, as the manager preview shows it', () => {
+ const sparse: ListStyle = { name: 'S', levels: [{ kind: 'bullet' }, { kind: 'number' }] };
+ expect(effectiveListLevel({}, false, sparse, 1).bulletChar).toBe('•');
+ expect(effectiveListLevel({}, true, sparse, 2).listStyleType).toBe('decimal');
+ });
+
+ it('a node marker attr keeps its own species over the level', () => {
+ expect(effectiveListLevel({ bulletChar: '❖' }, false, style, 1)).toMatchObject({ kind: 'bullet', bulletChar: '❖' });
+ expect(effectiveListLevel({ listStyleType: 'decimal' }, true, style, 2)).toMatchObject({ kind: 'number', listStyleType: 'decimal' });
});
it('falls back to the cycle default past the defined levels and without a style', () => {
diff --git a/tests/unit/ordered-list-decorations.test.ts b/tests/unit/ordered-list-decorations.test.ts
index 7d3361b..0a26b3d 100644
--- a/tests/unit/ordered-list-decorations.test.ts
+++ b/tests/unit/ordered-list-decorations.test.ts
@@ -7,10 +7,10 @@ import Text from '@tiptap/extension-text';
import ListItem from '@tiptap/extension-list-item';
import { OrderedList } from '../../src/lib/editor/extensions/orderedList';
import { BulletList } from '../../src/lib/editor/extensions/bulletList';
-import { listStyleDecos } from '../../src/lib/editor/extensions/listStyle';
-import { builtinStyleSheet } from '../../src/lib/styles/styleSheet';
+import { ListStyle, listStyleDecos } from '../../src/lib/editor/extensions/listStyle';
+import { builtinStyleSheet, type StyleSheet } from '../../src/lib/styles/styleSheet';
-const schema = getSchema([Document, Paragraph, Text, ListItem, OrderedList, BulletList]);
+const schema = getSchema([Document, Paragraph, Text, ListItem, OrderedList, BulletList, ListStyle]);
const p = (t: string) => schema.nodes.paragraph.create(null, schema.text(t));
const li = (...content: PmNode[]) => schema.nodes.listItem.create(null, content);
@@ -57,3 +57,54 @@ describe('orderedListStyleDecos (effective numbering per )', () => {
expect(effStyles(d)).toEqual(['lower-alpha']);
});
});
+
+describe('named list styles decide each depth\'s kind', () => {
+ const uls = (attrs: Record | null, ...items: PmNode[]) => schema.nodes.bulletList.create(attrs, items);
+ const sheet = (): StyleSheet => {
+ const s = builtinStyleSheet();
+ s.list['Mixed'] = { name: 'Mixed', levels: [
+ { kind: 'bullet', bulletChar: '–' },
+ { kind: 'number', numType: 'decimal' },
+ { kind: 'number', numType: 'decimal', startAt: 4 },
+ ] };
+ return s;
+ };
+ // Every list node's decoration attrs, in document order.
+ function decoAttrs(d: PmNode): Record[] {
+ const set = listStyleDecos(d, sheet());
+ const out: Record[] = [];
+ d.descendants((node, pos) => {
+ if (node.type.name !== 'orderedList' && node.type.name !== 'bulletList') return;
+ const deco = set.find(pos, pos + 1).find((x) => x.from === pos) as { type?: { attrs?: Record } } | undefined;
+ out.push(deco?.type?.attrs ?? {});
+ });
+ return out;
+ }
+
+ it('a number level numbers a nested ; the start rides the counter', () => {
+ const d = doc(uls({ listStyleName: 'Mixed' },
+ li(p('a'), uls(null, li(p('b'), uls(null, li(p('c'))))))));
+ const [l1, l2, l3] = decoAttrs(d);
+ expect(l1['data-bullet']).toBe('–');
+ expect(l1['data-eff-list-style']).toBeUndefined();
+ expect(l2['data-eff-list-style']).toBe('decimal');
+ expect(l3['data-eff-list-style']).toBe('decimal');
+ expect(l3.style).toContain('counter-reset: list-item 3');
+ });
+
+ it('a bullet level bullets a nested ', () => {
+ const s = sheet();
+ s.list['Rev'] = { name: 'Rev', levels: [{ kind: 'number', numType: 'decimal' }, { kind: 'bullet', bulletChar: '✓' }] };
+ const d = doc(ol({ listStyleName: 'Rev' }, li(p('1'), ol(null, li(p('x'))))));
+ const set = listStyleDecos(d, s);
+ const out: Record[] = [];
+ d.descendants((node, pos) => {
+ if (node.type.name !== 'orderedList') return;
+ const deco = set.find(pos, pos + 1).find((x) => x.from === pos) as { type?: { attrs?: Record } } | undefined;
+ out.push(deco?.type?.attrs ?? {});
+ });
+ expect(out[0]['data-eff-list-style']).toBe('decimal');
+ expect(out[1]['data-bullet']).toBe('✓');
+ expect(out[1]['data-eff-list-style']).toBeUndefined();
+ });
+});