From e0ec5efff480f43f44c78b1e55b508f381d80843 Mon Sep 17 00:00:00 2001 From: Triumph-light <2495685883@qq.com> Date: Sat, 19 Jul 2025 23:21:36 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=80=BC=E6=A0=BC=E5=BC=8F=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=EF=BC=8C=E5=AF=BC=E8=87=B4=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E5=A5=87=E6=80=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/compiler/compile-src-code-md.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/website-build/src/compiler/compile-src-code-md.ts b/packages/website-build/src/compiler/compile-src-code-md.ts index 86f4833..61fc6cf 100644 --- a/packages/website-build/src/compiler/compile-src-code-md.ts +++ b/packages/website-build/src/compiler/compile-src-code-md.ts @@ -9,6 +9,24 @@ import { parser } from '@mpxjs/vuese-parser' import { Render } from '@mpxjs/vuese-markdown-render' import { renderOptions } from '../common/options.js' +/** + * 将字符串的对象转为可读的markdown格式 + * @param str + * @returns + */ +function convertObjectStringToMarkdownHtml(str) { + if (!str) return + return ( + '
' +
+    str
+      .trim()
+      .split('\n')
+      .map(line => line.replace(//g, '>')) // 防止HTML标签注入
+      .join('
') + + '
' + ) +} + /** * 解析 cube-ui src 文件夹下的组件,生成md文档 * @@ -44,6 +62,9 @@ const genSrcCodeMd = function (srcDir: string, component: string, fnMixins) { item.type = item.type.replace(/\n/g, '
') item.type = item.type.replace(new RegExp(optionalMark, 'g'), '?') }) + text.props?.forEach(item => { + item.default = convertObjectStringToMarkdownHtml(item.default) + }) const render = new Render(text, Object.assign({ name: component } as any, renderOptions)) From fe79d1f4278adbb89b36b5577ce08abe06d39cd8 Mon Sep 17 00:00:00 2001 From: Triumph-light <2495685883@qq.com> Date: Mon, 21 Jul 2025 22:52:45 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E4=BC=98=E5=8C=96=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../website-build/src/compiler/compile-src-code-md.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/website-build/src/compiler/compile-src-code-md.ts b/packages/website-build/src/compiler/compile-src-code-md.ts index 61fc6cf..5cfa889 100644 --- a/packages/website-build/src/compiler/compile-src-code-md.ts +++ b/packages/website-build/src/compiler/compile-src-code-md.ts @@ -19,9 +19,14 @@ function convertObjectStringToMarkdownHtml(str) { return ( '
' +
     str
-      .trim()
       .split('\n')
-      .map(line => line.replace(//g, '>')) // 防止HTML标签注入
+      .map((line, idx) => {
+        line = line.replace(/\s+/g, '').replace(//g, '>')
+        if (idx !== 0 && idx !== str.split('\n').length - 1) {
+          line = '  ' + line
+        }
+        return line
+      }) // 防止HTML标签注入
       .join('
') + '
' ) From 12a48c1d043f6044602f87531e26afc6a75819eb Mon Sep 17 00:00:00 2001 From: Triumph-light <2495685883@qq.com> Date: Thu, 24 Jul 2025 15:47:59 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=B5=8C?= =?UTF-8?q?=E5=A5=97=E5=AF=B9=E8=B1=A1=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../website-build/src/compiler/compile-src-code-md.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/website-build/src/compiler/compile-src-code-md.ts b/packages/website-build/src/compiler/compile-src-code-md.ts index 5cfa889..d925c1c 100644 --- a/packages/website-build/src/compiler/compile-src-code-md.ts +++ b/packages/website-build/src/compiler/compile-src-code-md.ts @@ -14,16 +14,16 @@ import { renderOptions } from '../common/options.js' * @param str * @returns */ -function convertObjectStringToMarkdownHtml(str) { +export function convertObjectStringToMarkdownHtml(str) { if (!str) return return ( '
' +
     str
       .split('\n')
       .map((line, idx) => {
-        line = line.replace(/\s+/g, '').replace(//g, '>')
-        if (idx !== 0 && idx !== str.split('\n').length - 1) {
-          line = '  ' + line
+        // 第一行和最后一行是{},将括号的前后空白字符去除,只保留属性的
+        if (!(idx !== 0 && idx !== str.split('\n').length - 1)) {
+          line = line.replace(/\s+/g, '').replace(//g, '>')
         }
         return line
       }) // 防止HTML标签注入