Skip to content

Commit

Permalink
Fixed (#1061)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronzulu authored Sep 10, 2024
1 parent 72e7535 commit 2d2c152
Showing 1 changed file with 4 additions and 44 deletions.
48 changes: 4 additions & 44 deletions src/util/RenderMarkdownWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ export class RenderMarkdownWrapper {
if (link.target.extension !== "md") {
this.embedMediaFile(el, link.target);
} else {
el.innerText = "";
this.renderTransclude(el, link, recursiveDepth);
// We get here if there is a transclusion link, such as "![[Test Embed]]"
// In version 1.12.4 and earlier we used the deprecated Obsidian MarkdownRenderer.renderMarkdown() and we
// needed to have our own method "renderTransclude()" that loaded the referenced file and rendered it.
// In version 1.12.5, we started using MarkdownRenderer.render() instead, which does this automatically.
}
}
});
Expand Down Expand Up @@ -115,46 +117,4 @@ export class RenderMarkdownWrapper {
el.innerText = target.path;
}
}

private async renderTransclude(
el: HTMLElement,
link: {
text: string;
file: string;
heading: string;
blockId: string;
target: TFile;
},
recursiveDepth: number,
) {
const cache = this.app.metadataCache.getCache(link.target.path);
const text = await this.app.vault.cachedRead(link.target);
let blockText;
if (link.heading) {
const clean = (s: string) => s.replace(NON_LETTER_SYMBOLS_REGEX, "");
const headingIndex = cache.headings?.findIndex(
(h) => clean(h.heading) === clean(link.heading),
);
const heading = cache.headings[headingIndex];

const startAt = heading.position.start.offset;
const endAt =
cache.headings.slice(headingIndex + 1).find((h) => h.level <= heading.level)
?.position?.start?.offset || text.length;

blockText = text.substring(startAt, endAt);
} else if (link.blockId) {
const block = cache.blocks[link.blockId];
const startAt = block.position.start.offset;
const endAt = block.position.end.offset;
blockText = text.substring(startAt, endAt);
} else {
blockText = text;
}

// We are operating here within the parent container.
// It already has the rtl div if necessary.
// We don't need another rtl div, so we can set direction to Unspecified
this.renderMarkdownWrapper(blockText, el, TextDirection.Unspecified, recursiveDepth + 1);
}
}

0 comments on commit 2d2c152

Please sign in to comment.