Skip to content

Commit

Permalink
feat: add onMount
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Jun 12, 2020
1 parent 7cfaf05 commit ede2e38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/bytemd/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface BytemdPlugin {
remarkTransformer?: Transformer;
rehypeTransformer?: Transformer;
sanitizeSchema?: any;
onMount(el: HTMLElement): void;
}

export interface EditorProps {
Expand Down
13 changes: 12 additions & 1 deletion packages/bytemd/src/viewer.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
<script>
import { afterUpdate } from 'svelte';
import { processMarkdown } from './utils';
export let value = '';
export let plugins = [];
let el;
afterUpdate(() => {
plugins.forEach((p) => {
if (p.onMount) {
p.onMount(el);
}
});
});
$: html = processMarkdown(value, plugins);
// $: console.log(html);
</script>

<div class="markdown-body">
<div bind:this={el} class="markdown-body">
{@html html}
</div>

0 comments on commit ede2e38

Please sign in to comment.