forked from vrtmrz/obsidian-tagfolder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScrollViewMarkdownComponent.svelte
53 lines (45 loc) · 1.2 KB
/
ScrollViewMarkdownComponent.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<script lang="ts">
import { MarkdownRenderer } from "obsidian";
import { onDestroy, onMount } from "svelte";
import { type ScrollViewFile } from "types";
export let file: ScrollViewFile = { path: "" };
export let observer: IntersectionObserver;
let el: HTMLElement;
let renderedContent = "";
function onAppearing(this: HTMLElement, _: Event) {
if (file.content && el && renderedContent != file.content) {
MarkdownRenderer.renderMarkdown(file.content, el, file.path, null);
renderedContent = file.content;
}
}
onMount(() => {
observer.observe(el);
el.addEventListener("appearing", onAppearing);
});
onDestroy(() => {
observer.unobserve(el);
el.removeEventListener("appearing", onAppearing);
});
$: {
if (
renderedContent &&
file &&
file.content &&
el &&
renderedContent != file.content
) {
el.style.minHeight = `${el.clientHeight}px`;
el.innerHTML = "";
MarkdownRenderer.renderMarkdown(file.content, el, file.path, null);
renderedContent = file.content;
el.style.minHeight = "20px";
}
}
</script>
<div class="markdownBody" bind:this={el} style="min-height: 1em;" />
<style>
.markdownBody {
user-select: text;
-webkit-user-select: text;
}
</style>