Browse Source

feat: Add eventStructure support to preview panel hierarchy display

- Update parsedSections to use metadata.eventStructure for accurate hierarchy
- Add helper function findEventByDTag for event lookup
- Now supports proper 30040 vs 30041 event type distinction
- Enhanced preview logging with eventStructure information

 Verified: Hierarchical parser generates proper 30040/30041 events
 Test: Level 3 parsing shows 7 events (1 index + 2 chapter indices + 4 content)
 Core: Event structure metadata available for advanced preview features

Ready for: Export functionality verification

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
master
limina1 7 months ago
parent
commit
491584479c
  1. 32
      src/lib/components/ZettelEditor.svelte

32
src/lib/components/ZettelEditor.svelte

@ -120,27 +120,39 @@ import Asciidoctor from "asciidoctor"; @@ -120,27 +120,39 @@ import Asciidoctor from "asciidoctor";
return options;
}
// Parse sections for preview display using PublicationTree data
// Parse sections for preview display using hierarchical eventStructure
let parsedSections = $derived.by(() => {
if (!publicationResult) return [];
if (!publicationResult || !publicationResult.metadata?.eventStructure) return [];
console.log("Preview: publicationResult structure:", {
hasContentEvents: !!publicationResult.contentEvents,
contentEventsLength: publicationResult.contentEvents?.length,
hasEventStructure: !!publicationResult.metadata.eventStructure,
eventStructureLength: publicationResult.metadata.eventStructure?.length,
keys: Object.keys(publicationResult)
});
// Convert PublicationTree events to preview format
return publicationResult.contentEvents.map((event: any) => {
const title = event.tags.find((t: string[]) => t[0] === 'title')?.[1] || 'Untitled';
const tags = event.tags.filter((t: string[]) => t[0] === 't');
// Helper to find event by dTag
const findEventByDTag = (events: any[], dTag: string) => {
return events.find(event => {
const eventDTag = event.tags.find((t: string[]) => t[0] === 'd')?.[1];
return eventDTag === dTag;
});
};
// Use eventStructure for accurate hierarchy display
return publicationResult.metadata.eventStructure.map((node: any) => {
const event = findEventByDTag(publicationResult.contentEvents, node.dTag);
const tags = event?.tags.filter((t: string[]) => t[0] === 't') || [];
return {
title,
content: event.content,
title: node.title,
content: event?.content || '',
tags, // Already in [['t', 'tag1'], ['t', 'tag2']] format
level: 2, // Default level for display
isIndex: event.kind === 30040,
level: node.level,
isIndex: node.eventKind === 30040,
eventKind: node.eventKind,
eventType: node.eventType
};
});
});

Loading…
Cancel
Save