Skip to content

Commit

Permalink
fix(math): add wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Mar 29, 2020
1 parent ba3f4fc commit 39aae0f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
5 changes: 0 additions & 5 deletions packages/plugin-math/src/KatexView.svelte

This file was deleted.

11 changes: 4 additions & 7 deletions packages/plugin-math/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Plugin } from 'bytemd';
import katex from 'katex';
import remarkMath from 'remark-math';
import KatexView from './KatexView.svelte';
import Katex from './katex.svelte';

export default function math(): Plugin {
return {
Expand All @@ -19,12 +18,10 @@ export default function math(): Plugin {

const displayMode = node.properties.className.includes('math-display');
return {
component: KatexView,
component: Katex,
props: {
html: katex.renderToString(textNode.value as string, {
displayMode,
throwOnError: false,
}),
displayMode,
text: textNode.value,
},
};
},
Expand Down
19 changes: 19 additions & 0 deletions packages/plugin-math/src/katex.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script>
import katex from 'katex';
export let text;
export let displayMode;
</script>

<!-- Note: a wrapper(div or span) is necessary to make elements keep in order -->
{#if displayMode}
<div class="math math-display">
{@html katex.renderToString(text, {
displayMode: true,
throwOnError: false,
})}
</div>
{:else}
<span class="math math-inline">
{@html katex.renderToString(text, { throwOnError: false })}
</span>
{/if}

0 comments on commit 39aae0f

Please sign in to comment.