Skip to content

Commit c021a1f

Browse files
author
Dyllan
committed
Add equation block support & code fallback
1 parent 11c0c4b commit c021a1f

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

src/blocks/decorator.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@
5555
<NotionDecorator :content="nextContent" v-bind="pass" />
5656
</s>
5757
<component
58-
v-else-if="decoratorKey === 'e'"
58+
v-else-if="decoratorKey === 'e' && katex"
5959
:is="'katex-element'"
6060
:expression="decoratorValue"
6161
/>
62+
<code v-else-if="decoratorKey === 'e'" class="notion-inline-code">
63+
<NotionDecorator :content="nextContent" v-bind="pass" />
64+
</code>
6265
<NotionDecorator v-else :content="nextContent" v-bind="pass" />
6366
</template>
6467

src/blocks/equation.vue

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<template>
2+
<div v-if="katex">
3+
<KatexElement :expression="equation" />
4+
</div>
5+
<pre v-else-if="prism && supported" :class="['notion-code', langClass]">
6+
<PrismComponent :language="lang">{{ equation }}</PrismComponent>
7+
</pre>
8+
<pre v-else :class="['notion-code', langClass]">
9+
<code :class="langClass">{{ equation }}</code>
10+
</pre>
11+
</template>
12+
13+
<script>
14+
import KatexElement from "vue-katex";
15+
import Blockable, { blockComputed } from "@/lib/blockable";
16+
17+
export default {
18+
extends: Blockable,
19+
name: "NotionCode",
20+
components: { KatexElement },
21+
data() {
22+
return { Prism, lang: "latex", langClass: "language-latex" };
23+
},
24+
computed: {
25+
...blockComputed,
26+
equation() {
27+
return this.properties?.title?.[0]?.[0];
28+
},
29+
},
30+
};
31+
</script>

src/components/block.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<NotionBookmark v-else-if="isType('bookmark')" v-bind="pass" />
1010
<NotionCallout v-else-if="isType('callout')" v-bind="pass" />
1111
<NotionCode v-else-if="isType('code')" v-bind="pass" />
12+
<NotionEquation v-else-if="isType('equation')" v-bind="pass" />
1213
<NotionText v-else-if="isType('text')" v-bind="pass" />
1314
<NotionQuote v-else-if="isType('quote')" v-bind="pass" />
1415
<NotionToggle v-else-if="isType('toggle')" v-bind="pass">
@@ -49,6 +50,7 @@ import NotionHeader from "@/blocks/header";
4950
import NotionText from "@/blocks/text";
5051
import NotionToggle from "@/blocks/toggle";
5152
import NotionQuote from "@/blocks/quote";
53+
import NotionEquation from "@/blocks/equation";
5254
5355
export default {
5456
extends: Blockable,
@@ -65,6 +67,7 @@ export default {
6567
NotionText,
6668
NotionToggle,
6769
NotionQuote,
70+
NotionEquation,
6871
},
6972
};
7073
</script>

src/lib/blockable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const blockProps = {
1212
pageLinkOptions: Object,
1313
pageLinkTarget: { type: String, default: "_self" },
1414
prism: { type: Boolean, default: false },
15+
katex: { type: Boolean, default: false },
1516
textLinkTarget: { type: String, default: "_blank" },
1617
todo: { type: Boolean, default: false },
1718
};
@@ -30,6 +31,7 @@ export const blockComputed = {
3031
mapPageUrl: this.mapPageUrl,
3132
pageLinkOptions: this.pageLinkOptions,
3233
prism: this.prism,
34+
katex: this.katex,
3335
todo: this.todo,
3436
};
3537
},

0 commit comments

Comments
 (0)