Markdown
概述在 Pixi’VN 中使用 Markdown 及其集成,包含 React、Vue、Svelte 和 Angular 的示例。
Markdown 是一种轻量级标记语言,用于通过纯文本编辑器创建格式化文本。 John Gruber 于 2004 年与 Aaron Swartz 合作创建了 Markdown,作为一种在源代码形式下易于阅读的标记语言。 Markdown 被广泛用于博客和即时通讯,也在网络论坛、协作软件、文档页面和 readme 文件中使用。
Pixi’VN 不绑定任何标记语言,赋予开发者选择自己偏好的标记语言的能力。不过,推荐使用 Markdown。
模板
在所有模板中,Markdown 组件已经预先定义。
ink
你可以在 ink 语法中使用此方法。详情请参阅此处。
以下是一些在 JavaScript 生态系统中实现 Markdown 的示例:
// I use the @tanstack/markdown library to convert the Markdown to HTML
// read more about it here: https://www.npmjs.com/package/@tanstack/markdown
// Tables, strikethrough and task lists (GFM) are supported out of the box,
// `allowHtml` enables raw HTML (e.g. <span style="color:blue">...</span>).
import { Markdown } from "@tanstack/markdown/react";
export default function MarkdownComponent({ text }: { text: string }) {
return <Markdown allowHtml>{text}</Markdown>;
}Markdown Typewriter
Markdown Typewriter is a library that combines Markdown and Typewriter. 该库由我创建,旨在满足我在 React 模板的 Markdown 组件中添加打字机效果的需求。
It renders Markdown with @tanstack/markdown and accepts its props. With allowHtml, raw HTML is typed out too, keeping its attributes: <span style="color:blue">...</span> is blue while it appears.
npm install markdown-typewriter motion @tanstack/markdownimport { MarkdownTypewriter } from "markdown-typewriter/react";
export default function MarkdownComponent({ text }: { text: string }) {
return <MarkdownTypewriter allowHtml>{text}</MarkdownTypewriter>;
}