|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref, computed, type Component } from 'vue' |
| 3 | +import { MDC } from 'mdc-syntax/vue' |
| 4 | +import CustomAlert from './components/CustomAlert.vue' |
| 5 | +import CustomHeading from './components/CustomHeading.vue' |
| 6 | +import StreamingPreview from './components/StreamingPreview.vue' |
| 7 | +
|
| 8 | +const sampleMarkdown = `# MDC Syntax for Vue |
| 9 | +
|
| 10 | +Welcome to **MDC Syntax** - a powerful markdown parser built for the *AI era*. |
| 11 | +
|
| 12 | +## Features |
| 13 | +
|
| 14 | +- 🚀 **5.5x faster** than regex-based parsers |
| 15 | +- ⚡ O(n) linear-time algorithm |
| 16 | +- 🔄 Streaming support for real-time rendering |
| 17 | +- 🎨 Custom component support |
| 18 | +- 📦 Zero dependencies |
| 19 | +
|
| 20 | +## Code Example |
| 21 | +
|
| 22 | +Here's a simple Vue example: |
| 23 | +
|
| 24 | +\`\`\`vue |
| 25 | +<script setup> |
| 26 | +import { MDC } from 'mdc-syntax/vue' |
| 27 | +
|
| 28 | +const markdown = \`# Hello **World**\`\n<` |
| 29 | + + `/script> |
| 30 | +
|
| 31 | +<template> |
| 32 | + <MDC :markdown="markdown" /> |
| 33 | +</template> |
| 34 | +\`\`\` |
| 35 | +
|
| 36 | +## Custom Components |
| 37 | +
|
| 38 | +MDC supports custom Vue-like components: |
| 39 | +
|
| 40 | +::alert{type="success"} |
| 41 | +This is a **success** alert with custom styling! |
| 42 | +:: |
| 43 | +
|
| 44 | +::alert{type="warning"} |
| 45 | +⚠️ This parser handles streaming markdown correctly, even with incomplete syntax. |
| 46 | +:: |
| 47 | +
|
| 48 | +## Lists |
| 49 | +
|
| 50 | +### Ordered List |
| 51 | +1. First item |
| 52 | +2. Second item |
| 53 | +3. Third item |
| 54 | +
|
| 55 | +### Unordered List |
| 56 | +- React support |
| 57 | +- Vue support |
| 58 | +- TypeScript support |
| 59 | +- Zero dependencies |
| 60 | +
|
| 61 | +## Links & Formatting |
| 62 | +
|
| 63 | +Visit [MDC Syntax on GitHub](https://github.com/nuxt-content/mdc-syntax) for more information. |
| 64 | +
|
| 65 | +You can use *italic*, **bold**, and even ~~strikethrough~~ text. |
| 66 | +
|
| 67 | +## Blockquotes |
| 68 | +
|
| 69 | +> "The development of full artificial intelligence could spell the end of the human race." |
| 70 | +> — Stephen Hawking |
| 71 | +
|
| 72 | +## Tables |
| 73 | +
|
| 74 | +| Feature | MDC Syntax | Traditional Parsers | |
| 75 | +|---------|-----------|---------------------| |
| 76 | +| Speed | 5.5x faster | Baseline | |
| 77 | +| Streaming | ✅ Auto-close | ❌ Broken | |
| 78 | +| Algorithm | O(n) | O(n²) or worse | |
| 79 | +
|
| 80 | +--- |
| 81 | +
|
| 82 | +## Try It Yourself |
| 83 | +
|
| 84 | +Edit the markdown below to see it update in real-time! |
| 85 | +` |
| 86 | +
|
| 87 | +const markdown = ref(sampleMarkdown) |
| 88 | +const useCustom = ref(true) |
| 89 | +const mode = ref<'editor' | 'streaming'>('editor') |
| 90 | +
|
| 91 | +const customComponents = computed<Record<string, Component>>(() => { |
| 92 | + if (!useCustom.value) return {} |
| 93 | + return { |
| 94 | + alert: CustomAlert, |
| 95 | + h1: CustomHeading, |
| 96 | + } |
| 97 | +}) |
| 98 | +</script> |
| 99 | + |
| 100 | +<template> |
| 101 | + <Suspense> |
| 102 | + <div class="h-screen flex flex-col overflow-hidden max-w-[1400px] mx-auto"> |
| 103 | + <header class="flex-shrink-0 text-center py-6 px-8 border-b-2 border-neutral-200 dark:border-neutral-700"> |
| 104 | + <h1 class="text-4xl bg-gradient-to-r from-green-500 to-teal-500 bg-clip-text text-transparent"> |
| 105 | + MDC Syntax - Vue Example |
| 106 | + </h1> |
| 107 | + <p class="mt-2 text-neutral-500 dark:text-neutral-400"> |
| 108 | + Interactive markdown editor with live preview & streaming support |
| 109 | + </p> |
| 110 | + </header> |
| 111 | + |
| 112 | + <div class="flex-shrink-0 px-8 py-4 bg-neutral-50 dark:bg-neutral-800 border-b border-neutral-200 dark:border-neutral-700"> |
| 113 | + <div class="flex items-center gap-4 flex-wrap"> |
| 114 | + <button |
| 115 | + :class="[ |
| 116 | + 'px-4 py-2 rounded-lg transition-colors', |
| 117 | + mode === 'editor' |
| 118 | + ? 'bg-green-500 text-white' |
| 119 | + : 'bg-neutral-200 dark:bg-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-300 dark:hover:bg-neutral-600', |
| 120 | + ]" |
| 121 | + @click="mode = 'editor'" |
| 122 | + > |
| 123 | + Editor Mode |
| 124 | + </button> |
| 125 | + <button |
| 126 | + :class="[ |
| 127 | + 'px-4 py-2 rounded-lg transition-colors', |
| 128 | + mode === 'streaming' |
| 129 | + ? 'bg-green-500 text-white' |
| 130 | + : 'bg-neutral-200 dark:bg-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-300 dark:hover:bg-neutral-600', |
| 131 | + ]" |
| 132 | + @click="mode = 'streaming'" |
| 133 | + > |
| 134 | + Streaming Demo |
| 135 | + </button> |
| 136 | + <label class="flex items-center gap-2 cursor-pointer text-[0.95rem]"> |
| 137 | + <input |
| 138 | + v-model="useCustom" |
| 139 | + type="checkbox" |
| 140 | + class="w-5 h-5 cursor-pointer" |
| 141 | + > |
| 142 | + Use custom components |
| 143 | + </label> |
| 144 | + </div> |
| 145 | + </div> |
| 146 | + |
| 147 | + <div class="flex-1 overflow-hidden px-8 py-6"> |
| 148 | + <!-- Editor Mode --> |
| 149 | + <div |
| 150 | + v-if="mode === 'editor'" |
| 151 | + class="grid grid-cols-1 md:grid-cols-2 gap-6 h-full" |
| 152 | + > |
| 153 | + <div class="flex flex-col min-h-0"> |
| 154 | + <h2 class="mb-3 text-xl text-neutral-800 dark:text-neutral-100"> |
| 155 | + Markdown Input |
| 156 | + </h2> |
| 157 | + <textarea |
| 158 | + v-model="markdown" |
| 159 | + placeholder="Enter markdown here..." |
| 160 | + class="flex-1 w-full p-4 font-mono text-sm leading-relaxed border-2 border-neutral-200 dark:border-neutral-700 rounded-lg resize-none bg-white dark:bg-neutral-800 text-neutral-800 dark:text-neutral-100 focus:outline-none focus:border-green-500 focus:ring-4 focus:ring-green-500/10 overflow-y-auto" |
| 161 | + /> |
| 162 | + </div> |
| 163 | + |
| 164 | + <div class="flex flex-col min-h-0"> |
| 165 | + <h2 class="mb-3 text-xl text-neutral-800 dark:text-neutral-100"> |
| 166 | + Live Preview |
| 167 | + </h2> |
| 168 | + <div class="flex-1 border-2 border-neutral-200 dark:border-neutral-700 rounded-lg p-6 bg-white dark:bg-neutral-800 overflow-y-auto"> |
| 169 | + <div class="leading-relaxed"> |
| 170 | + <MDC |
| 171 | + :markdown="markdown" |
| 172 | + :components="customComponents" |
| 173 | + /> |
| 174 | + </div> |
| 175 | + </div> |
| 176 | + </div> |
| 177 | + </div> |
| 178 | + |
| 179 | + <!-- Streaming Mode --> |
| 180 | + <div |
| 181 | + v-else |
| 182 | + class="h-full flex flex-col space-y-4 overflow-y-auto" |
| 183 | + > |
| 184 | + <div class="flex-shrink-0 bg-green-50 dark:bg-green-900/20 border-l-4 border-green-500 p-4 rounded-r"> |
| 185 | + <h3 class="text-lg font-semibold text-green-900 dark:text-green-100 mb-2"> |
| 186 | + 🔄 Streaming Demo |
| 187 | + </h3> |
| 188 | + <p class="text-green-800 dark:text-green-200 text-sm"> |
| 189 | + Watch as markdown content streams in character-by-character, with automatic handling of incomplete syntax. |
| 190 | + This demonstrates MDC Syntax's unique ability to render partial markdown correctly. |
| 191 | + </p> |
| 192 | + </div> |
| 193 | + |
| 194 | + <div class="flex-1 min-h-0"> |
| 195 | + <StreamingPreview |
| 196 | + :markdown="markdown" |
| 197 | + :chunk-size="10" |
| 198 | + :delay-ms="30" |
| 199 | + :components="customComponents" |
| 200 | + /> |
| 201 | + </div> |
| 202 | + </div> |
| 203 | + </div> |
| 204 | + </div> |
| 205 | + </Suspense> |
| 206 | +</template> |
0 commit comments