refactor: consolidate block processing logic
Introduce a centralized `block-processor` and `block-scanner` to handle markdown fenced code blocks. This replaces the previous `inline-blocks.ts` and individual completion sources with a unified approach that handles block stripping, directive replacement, and metadata extraction (stats, templates, and spark tables) in a single pass.
This commit is contained in:
@@ -4,10 +4,8 @@
|
||||
|
||||
import { diceSource } from "./sources/dice.js";
|
||||
import { linksSource } from "./sources/links.js";
|
||||
import { sparkTablesSource } from "./sources/spark-tables.js";
|
||||
import { statsSource } from "./sources/stats.js";
|
||||
import { templatesSource } from "./sources/templates.js";
|
||||
import type { CompletionSource, CompletionsPayload } from "./types.js";
|
||||
import type { ProcessedBlocks } from "./block-processor.js";
|
||||
import type { CompletionsPayload } from "./types.js";
|
||||
|
||||
export type {
|
||||
CompletionsPayload,
|
||||
@@ -18,27 +16,22 @@ export type {
|
||||
StatTemplate,
|
||||
} from "./types.js";
|
||||
|
||||
/** Registered sources — open for extension */
|
||||
const sources: CompletionSource[] = [
|
||||
diceSource,
|
||||
linksSource,
|
||||
sparkTablesSource,
|
||||
statsSource,
|
||||
templatesSource,
|
||||
];
|
||||
|
||||
/**
|
||||
* Scan the full content index and return structured completion data.
|
||||
* Build completions from the content index and pre-collected blocks.
|
||||
* Called at server startup and on any file change.
|
||||
*/
|
||||
export function scanCompletions(
|
||||
index: Record<string, string>,
|
||||
blocks: ProcessedBlocks,
|
||||
): CompletionsPayload {
|
||||
const payload: Record<string, unknown[]> = {};
|
||||
const dice = diceSource.scan(index) as CompletionsPayload["dice"];
|
||||
const links = linksSource.scan(index) as CompletionsPayload["links"];
|
||||
|
||||
for (const source of sources) {
|
||||
payload[source.key] = source.scan(index);
|
||||
}
|
||||
|
||||
return payload as unknown as CompletionsPayload;
|
||||
return {
|
||||
dice,
|
||||
links,
|
||||
sparkTables: blocks.sparkTables,
|
||||
stats: blocks.stats,
|
||||
statTemplates: blocks.statTemplates,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user