feat: parse desktop OneNote table of contents

This commit is contained in:
2026-07-22 18:54:32 +02:00
parent f581cbdced
commit a0c26d604d
3 changed files with 595 additions and 30 deletions

View File

@@ -5,6 +5,7 @@ import { resolve } from 'node:path';
import { describe, expect, it } from 'vitest';
import { parseOneNoteSection } from '../parser/parse-section.js';
import { parseOneNoteTableOfContents } from '../parser/parse-toc.js';
import { enumerateCabinet, extractCabinet } from './cabinet.js';
import { openOneNotePackage } from './package.js';
@@ -111,4 +112,36 @@ describe('pinned Joplin .onepkg fixture', () => {
text: 'Link to page: Page 2',
});
});
it('interprets both desktop TOCs with their authored ordering', async () => {
const extraction = await extractCabinet(JOPLIN_ONEPKG);
const root = extraction.extractedEntries.find(
(entry) => entry.normalizedPath === 'Open Notebook.onetoc2'
);
const group = extraction.extractedEntries.find(
(entry) => entry.normalizedPath === 'Section group/Open Notebook.onetoc2'
);
expect(root).toBeDefined();
expect(group).toBeDefined();
expect(
parseOneNoteTableOfContents(root!.bytes, {
sourceName: root!.normalizedPath,
}).entries.map((entry) => [entry.orderingId, entry.filename])
).toEqual([
[1, 'Tést!.one'],
[2, 'OneNote_RecycleBin'],
[3, 'Another section.one'],
[4, 'Section group'],
[5, '⅀⸨ Unicode ⸩.one'],
]);
expect(
parseOneNoteTableOfContents(group!.bytes, {
sourceName: group!.normalizedPath,
}).entries.map((entry) => [entry.orderingId, entry.filename])
).toEqual([
[1, 'A.one'],
[2, 'B.one'],
]);
});
});