### Install @vunk/markdown (Bash)
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/introduction/+Page.md
This command installs the @vunk/markdown package as a dependency for a project using pnpm. It adds the package to the project's dependencies, ensuring it can be used within the application.
```bash
pnpm install @vunk/markdown -S
```
--------------------------------
### Custom Fence Rendering with Shiki for Syntax Highlighting
Source: https://context7.com/eralchen/vunk-markdown/llms.txt
Illustrates how to customize the rendering of code blocks (fences) using the VkRendererTemplate. This example integrates the Shiki library to provide syntax highlighting for TypeScript code blocks, showcasing the extensibility of @vunk/markdown for rich code presentation.
```vue
```
--------------------------------
### TypeScript: Import VkTemplatesFence Component
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/render-fence/+Page.md
This code snippet shows how to import the `VkTemplatesFence` component from the `@vunk/markdown/components/templates-fence` module using TypeScript. This component provides container rendering strategies for code fences, simplifying the setup for custom fence rendering.
```typescript
import { VkTemplatesFence } from '@vunk/markdown/components/templates-fence'
```
--------------------------------
### Integrate KaTeX Plugin with Markdown-it in Vue
Source: https://context7.com/eralchen/vunk-markdown/llms.txt
Demonstrates how to extend markdown-it with the KaTeX plugin to render mathematical equations within a Vue application. It requires installing `@mdit/plugin-katex` and `katex`.
```vue
```
--------------------------------
### Basic VkMarkdown Component Usage with Streaming
Source: https://context7.com/eralchen/vunk-markdown/llms.txt
Demonstrates the fundamental use of the VkMarkdown component to render Markdown content. It simulates a streaming effect by progressively revealing the text, mimicking real-time output from AI models. This example requires Vue 3 and the @vunk/markdown library.
```vue
```
--------------------------------
### Define Custom Container Rendering Template with VkRendererTemplate Vue Component
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/render-container/+Page.md
This example demonstrates how to define a custom rendering template for a specific container type, in this case, 'warning'. It utilizes the `VkRendererTemplate` component and its default slot, which provides `raw` content and a `Renderer` component. The `raw.children` are passed to the `Renderer` to recursively render the content within the custom warning box.
```vue
⚠️ 警告
```
--------------------------------
### Configure Container Rendering in VkMarkdown Vue Component
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/render-container/+Page.md
This snippet shows how to configure the `VkMarkdown` component to handle custom container types. It specifies an array of container names to be processed and includes a placeholder for where the custom rendering templates would be defined. This setup enables the conversion of specific Markdown container blocks into interactive Vue components.
```vue
```
--------------------------------
### Custom HTML Table Rendering with Vue and Element Plus
Source: https://context7.com/eralchen/vunk-markdown/llms.txt
This example demonstrates intercepting HTML table tags within markdown using VkMarkdown for custom rendering. It utilizes Vue's `defineComponent` and Element Plus components (`ElTable`, `ElTableColumn`) to parse markdown table data into a structured, interactive table. The `VkRendererTemplate` is key for tag interception.
```vue
```
--------------------------------
### Basic Usage of VkMarkdown Component (Vue)
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/introduction/+Page.md
Demonstrates the basic integration of the VkMarkdown component in a Vue 3 application. It shows how to bind Markdown content to the `source` prop and declare custom container types using the `containers` prop. It also illustrates the inclusion of default and container templates.
```vue
```
--------------------------------
### Markdown Parsing and Token Manipulation (JavaScript)
Source: https://context7.com/eralchen/vunk-markdown/llms.txt
Demonstrates the core markdown-it parsing and token manipulation utilities. It covers parsing markdown to tokens, converting tokens to a tree structure for rendering, extracting plain text, and reconstructing flat tokens. No external dependencies are explicitly mentioned for these core functions.
```javascript
const tokens = md.parse(source, {})
console.log('Flat tokens:', tokens.length)
const tree = tokensToTree(tokens, ['table'], ['mermaid'])
console.log('Tree structure:', tree)
const text = tokensToString(tree)
console.log('Plain text:', text)
const flatTokens = treeToTokens(tree)
console.log('Reconstructed tokens:', flatTokens.length)
```
--------------------------------
### Vue Template Rendering Strategy
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/load-templates/+Page.md
Demonstrates how to compose specific templates for rendering within a Vue application. This approach allows selective inclusion of template components like VkTemplatesDefault and VkTemplateMermaid, enabling a custom rendering strategy based on project needs.
```vue
```
--------------------------------
### RendererTemplate Slot Arguments - TypeScript
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/render/+Page.md
Defines the structure of arguments passed to the default slot of the RendererTemplate component. It includes the raw matched data and the Renderer component for rendering nested content.
```typescript
export interface SlotArguments {
/**
* 匹配到的原始数据
*/
raw: SourceItem
/**
* 传递 source: SourceItem[] 可渲染内容
*/
Renderer: Component
}
```
--------------------------------
### Vue: Customize Code Fence Rendering with VkRendererTemplate
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/render-fence/+Page.md
This snippet demonstrates how to use the `VkRendererTemplate` component to customize the rendering of code fences. It targets fences of type `fence:card` and renders them using an Element Plus card component, displaying the fence's info as the header and its content within a pre tag. This allows for dynamic and structured presentation of code blocks.
```vue
{{ raw.content }}
```
--------------------------------
### Vue: Enable and Use VkTemplatesFence for Fences
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/render-fence/+Page.md
This Vue snippet illustrates how to enable and use the `VkTemplatesFence` component within a `VkMarkdown` component. By passing `['mermaid']` to the `fences` attribute of `VkMarkdown`, it specifies that mermaid fences should be processed. The `VkTemplatesFence` component is then included to apply its default rendering strategies to these enabled fences.
```vue
```
--------------------------------
### Custom Container Blocks for Styled Alerts
Source: https://context7.com/eralchen/vunk-markdown/llms.txt
Demonstrates how to define custom container blocks in Markdown using the Container plugin and VkRendererTemplate. This allows for styled alert boxes (warning, info, danger) with custom content and formatting, enhancing the organization and visual appeal of documentation.
```vue
⚠️ {{ raw.info || 'Warning' }}
🚨 Danger
```
--------------------------------
### Import and Use TemplatesContainer for Echarts Rendering Strategy
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/render-container/+Page.md
This code demonstrates how to import and use the `VkTemplatesContainer` component from `@vunk/markdown/components/templates-container`. It shows how to enable the 'echarts' rendering strategy by passing it in the `containers` prop of the `VkMarkdown` component and including the `VkTemplatesContainer` within the `VkMarkdown` component's children.
```javascript
import { VkTemplatesContainer } from '@vunk/markdown/components/templates-container'
```
```vue
```
--------------------------------
### Render Mermaid Diagrams with Streaming and Error Handling using Vue
Source: https://context7.com/eralchen/vunk-markdown/llms.txt
This code snippet shows how to use VkMarkdown to render Mermaid diagrams. It supports streaming content and includes basic error handling implicitly through Mermaid's rendering. The primary dependency is '@vunk/markdown'.
```vue
```
--------------------------------
### GroupToken Interface - TypeScript
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/render/+Page.md
Defines the interface for a GroupToken, which represents nested Markdown structures. It includes the HTML tag name, opening and closing tokens, and an array of child tokens.
```typescript
export interface GroupToken extends __VkRenderer.SourceItem {
tag: string // HTML 标签名(如 'div', 'p', 'blockquote')
open: BasicToken // 开始标签的 Token
close: BasicToken // 结束标签的 Token
children: RendererToken[] // 子元素数组
}
```
--------------------------------
### Convert Markdown Tokens to Tree and Back with @vunk/markdown
Source: https://context7.com/eralchen/vunk-markdown/llms.txt
Provides core utilities for managing markdown tokens, specifically converting between flat token arrays and nested tree structures using `tokensToTree` and `treeToTokens`. It also includes `tokensToString` for converting tokens back into a markdown string. This is essential for advanced markdown manipulation.
```typescript
import { tokensToTree, treeToTokens, tokensToString } from '@vunk/markdown'
import MarkdownIt from 'markdown-it'
const md = new MarkdownIt()
const source = `
```
--------------------------------
### RendererToken Structure for vunk-markdown Parsing
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/parse/+Page.md
Defines the TypeScript interface for a RendererToken, which represents a node in the nested tree structure generated by the parsing module. This structure is used by the renderer to determine how to display content, with 'templateType' dictating the rendering strategy.
```typescript
interface RendererToken {
templateType: string // 渲染模板类型
type?: string // 原始 token 类型
tag?: string // HTML 标签
content?: string // 文本内容
children?: RendererToken[] // 子节点
}
```
--------------------------------
### GroupToken Default Rendering - Vue SFC
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/render/+Page.md
Provides the default rendering logic for GroupToken in Vue SFC using VkRendererTemplate. It dynamically renders an HTML tag with its children, maintaining the structure.
```vue
{{
default: (ctx) => {
const Renderer = ctx.Renderer
const Tag = ctx.raw.tag // 获取标签名
const children = ctx.raw.children // 获取子元素
return (
)
}
}}
```
--------------------------------
### Render ECharts Charts with Streaming Updates using Vue
Source: https://context7.com/eralchen/vunk-markdown/llms.txt
This snippet demonstrates how to use VkMarkdown to render ECharts charts directly from YAML or JSON configuration. It also shows how to simulate streaming data updates to dynamically refresh the chart. Dependencies include '@vunk/markdown' and Vue's reactivity system.
```vue
```
--------------------------------
### Define Custom Renderer Template for Tags
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/render-tag/+Page.md
Use the VkRendererTemplate component to define custom rendering logic for specific tags. The 'type' attribute follows the 'tag:{tagName}' format for matching, and the 'default' slot receives the raw tag content.
```vue
```
--------------------------------
### Extract JSON/YAML from Markdown Tokens with VkResolverJson in Vue
Source: https://context7.com/eralchen/vunk-markdown/llms.txt
Demonstrates the use of `VkResolverJson` from `@vunk/markdown` to extract and parse JSON or YAML content from specific markdown token children. This is useful for embedding configuration blocks, such as those used for charting libraries, directly within markdown.
```vue
Description: {{ description }}
Language: {{ language }}
```
--------------------------------
### Auto-repair Streaming JSON with useJsonrepair in Vue
Source: https://context7.com/eralchen/vunk-markdown/llms.txt
Utilizes the `useJsonrepair` composable from `@vunk-markdown/composables` to automatically fix and parse incomplete or malformed JSON data, commonly encountered in streaming AI responses. It watches for changes in the JSON input and provides the parsed result or an error.
```vue
Streaming JSON:
{{ streamingJson }}
Parsed Result:
Incomplete: {{ error }}
{{ JSON.stringify(json, null, 2) }}
```
--------------------------------
### Configure Custom Tag Rendering in VkMarkdown
Source: https://github.com/eralchen/vunk-markdown/blob/master/docs/pages/zh-CN/guide/render-tag/+Page.md
Specify custom tags for rendering within the VkMarkdown component by using the 'tags' attribute. This allows vunk-markdown to identify and replace specific HTML tags with custom Vue components.
```vue
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.