diff --git a/docs/docs/example/Layout.tsx b/docs/docs/example/Layout.tsx
index 617642b21bdff51d6bac9d151b0e3eea87c0ad87..a125b7a79e20bc83d24aa0f1e54b105d516e75e9 100644
--- a/docs/docs/example/Layout.tsx
+++ b/docs/docs/example/Layout.tsx
@@ -1,13 +1,9 @@
import React, { FC } from "react";
import "highlight.js/styles/atom-one-dark.css";
-// @ts-ignore
-import initVal from "./data.raw.txt";
const Layout: FC<{
children: React.ReactNode;
}> = ({ children }) => {
- console.log(initVal);
-
return (
diff --git a/docs/docs/example/data.raw.txt b/docs/docs/example/data.raw.txt
index b213ee8e5f33005cc43330349ee4559caa2f663a..d2cfe82893926ff38c7477f882caeab8b24eba31 100644
--- a/docs/docs/example/data.raw.txt
+++ b/docs/docs/example/data.raw.txt
@@ -1,6 +1,6 @@
-# 介绍
+# Mini Markdown Editor
-## 背景
+## 介绍
Mini Markdown Editor 是 2025年寒假字节青训营「前端」的一个开源项目。
@@ -9,32 +9,43 @@ Mini Markdown Editor 是 2025年寒假字节青训营「前端」的一个开源
该项目采用 `pnpm` + `monorepo` 进行管理,包含两个核心子项目:
- `@mini-markdown-rc/ast-parser`:核心库,实现 Markdown 语法的 AST 解析器,用于解析 Markdown 文本,生成 AST、HTML。
+
- `@mini-markdown-rc/editor`:一款 React 的 Markdown 编辑器。
## 优点
简单易用、轻量、性能高,十万➕内容依然流畅。
-
# 快速开始
## 安装
```bash
+
# npm
+
npm install @mini-markdown-rc/editor
+
# yarn
+
yarn add install @mini-markdown-rc/editor
+
# pnpm
+
pnpm add install @mini-markdown-rc/editor
+
```
## 使用
```tsx
+
import { Editor } from "@mini-markdown-rc/editor";
export default function App() {
+
return ;
+
}
+
```
diff --git a/docs/docs/example/editor.preview.jsx b/docs/docs/example/editor.preview.jsx
index 1f30c935a2bdcba63ab8eeb30b234582affdb537..0513e96ec83b92408df19c267938cb262d2b1d5e 100644
--- a/docs/docs/example/editor.preview.jsx
+++ b/docs/docs/example/editor.preview.jsx
@@ -1,13 +1,14 @@
import { Editor } from "@mini-markdown-rc/editor";
-import { useDark } from "rspress/runtime";
+import { useDark, usePageData } from "rspress/runtime";
export default function () {
const dark = useDark();
const theme = dark ? "dark" : "light";
+ const pageData = usePageData();
return (
<>
-
+
>
);
}
diff --git a/docs/docs/example/index.mdx b/docs/docs/example/index.mdx
index 4b276dca4d2b6637b6dc0a6be4dabc051b473e6d..580e2e69b66c63ffa7e31191b3d04e5816ab6075 100644
--- a/docs/docs/example/index.mdx
+++ b/docs/docs/example/index.mdx
@@ -1,6 +1,7 @@
---
pageType: custom
title: 在线尝试
+initVal: './data.raw.txt'
---
import Layout from "./Layout.tsx";
diff --git a/docs/loader/init-value-loader.js b/docs/loader/init-value-loader.js
new file mode 100644
index 0000000000000000000000000000000000000000..4a326d2a3f4179f755321802bae3163d1a1bd4e8
--- /dev/null
+++ b/docs/loader/init-value-loader.js
@@ -0,0 +1,33 @@
+const path = require("path");
+const fs = require("fs");
+
+/**
+ * 自定义loader,用于将 mdx 文件中自定义源数据( initVal 的值转为某个文件的内容)
+ * 例如:
+ * ---
+ * pageType: custom
+ * initVal: './data.raw.txt'
+ * ---
+ *
+ * 使用:
+ * import { usePageData } from "rspress/runtime";
+ * const pageData = usePageData()
+ * pageData.page.frontmatter.initVal
+ */
+module.exports = function (source) {
+ // 使用正则表达式匹配 initVal 后的内容
+ const initValMatch = source.match(/initVal:\s*['"]([^'"]+)['"]/);
+ if (initValMatch && initValMatch[1]) {
+ const initVal = initValMatch[1].trim();
+ // 获取当前文件的绝对路径 resourcePath(webpack内置的)
+ const currentFilePath = this.resourcePath;
+ // 将相对路径转换为绝对路径
+ const absolutePath = path.resolve(path.dirname(currentFilePath), initVal);
+
+ // 读取文件内容
+ const fileContent = fs.readFileSync(absolutePath, "utf-8");
+ const newSource = source.replace(initValMatch[0], `initVal: '${fileContent}'`);
+ return newSource;
+ }
+ return source;
+};
diff --git a/docs/package.json b/docs/package.json
index 227c2e4ad5394d4969533ebba4b3706a1ef414d8..5782248ef7923c48b2b400a7908d489048561f02 100644
--- a/docs/package.json
+++ b/docs/package.json
@@ -16,7 +16,7 @@
"tailwindcss": "^3.4.17"
},
"dependencies": {
- "@mini-markdown-rc/editor": "latest",
+ "@mini-markdown-rc/editor": "1.0.9",
"antd": "^5.23.2",
"highlight.js": "^11.11.1"
}
diff --git a/docs/rspress.config.ts b/docs/rspress.config.ts
index 9f11027025651f6ba7b2a6e3ed7b652a8d8f1930..2872ffd8b44ff02b2dc7697635dcf8f1bb8982df 100644
--- a/docs/rspress.config.ts
+++ b/docs/rspress.config.ts
@@ -15,8 +15,9 @@ export default defineConfig({
module: {
rules: [
{
- test: /\.raw.txt$/,
- type: "asset/source",
+ enforce: "pre",
+ test: /\.mdx$/,
+ loader: "./loader/init-value-loader.js",
},
],
},