Skip to content

Commit 134114c

Browse files
committed
add custom component
1 parent 7d9827e commit 134114c

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-2
lines changed

dev/serve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ Vue.use(VueKatex);
88
Vue.config.productionTip = false;
99

1010
new Vue({
11-
render: (h) => h(Dev),
11+
render: h => h(Dev)
1212
}).$mount("#app");

example/nuxt.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ export default {
2323
buildModules: ["vue-notion/nuxt"],
2424

2525
// Plugins (e.g. vue-katex for equations)
26-
plugins: ["~/plugins/vue-katex.js"],
26+
plugins: [
27+
"~/plugins/vue-katex.js",
28+
"~/plugins/vue-custom-notion-component.js",
29+
],
2730
};

example/pages/_slug.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<NotionRenderer
33
:blockMap="blockMap"
4+
:blockOverrides="blockOverrides"
45
:pageLinkOptions="pageLinkOptions"
56
fullPage
67
prism
@@ -15,6 +16,7 @@ import "prismjs/themes/prism.css";
1516
export default {
1617
data() {
1718
return {
19+
blockOverrides: { code: "CustomCode" },
1820
pageLinkOptions: { component: "NuxtLink", href: "to" },
1921
};
2022
},

example/plugins/custom-code.vue

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<template>
2+
<pre
3+
:style="{
4+
border: '3px solid tomato',
5+
}"
6+
v-if="prism && supported"
7+
:class="['notion-code', langClass]"
8+
><PrismComponent :language="lang">{{ properties.title[0][0] }}</PrismComponent></pre>
9+
<pre
10+
v-else
11+
:class="['notion-code', langClass]"
12+
><code :class="langClass">{{ properties.title[0][0] }}</code></pre>
13+
</template>
14+
15+
<script>
16+
import Prism from "prismjs";
17+
import PrismComponent from "vue-prism-component";
18+
import { Blockable, blockComputed, blockProps } from "vue-notion";
19+
20+
export default {
21+
extends: Blockable,
22+
name: "CustomCode",
23+
components: { PrismComponent },
24+
props: { ...blockProps, overrideLang: String, overrideLangClass: String },
25+
data() {
26+
return { Prism };
27+
},
28+
computed: {
29+
...blockComputed,
30+
lang() {
31+
return (
32+
this.overrideLang || this.properties?.language?.[0]?.[0]?.toLowerCase()
33+
);
34+
},
35+
langClass() {
36+
return this.overrideLangClass || `language-${this.lang}`;
37+
},
38+
supported() {
39+
return this.Prism.languages[this.lang];
40+
},
41+
},
42+
};
43+
</script>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Vue from "vue";
2+
import CustomCode from "./custom-code.vue";
3+
4+
Vue.component("CustomCode", CustomCode);

0 commit comments

Comments
 (0)