mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-23 23:10:17 +05:30
feat(plugins): add export-format registration hook to plugin API
Add context.formats.registerExportFormat(id, opts) to PluginContext,
backed by a new FormatRegistry (mirrors PluginRegistry's Map-based
shape). Plugins register namespaced (${pluginId}:${id}) export
formats with a label/extension/handler; the writing-studio built-in
plugin registers a trivial "sprint-summary" .txt export as a
worked example.
The plugin system lives entirely in the renderer process while the
Export menu is built in main.js, so wiring formats into the menu
required a small IPC round-trip: renderer sends format metadata to
main after plugin load (main rebuilds the menu via the already-
idempotent createMenu()), and a menu click sends the resolved save
path back to the renderer, which is the only process holding the
plugin's handler function.
Amit Haridas
This commit is contained in:
@@ -21,6 +21,7 @@ describe('PluginContext', () => {
|
||||
},
|
||||
ipc: { invoke: jest.fn(), on: jest.fn() },
|
||||
exportHooks: { preHooks: [], postHooks: [] },
|
||||
formatRegistry: { register: jest.fn(), get: jest.fn(), getAll: jest.fn() },
|
||||
};
|
||||
context = new PluginContext(mockDeps);
|
||||
});
|
||||
@@ -87,4 +88,18 @@ describe('PluginContext', () => {
|
||||
context.exports.registerPostHook(handler);
|
||||
expect(mockDeps.exportHooks.postHooks).toContain(handler);
|
||||
});
|
||||
|
||||
test('exposes formats.registerExportFormat with namespaced id', () => {
|
||||
const handler = jest.fn();
|
||||
const opts = { label: 'My Format', extension: 'txt', handler };
|
||||
context.formats.registerExportFormat('my-format', opts);
|
||||
expect(mockDeps.formatRegistry.register).toHaveBeenCalledWith('test-plugin:my-format', opts);
|
||||
});
|
||||
|
||||
test('formats.registerExportFormat is a no-op when no formatRegistry is injected', () => {
|
||||
const noRegistryContext = new PluginContext({ ...mockDeps, formatRegistry: undefined });
|
||||
expect(() =>
|
||||
noRegistryContext.formats.registerExportFormat('x', { handler: jest.fn() })
|
||||
).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user