65 lines
1.2 KiB
Vue
65 lines
1.2 KiB
Vue
<template>
|
|
<div class="demo">
|
|
<textarea v-model="source" class="field" spellcheck="false" />
|
|
|
|
<h4 v-text="'toHTML 的输出'" />
|
|
<div class="preview" v-html="html" />
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { ref, watch } from "vue";
|
|
import { Markdown } from "timi-web";
|
|
|
|
const source = ref(`## 渲染结果
|
|
|
|
支持标题、列表与代码高亮:
|
|
|
|
- 无序列表项
|
|
- 行内 \`代码\` 会渲染为红色
|
|
|
|
\`\`\`typescript
|
|
const answer: number = 42;
|
|
\`\`\`
|
|
`);
|
|
|
|
const html = ref("");
|
|
|
|
/** toHTML 返回字符串或 Promise,两种都要接住。 */
|
|
async function render() {
|
|
html.value = await Markdown.getInstance().toHTML(source.value);
|
|
}
|
|
|
|
watch(source, render, { immediate: true });
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.demo {
|
|
.field {
|
|
width: 100%;
|
|
height: 11rem;
|
|
padding: .75rem;
|
|
margin-bottom: 1.25rem;
|
|
box-sizing: border-box;
|
|
font-size: .8125rem;
|
|
font-family: monospace;
|
|
line-height: 1.6;
|
|
border: 1px solid var(--vp-c-divider);
|
|
border-radius: .5rem;
|
|
color: var(--vp-c-text-1);
|
|
background: var(--vp-c-bg-soft);
|
|
}
|
|
|
|
h4 {
|
|
margin: 0 0 .5rem;
|
|
font-size: .8125rem;
|
|
}
|
|
|
|
.preview {
|
|
padding: 0 1rem;
|
|
border: 1px solid var(--vp-c-divider);
|
|
border-radius: .5rem;
|
|
}
|
|
}
|
|
</style>
|