Skip to content

Commit f5eb555

Browse files
committed
refactor: use more modern style to define component
1 parent 645e31f commit f5eb555

File tree

5 files changed

+39
-61
lines changed

5 files changed

+39
-61
lines changed

dist/VueMarkdown.d.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { type Component } from "vue";
1+
import MarkdownIt from "markdown-it";
22
export type { Options } from "markdown-it";
3-
declare const VueMarkdown: Component;
3+
declare const VueMarkdown: import("vue").DefineSetupFnComponent<{
4+
source: string;
5+
options?: MarkdownIt.Options | undefined;
6+
plugins?: MarkdownIt.PluginSimple[] | undefined;
7+
}, {}, {}, {
8+
source: string;
9+
options?: MarkdownIt.Options | undefined;
10+
plugins?: MarkdownIt.PluginSimple[] | undefined;
11+
} & {}, import("vue").PublicProps>;
412
export default VueMarkdown;

dist/VueMarkdown.js

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

dist/VueMarkdown.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/App.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<script setup lang="ts">
22
// This starter template is using Vue 3 <script setup> SFCs
33
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
4-
import VueMarkdown, { Options } from '../../dist/VueMarkdown'
5-
import { ref } from 'vue'
4+
import VueMarkdown, { Options } from "../../dist/VueMarkdown";
5+
import { ref } from "vue";
66
7-
const i = ref(0)
8-
const options: Options = { html: true }
7+
const i = ref(0);
8+
const options: Options = { html: true };
99
</script>
1010

1111
<template>
1212
<img alt="Vue logo" src="./assets/logo.png" />
1313
<button type="button" @click="i++">Increment</button>
14-
<vue-markdown
14+
<VueMarkdown
1515
:source="`# This is a markdown heading\n## This is your number: ${i}.\n<i>HTML is allowed via options</i>`"
1616
:options="options"
17-
></vue-markdown>
17+
/>
1818
</template>
1919

2020
<style>

src/VueMarkdown.ts

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,16 @@ import MarkdownIt, {
22
type Options as MarkdownItOptions,
33
type PluginSimple,
44
} from "markdown-it";
5-
import {
6-
type Component,
7-
type PropType,
8-
computed,
9-
defineComponent,
10-
h,
11-
ref,
12-
} from "vue";
5+
import { computed, defineComponent, h, ref } from "vue";
136
export type { Options } from "markdown-it";
147

15-
const VueMarkdown: Component = defineComponent({
16-
name: "VueMarkdown",
17-
props: {
18-
source: {
19-
type: String,
20-
required: true,
21-
},
22-
options: {
23-
type: Object as PropType<MarkdownItOptions>,
24-
required: false,
25-
},
26-
plugins: {
27-
type: Array as PropType<PluginSimple[]>,
28-
required: false,
29-
},
30-
},
31-
setup(props) {
32-
const md = ref<MarkdownIt>(new MarkdownIt(props.options ?? {}));
8+
const VueMarkdown = defineComponent(
9+
(props: {
10+
source: string;
11+
options?: MarkdownItOptions;
12+
plugins?: PluginSimple[];
13+
}) => {
14+
const md = ref(new MarkdownIt(props.options ?? {}));
3315

3416
for (const plugin of props.plugins ?? []) {
3517
md.value.use(plugin);
@@ -39,6 +21,9 @@ const VueMarkdown: Component = defineComponent({
3921

4022
return () => h("div", { innerHTML: content.value });
4123
},
42-
});
24+
{
25+
props: ["source", "options", "plugins"],
26+
}
27+
);
4328

4429
export default VueMarkdown;

0 commit comments

Comments
 (0)