|
| 1 | +<script setup lang="ts"> |
| 2 | +import { useStorage } from '@vueuse/core'; |
| 3 | +import { renderMarkdown } from './markdown-preview.service'; |
| 4 | +
|
| 5 | +const inputMarkdown = useStorage('markdown-preview:input', ''); |
| 6 | +const previewHtml = computed(() => renderMarkdown(inputMarkdown.value)); |
| 7 | +</script> |
| 8 | + |
| 9 | +<template> |
| 10 | + <div class="markdown-preview-tool"> |
| 11 | + <c-input-text |
| 12 | + v-model:value="inputMarkdown" |
| 13 | + |
| 14 | + placeholder="Your Markdown content..." |
| 15 | + rows="8" |
| 16 | + |
| 17 | + label="Your Markdown to preview:" |
| 18 | + autocomplete="off" |
| 19 | + autocorrect="off" |
| 20 | + autocapitalize="off" |
| 21 | + spellcheck="false" |
| 22 | + raw-text autofocus multiline monospace |
| 23 | + test-id="markdown-input" |
| 24 | + /> |
| 25 | + |
| 26 | + <n-divider /> |
| 27 | + |
| 28 | + <n-form-item label="Rendered preview:"> |
| 29 | + <c-card> |
| 30 | + <div |
| 31 | + class="markdown-preview" |
| 32 | + data-test-id="markdown-preview" |
| 33 | + v-html="previewHtml" |
| 34 | + /> |
| 35 | + </c-card> |
| 36 | + </n-form-item> |
| 37 | + </div> |
| 38 | +</template> |
| 39 | + |
| 40 | +<style lang="less" scoped> |
| 41 | +.markdown-preview-tool { |
| 42 | + flex: 0 0 100%; |
| 43 | +} |
| 44 | +
|
| 45 | +.markdown-preview { |
| 46 | + overflow: auto; |
| 47 | + width: 100%; |
| 48 | + min-height: 200px; |
| 49 | + max-height: 600px; |
| 50 | + box-sizing: border-box; |
| 51 | + scrollbar-width: none; |
| 52 | + -ms-overflow-style: none; |
| 53 | +
|
| 54 | + &::-webkit-scrollbar { |
| 55 | + display: none; |
| 56 | + } |
| 57 | +
|
| 58 | + :deep(h1) { font-size: 1.5em; } |
| 59 | + :deep(h2) { font-size: 1.3em; } |
| 60 | + :deep(h3) { font-size: 1.1em; } |
| 61 | + :deep(h1), :deep(h2), :deep(h3) { margin: 0.5em 0; line-height: 1.3; } |
| 62 | + :deep(p), :deep(ul), :deep(ol) { margin: 0.5em 0; line-height: 1.6; } |
| 63 | + :deep(ul), :deep(ol) { padding-left: 1.5em; } |
| 64 | + :deep(code) { background: var(--n-color-modal); padding: 0.2em 0.4em; border-radius: 4px; font-size: 0.9em; } |
| 65 | + :deep(pre) { background: var(--n-color-modal); padding: 12px; border-radius: 6px; overflow-x: auto; margin: 0.5em 0; } |
| 66 | + :deep(pre code) { background: none; padding: 0; font-size: 0.9em; } |
| 67 | + :deep(a) { color: var(--n-color-primary); text-decoration: none; } |
| 68 | + :deep(a:hover) { text-decoration: underline; } |
| 69 | +} |
| 70 | +</style> |
0 commit comments