Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 28 additions & 29 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,38 +932,37 @@ export async function tryCopyMarkdownByRead(

// Process embeds BEFORE converting WikiLinks to Markdown
// This ensures block embeds like ![[#^blockid]] are handled correctly
const cfile = plugin.app.workspace.getActiveFile();
if (cfile != undefined) {
const embedMap = await getEmbedMap(plugin, content, cfile.path);
const embeds = await getEmbeds(content);
for (const index in embeds) {
const embedMatch = embeds[index];
const fullMatch = embedMatch[0];
const embedLink = embedMatch[1];

let replacement = embedMap.get(embedLink);

// If not in embedMap and inlineBlockEmbeds is enabled, try to extract block content
if (replacement === undefined && plugin.settings.inlineBlockEmbeds) {
const parsed = parseEmbedLink(embedLink, cfile.path);
if (parsed.blockId && parsed.filePath) {
const blockContent = await getBlockContent(
plugin,
parsed.filePath,
parsed.blockId
);
if (blockContent !== null) {
// Format block content as quote block
replacement = "> " + blockContent.replace(/\n/g, "\n> ");
}
// Use the file being exported instead of getActiveFile() to avoid issues
// when the active file changes during async processing or is undefined
const embedMap = await getEmbedMap(plugin, content, file.path);
const embeds = await getEmbeds(content);
for (const index in embeds) {
const embedMatch = embeds[index];
const fullMatch = embedMatch[0];
const embedLink = embedMatch[1];

let replacement = embedMap.get(embedLink);

// If not in embedMap and inlineBlockEmbeds is enabled, try to extract block content
if (replacement === undefined && plugin.settings.inlineBlockEmbeds) {
const parsed = parseEmbedLink(embedLink, file.path);
if (parsed.blockId && parsed.filePath) {
const blockContent = await getBlockContent(
plugin,
parsed.filePath,
parsed.blockId
);
if (blockContent !== null) {
// Format block content as quote block
replacement = "> " + blockContent.replace(/\n/g, "\n> ");
}
}
}

// Only replace if we found a replacement
// This prevents replacing with "undefined"
if (replacement !== undefined) {
content = content.replace(fullMatch, replacement);
}
// Only replace if we found a replacement
// This prevents replacing with "undefined"
if (replacement !== undefined) {
content = content.replace(fullMatch, replacement);
}
}

Expand Down