MCPcopy Create free account
hub / github.com/UNLINEARITY/Obsidian-CodeSpace / runPatchedNativePdfExport

Function runPatchedNativePdfExport

src/native_pdf_export_patch.ts:485–514  ·  view source on GitHub ↗
(
	plugin: CodeSpacePlugin,
	invokeOriginal: () => unknown,
	preferredView?: MutableMarkdownView | null
)

Source from the content-addressed store, hash-verified

483}
484
485async function runPatchedNativePdfExport(
486 plugin: CodeSpacePlugin,
487 invokeOriginal: () => unknown,
488 preferredView?: MutableMarkdownView | null
489): Promise<unknown> {
490 const view =
491 (preferredView?.file ? preferredView : null) ??
492 (plugin.app.workspace.getActiveViewOfType(MarkdownView) as MutableMarkdownView | null);
493 if (!view?.file) {
494 debugNativePdf(null, "native export invoked without active markdown view");
495 return await Promise.resolve(invokeOriginal());
496 }
497
498 const ownerDoc = view.containerEl?.ownerDocument ?? activeDocument;
499 const knownModals = getModalContainers(ownerDoc);
500 const fallbackMarkdown = view.getViewData();
501 const stopSession = beginNativeExportSession(plugin, view.file, fallbackMarkdown, ownerDoc, knownModals);
502 debugNativePdf(activeNativeExportSession, "invoking original native export command", {
503 file: view.file.path,
504 markdownLength: fallbackMarkdown.length,
505 });
506
507 try {
508 const result = await Promise.resolve(invokeOriginal());
509 return result;
510 } catch (error) {
511 stopSession();
512 throw error;
513 }
514}
515
516function installCachedReadOverride(plugin: CodeSpacePlugin) {
517 const vault = plugin.app.vault as MutableVault;

Callers 2

Calls 4

debugNativePdfFunction · 0.85
getModalContainersFunction · 0.85
beginNativeExportSessionFunction · 0.85
getViewDataMethod · 0.80

Tested by

no test coverage detected