How to render markdown in component #2050
Replies: 4 comments 8 replies
-
Need to write a markdown-it plugin that duplicates that wrapped code for you 👀 . |
Beta Was this translation helpful? Give feedback.
-
Any tips on how to achieve components such Mintlify's Callout Boxes? Something along the lines of:
|
Beta Was this translation helpful? Give feedback.
-
What I get is: <template>
<div v-html="renderedContent"></div>
</template>
<script setup lang="ts">
import { computed, getCurrentInstance } from 'vue'
import type { Slot } from 'vue'
const instance = getCurrentInstance()
// This get the rawContent (markdown text) from default slot
const rawContent = computed<string>(() => {
const defaultSlot: Slot | undefined = instance?.slots.default
if (!defaultSlot) return ''
const renderedSlots = defaultSlot()
if (renderedSlots.length > 0)
return renderedSlots[0].children?.toString().trim() ?? ''
return ''
})
// This render content to HTML
const renderedContent = computed(() => {
// TODO: parse rawContent with `markdown-it` and return rendered HTML
})
</script> That's it. That Note: For web security, you may need to use something like |
Beta Was this translation helpful? Give feedback.
-
I want to implement a component to display the markdown source code on the left and the rendering results on the right.
But I don't know how to render markdown in the component.
My expected usage is as follows:
Beta Was this translation helpful? Give feedback.
All reactions