|
| 1 | +# MDC Syntax |
| 2 | + |
| 3 | +A high-performance markdown parser with MDC (Markdown Components) support. |
| 4 | + |
| 5 | +[](https://www.npmjs.com/package/mdc-syntax) |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- 🚀 Fast markdown-it based parser |
| 10 | +- 📦 Stream API with both buffered and incremental modes |
| 11 | +- ⚡ Incremental parsing for real-time UI updates |
| 12 | +- 🔧 MDC component syntax support |
| 13 | +- 🔒 Auto-close unclosed markdown syntax (perfect for streaming) |
| 14 | +- 📝 Frontmatter parsing (YAML) |
| 15 | +- 📑 Automatic table of contents generation |
| 16 | +- 🎯 Full TypeScript support |
| 17 | +- 📊 Progress tracking built-in for streams |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +```bash |
| 22 | +npm install mdc-syntax |
| 23 | +# or |
| 24 | +pnpm add mdc-syntax |
| 25 | +``` |
| 26 | + |
| 27 | +Then, update your Tailwind `main.css` to include the following so that Tailwind can detect the utility classes used by MDC. |
| 28 | + |
| 29 | +```css |
| 30 | +@source "../node_modules/mdc-syntax/dist/*.mjs"; |
| 31 | +``` |
| 32 | + |
| 33 | +The path must be relative from your CSS file to the node_modules folder containing mdc-syntax. |
| 34 | + |
| 35 | + |
| 36 | +## Usage |
| 37 | + |
| 38 | +### Vue |
| 39 | + |
| 40 | +```vue |
| 41 | +<script setup lang="ts"> |
| 42 | +import { MDC } from 'mdc-syntax/vue' |
| 43 | +import cjkPlugin from '@mdc-syntax/cjk' |
| 44 | +import mathPlugin from '@mdc-syntax/math' |
| 45 | +import { Math } from '@mdc-syntax/math/vue' |
| 46 | +
|
| 47 | +const chatMessage = ... |
| 48 | +</script> |
| 49 | +
|
| 50 | +<template> |
| 51 | + <MDC :markdown="chatMessage" :components="{ Math }" :options="{ plugins: [cjkPlugin, mathPlugin] }" /> |
| 52 | +</template> |
| 53 | +``` |
| 54 | + |
| 55 | +### React |
| 56 | + |
| 57 | +```tsx |
| 58 | +import { MDC } from 'mdc-syntax/react' |
| 59 | +import cjkPlugin from '@mdc-syntax/cjk' |
| 60 | +import mathPlugin from '@mdc-syntax/math' |
| 61 | +import { Math } from '@mdc-syntax/math/react' |
| 62 | + |
| 63 | +function App() { |
| 64 | + const chatMessage = ... |
| 65 | + return <MDC markdown={chatMessage} components={{ Math }} options={{ plugind: [cjkPlugin, mathPlugin] }} /> |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | + |
| 70 | +## License |
| 71 | + |
| 72 | +MIT |
0 commit comments