Skip to content

Commit a970188

Browse files
authored
Merge pull request #60 from dyllan-to-yu/main
2 parents 11c0c4b + 64a0e9d commit a970188

File tree

10 files changed

+87
-15
lines changed

10 files changed

+87
-15
lines changed

dev/serve.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import Dev from "./serve.vue";
33

44
import VueKatex from "vue-katex";
55

6-
Vue.config.productionTip = false;
7-
86
Vue.use(VueKatex);
97

8+
Vue.config.productionTip = false;
9+
1010
new Vue({
1111
render: (h) => h(Dev),
1212
}).$mount("#app");

dev/serve.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div id="app">
3-
<NotionRenderer :blockMap="blockMap" fullPage prism todo />
3+
<NotionRenderer :blockMap="blockMap" fullPage prism katex todo />
44
</div>
55
</template>
66

docs/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The `NotionRenderer` component offers a few properties
2323
- [`pageLinkOptions`](#pageLinkOptions) – default: `undefined`
2424
- [`pageLinkTarget`](#pageLinkTarget) – default: `"_self"`
2525
- [`prism`](#prism) – default: `false`
26+
- [`katex`](#katex) – default: `false`
2627
- [`textLinkTarget`](#textLinkTarget) – default: `"_blank"`
2728

2829
### `blockMap`: Object
@@ -94,6 +95,12 @@ pageLinkOptions: {
9495

9596
> Check the `docs#syntax-highlighting` section below for more details.
9697
98+
### `katex`: Boolean
99+
100+
– whether or not latex rendering using vue-katex should be activated.
101+
102+
> Check the `docs#equations` section below for more details.
103+
97104
### `textLinkTarget`: String
98105

99106
– the [target attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target) of links
@@ -141,6 +148,13 @@ import VueKatex from "vue-katex";
141148
Vue.use(VueKatex);
142149
```
143150

151+
- Add the `katex` flag to the `NotionRenderer`
152+
153+
```diff
154+
-<NotionRenderer :blockMap="blockMap" />
155+
+<NotionRenderer :blockMap="blockMap" katex />
156+
```
157+
144158
> For usage with Nuxt, look at the `/example` (`plugins` in `nuxt.config.js`, `plugins/vue-katex.js`)
145159
146160
## Notion API

package-lock.json

Lines changed: 24 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@rollup/plugin-alias": "^2.2.0",
3939
"@rollup/plugin-commonjs": "^20.0.0",
4040
"@rollup/plugin-replace": "^3.0.0",
41+
"@types/prismjs": "^1.16.6",
4142
"@vue/cli-plugin-babel": "^4.3.1",
4243
"@vue/cli-service": "^4.3.1",
4344
"cross-env": "^7.0.2",
@@ -52,12 +53,12 @@
5253
"rollup-plugin-terser": "^7.0.2",
5354
"rollup-plugin-vue": "^5.1.9",
5455
"vue": "^2.6.14",
56+
"vue-katex": "^0.5.0",
5557
"vue-template-compiler": "^2.6.14"
5658
},
5759
"peerDependencies": {
5860
"prismjs": "^1.22.0",
59-
"vue": "^2.6.14",
60-
"vue-katex": "^0.5.0"
61+
"vue": "^2.6.14"
6162
},
6263
"engines": {
6364
"node": ">=10"

src/blocks/code.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,25 @@
1212
<script>
1313
import Prism from "prismjs";
1414
import PrismComponent from "vue-prism-component";
15-
import Blockable, { blockComputed } from "@/lib/blockable";
15+
import Blockable, { blockComputed, blockProps } from "@/lib/blockable";
1616
1717
export default {
1818
extends: Blockable,
1919
name: "NotionCode",
2020
components: { PrismComponent },
21+
props: { ...blockProps, overrideLang: String, overrideLangClass: String },
2122
data() {
2223
return { Prism };
2324
},
2425
computed: {
2526
...blockComputed,
2627
lang() {
27-
return this.properties?.language?.[0]?.[0]?.toLowerCase();
28+
return (
29+
this.overrideLang || this.properties?.language?.[0]?.[0]?.toLowerCase()
30+
);
2831
},
2932
langClass() {
30-
return `language-${this.lang}`;
33+
return this.overrideLangClass || `language-${this.lang}`;
3134
},
3235
supported() {
3336
return this.Prism.languages[this.lang];

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+
{{ decoratorValue }}
64+
</code>
6265
<NotionDecorator v-else :content="nextContent" v-bind="pass" />
6366
</template>
6467

src/blocks/equation.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<template>
2+
<div v-if="katex">
3+
<component :is="'katex-element'" :expression="equation" />
4+
</div>
5+
<NotionCode
6+
v-else
7+
v-bind="pass"
8+
overrideLang="latex"
9+
overrideLangClass="language-latex"
10+
/>
11+
</template>
12+
13+
<script>
14+
import Blockable, { blockComputed } from "@/lib/blockable";
15+
import NotionCode from "@/blocks/code";
16+
17+
export default {
18+
extends: Blockable,
19+
name: "NotionEquation",
20+
components: { NotionCode },
21+
computed: {
22+
...blockComputed,
23+
equation() {
24+
return this.properties?.title?.[0]?.[0];
25+
},
26+
},
27+
};
28+
</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)