From fadbbd502dd5c7ea73ed215c2ef19fb9ba0b233e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= Date: Wed, 4 Sep 2024 11:24:07 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fix:=20=E5=AF=B9=E4=BA=8E=E9=85=8D=E7=BD=AE?= =?UTF-8?q?config=20=E7=B1=BB=E5=9E=8B=E7=9A=84=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/.npmrc | 2 +- .../CherryMarkdown/cherry.config.ts | 18 +++++++++++---- types/cherry.d.ts | 23 ++++++++----------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/client/.npmrc b/client/.npmrc index b09af8431..535a03f58 100644 --- a/client/.npmrc +++ b/client/.npmrc @@ -1 +1 @@ -ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/" \ No newline at end of file +electron_mirror=https://npmmirror.com/mirrors/electron/ \ No newline at end of file diff --git a/client/src/components/CherryMarkdown/cherry.config.ts b/client/src/components/CherryMarkdown/cherry.config.ts index 256a3d43f..10bdd8480 100644 --- a/client/src/components/CherryMarkdown/cherry.config.ts +++ b/client/src/components/CherryMarkdown/cherry.config.ts @@ -1,6 +1,6 @@ import { useStoreCherry } from "@/store/storeCherry"; import Cherry from "cherry-markdown"; -import { CherryOptions } from "cherry-markdown/types/cherry"; +import { CherryOptions } from "../../../../types/cherry"; import { ipcRenderer } from "electron"; import { onMounted, shallowReactive } from "vue"; @@ -60,14 +60,14 @@ const initCherryMarkdown = () => { // 对复制内容进行额外处理 return code; }, - onExpandCode: (event, code) => { + onExpandCode: (event: any, code: string) => { // 阻止默认的粘贴事件 // return false; // 对复制内容进行额外处理 // console.log(event, code); return code; }, - onUnExpandCode: (event, code) => { + onUnExpandCode: (event: any, code: string) => { // 阻止默认的粘贴事件 // return false; // 对复制内容进行额外处理 @@ -85,11 +85,19 @@ const initCherryMarkdown = () => { }, }; + type CustomConfig = { + CustomToolbar: { + CustomMenuType: { + customMenu_fileUpload: any + } + } + } /** * 默认配置 */ - const defaultConfig = { + // const defaultConfig: CherryOptions = { + const defaultConfig: CherryOptions = { id: "cherry-markdown", // 第三方包 externals: { @@ -278,7 +286,7 @@ const initCherryMarkdown = () => { }; onMounted(() => { - const cherryInstance = new Cherry(defaultConfig as Partial); + const cherryInstance = new Cherry(defaultConfig); storeCherry.cherry = shallowReactive(cherryInstance) }) } diff --git a/types/cherry.d.ts b/types/cherry.d.ts index 6f6a47039..5fae4a2fa 100644 --- a/types/cherry.d.ts +++ b/types/cherry.d.ts @@ -2,9 +2,8 @@ import CodeMirror from 'codemirror'; import SyntaxBase from '../src/core/SyntaxBase'; import { FormulaMenu } from '@/toolbars/BubbleFormula'; - export interface CherryExternalsOptions { - [key: string]: any; + [key: symbol]: any; } type CherryToolbarsCustomType = { @@ -69,7 +68,7 @@ export interface _CherryOptions void; /** 变更语言时触发 */ - afterChangeLocale?: ( locale: string ) => void; + afterChangeLocale?: (locale: string) => void; /** 变更主题时触发 */ - changeMainTheme?: ( theme: string ) => void; + changeMainTheme?: (theme: string) => void; /** 变更代码块主题时触发 */ - changeCodeBlockTheme?: ( theme: string ) => void; + changeCodeBlockTheme?: (theme: string) => void; }; /** 预览区域配置 */ previewer: CherryPreviewerOptions; @@ -271,10 +270,7 @@ export interface CherryPreviewerOptions { export type CherryToolbarSeparator = '|'; -export type CherryCustomToolbar = string; - export type CherryDefaultToolbar = - // | CherryToolbarSeparator | 'audio' | 'barTable' | 'bold' @@ -390,13 +386,12 @@ export interface CherryToolbarsOptions | CherryDefaultToolbar]?: (keyof F['CustomMenuType'] | CherryDefaultToolbar)[] })[] + { [K in (keyof Partial) | CherryDefaultToolbar]?: (keyof F['CustomMenuType'] | CherryDefaultToolbar)[] })[] | false; toolbarRight?: - | (CherryCustomToolbar | CherryDefaultBubbleToolbar | CherryDefaultToolbar)[] + | (CherryDefaultBubbleToolbar | CherryDefaultToolbar)[] | false; /** 是否展示悬浮目录 */ toc?: false | { @@ -433,7 +428,7 @@ export interface CherryToolbarsOptions Date: Thu, 5 Sep 2024 19:06:52 +0800 Subject: [PATCH 2/6] =?UTF-8?q?chore:=20=E5=B0=86`CherryPreviewerOptions`?= =?UTF-8?q?=E5=8C=85=E5=90=AB=E7=9A=84=E5=AD=97=E6=AE=B5=E8=AE=BE=E4=B8=BA?= =?UTF-8?q?=E5=8F=AF=E9=80=89=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/cherry.d.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/types/cherry.d.ts b/types/cherry.d.ts index 5fae4a2fa..9e0442bd3 100644 --- a/types/cherry.d.ts +++ b/types/cherry.d.ts @@ -240,31 +240,31 @@ export interface CherryEditorOptions { export type CherryLifecycle = (text: string, html: string) => void; export interface CherryPreviewerOptions { - dom: HTMLDivElement | false; + dom?: HTMLDivElement | false; /** 预览区域的DOM className */ - className: string; - enablePreviewerBubble: boolean; - floatWhenClosePreviewer: boolean; + className?: string; + enablePreviewerBubble?: boolean; + floatWhenClosePreviewer?: boolean; // 配置图片懒加载的逻辑 - lazyLoadImg: { + lazyLoadImg?: { // 加载图片时如果需要展示loaing图,则配置loading图的地址 - loadingImgPath: string; + loadingImgPath?: string; // 同一时间最多有几个图片请求,最大同时加载6张图片 - maxNumPerTime: 1 | 2 | 3 | 4 | 5 | 6, + maxNumPerTime?: 1 | 2 | 3 | 4 | 5 | 6, // 不进行懒加载处理的图片数量,如果为0,即所有图片都进行懒加载处理, 如果设置为-1,则所有图片都不进行懒加载处理 - noLoadImgNum: number, + noLoadImgNum?: number, // 首次自动加载几张图片(不论图片是否滚动到视野内),autoLoadImgNum = -1 表示会自动加载完所有图片 - autoLoadImgNum: -1 | number; + autoLoadImgNum?: -1 | number; // 针对加载失败的图片 或 beforeLoadOneImgCallback 返回false 的图片,最多尝试加载几次,为了防止死循环,最多5次。以图片的src为纬度统计重试次数 - maxTryTimesPerSrc: 0 | 1 | 2 | 3 | 4 | 5, + maxTryTimesPerSrc?: 0 | 1 | 2 | 3 | 4 | 5, // 加载一张图片之前的回调函数,函数return false 会终止加载操作 - beforeLoadOneImgCallback: (img: HTMLImageElement) => void | boolean; + beforeLoadOneImgCallback?: (img: HTMLImageElement) => void | boolean; // 加载一张图片失败之后的回调函数 - failLoadOneImgCallback: (img: HTMLImageElement) => void; + failLoadOneImgCallback?: (img: HTMLImageElement) => void; // 加载一张图片之后的回调函数,如果图片加载失败,则不会回调该函数 - afterLoadOneImgCallback: (img: HTMLImageElement) => void; + afterLoadOneImgCallback?: (img: HTMLImageElement) => void; // 加载完所有图片后调用的回调函数 - afterLoadAllImgCallback: () => void; + afterLoadAllImgCallback?: () => void; }; } From 6b327cca8c8b80a37c9c18227bc9f1592f737b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= Date: Fri, 6 Sep 2024 02:57:29 +0800 Subject: [PATCH 3/6] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/cherry.d.ts | 2 +- types/previewer.d.ts | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/types/cherry.d.ts b/types/cherry.d.ts index 9e0442bd3..7a40e2097 100644 --- a/types/cherry.d.ts +++ b/types/cherry.d.ts @@ -272,7 +272,7 @@ export type CherryToolbarSeparator = '|'; export type CherryDefaultToolbar = | 'audio' - | 'barTable' + | 'bar-table' | 'bold' | 'br' | 'checklist' diff --git a/types/previewer.d.ts b/types/previewer.d.ts index 5f6b83531..272b5f68a 100644 --- a/types/previewer.d.ts +++ b/types/previewer.d.ts @@ -30,24 +30,24 @@ export interface PreviewerOptions { floatWhenClosePreviewer?: boolean; $cherry?: Cherry; // 配置图片懒加载的逻辑 - lazyLoadImg: { + lazyLoadImg?: { // 加载图片时如果需要展示loaing图,则配置loading图的地址 - loadingImgPath: string; + loadingImgPath?: string; // 同一时间最多有几个图片请求,最大同时加载6张图片 - maxNumPerTime: 1 | 2 | 3 | 4 | 5 | 6, + maxNumPerTime?: 1 | 2 | 3 | 4 | 5 | 6, // 不进行懒加载处理的图片数量,如果为0,即所有图片都进行懒加载处理, 如果设置为-1,则所有图片都不进行懒加载处理 - noLoadImgNum: number, + noLoadImgNum?: number, // 首次自动加载几张图片(不论图片是否滚动到视野内),autoLoadImgNum = -1 表示会自动加载完所有图片 - autoLoadImgNum: -1 | number; + autoLoadImgNum?: -1 | number; // 针对加载失败的图片 或 beforeLoadOneImgCallback 返回false 的图片,最多尝试加载几次,为了防止死循环,最多5次。以图片的src为纬度统计重试次数 - maxTryTimesPerSrc: 0 | 1 | 2 | 3 | 4 | 5, + maxTryTimesPerSrc?: 0 | 1 | 2 | 3 | 4 | 5, // 加载一张图片之前的回调函数,函数return false 会终止加载操作 - beforeLoadOneImgCallback: (img: HTMLImageElement) => void | boolean; + beforeLoadOneImgCallback?: (img: HTMLImageElement) => void | boolean; // 加载一张图片失败之后的回调函数 - failLoadOneImgCallback: (img: HTMLImageElement) => void; + failLoadOneImgCallback?: (img: HTMLImageElement) => void; // 加载一张图片之后的回调函数,如果图片加载失败,则不会回调该函数 - afterLoadOneImgCallback: (img: HTMLImageElement) => void; + afterLoadOneImgCallback?: (img: HTMLImageElement) => void; // 加载完所有图片后调用的回调函数 - afterLoadAllImgCallback: () => void; + afterLoadAllImgCallback?: () => void; }; } From 766afc287cb7481c1cd6beed8c279554d50bbca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= Date: Fri, 6 Sep 2024 03:17:00 +0800 Subject: [PATCH 4/6] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9CherryDefaultToo?= =?UTF-8?q?lbar=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/cherry.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/cherry.d.ts b/types/cherry.d.ts index 7a40e2097..17b83fdc3 100644 --- a/types/cherry.d.ts +++ b/types/cherry.d.ts @@ -296,7 +296,7 @@ export type CherryDefaultToolbar = | 'insert' | 'italic' | 'justify' - | 'lineTable' + | 'line-table' | 'link' | 'list' | 'mobilePreview' From 2cec64e40d21efecc25a076404070ffe600db7a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= Date: Sun, 8 Sep 2024 19:34:59 +0800 Subject: [PATCH 5/6] chore: remove client's change --- client/.npmrc | 2 +- .../CherryMarkdown/cherry.config.ts | 20 ++++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/client/.npmrc b/client/.npmrc index 535a03f58..b09af8431 100644 --- a/client/.npmrc +++ b/client/.npmrc @@ -1 +1 @@ -electron_mirror=https://npmmirror.com/mirrors/electron/ \ No newline at end of file +ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/" \ No newline at end of file diff --git a/client/src/components/CherryMarkdown/cherry.config.ts b/client/src/components/CherryMarkdown/cherry.config.ts index 10bdd8480..98e711639 100644 --- a/client/src/components/CherryMarkdown/cherry.config.ts +++ b/client/src/components/CherryMarkdown/cherry.config.ts @@ -1,6 +1,6 @@ import { useStoreCherry } from "@/store/storeCherry"; import Cherry from "cherry-markdown"; -import { CherryOptions } from "../../../../types/cherry"; +import { CherryOptions } from "cherry-markdown/types/cherry"; import { ipcRenderer } from "electron"; import { onMounted, shallowReactive } from "vue"; @@ -60,14 +60,14 @@ const initCherryMarkdown = () => { // 对复制内容进行额外处理 return code; }, - onExpandCode: (event: any, code: string) => { + onExpandCode: (event, code) => { // 阻止默认的粘贴事件 // return false; // 对复制内容进行额外处理 // console.log(event, code); return code; }, - onUnExpandCode: (event: any, code: string) => { + onUnExpandCode: (event, code) => { // 阻止默认的粘贴事件 // return false; // 对复制内容进行额外处理 @@ -85,19 +85,11 @@ const initCherryMarkdown = () => { }, }; - type CustomConfig = { - CustomToolbar: { - CustomMenuType: { - customMenu_fileUpload: any - } - } - } /** * 默认配置 */ - // const defaultConfig: CherryOptions = { - const defaultConfig: CherryOptions = { + const defaultConfig = { id: "cherry-markdown", // 第三方包 externals: { @@ -286,9 +278,9 @@ const initCherryMarkdown = () => { }; onMounted(() => { - const cherryInstance = new Cherry(defaultConfig); + const cherryInstance = new Cherry(defaultConfig as Partial); storeCherry.cherry = shallowReactive(cherryInstance) }) } -export default initCherryMarkdown; +export default initCherryMarkdown; \ No newline at end of file From f6e15344cfa74db6b68b3fb75bd9b41514afe2d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= Date: Sun, 8 Sep 2024 20:33:38 +0800 Subject: [PATCH 6/6] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0`syntax`=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/cherry.d.ts | 128 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 1 deletion(-) diff --git a/types/cherry.d.ts b/types/cherry.d.ts index 17b83fdc3..a018fd6ee 100644 --- a/types/cherry.d.ts +++ b/types/cherry.d.ts @@ -195,7 +195,133 @@ export interface CherryEngineOptions { flowSessionContext?: boolean; }; /** 内置语法配置 */ - syntax?: Record | false>; + syntax?: { + // 语法开关 + // 'hookName': false, + // 语法配置 + // 'hookName': { + // + // } + link?: { + /** 生成的标签追加target属性的默认值 空:在标签里不会追加target属性, _blank:在标签里追加target="_blank"属性 */ + target?: '_blank' | '', + /** 生成的标签追加rel属性的默认值 空:在标签里不会追加rel属性, nofollow:在标签里追加rel="nofollow:在"属性*/ + rel?: '_blank' | 'nofollow' | '', + }, + autoLink?: { + /** 生成的标签追加target属性的默认值 空:在标签里不会追加target属性, _blank:在标签里追加target="_blank"属性 */ + target?: '_blank' | '', + /** 生成的标签追加rel属性的默认值 空:在标签里不会追加rel属性, nofollow:在标签里追加rel="nofollow:在"属性*/ + rel?: '_blank' | 'nofollow' | '', + /** 是否开启短链接 默认:true */ + enableShortLink?: boolean, + /** 短链接长度 默认:20 */ + shortLinkLength?: number, + }, + list?: { + listNested?: boolean, // 同级列表类型转换后变为子级 + indentSpace?: number, // 默认2个空格缩进 + }, + table: { + enableChart?: boolean, + selfClosing?: boolean, // 自动闭合,为true时,当输入第一行table内容时,cherry会自动按表格进行解析 + // chartRenderEngine: EChartsTableEngine, + // externals: ['echarts'], + }, + inlineCode?: { + /** + * @deprecated 不再支持theme的配置,统一在`themeSettings.inlineCodeTheme`中配置 + */ + // theme: 'red', + }, + codeBlock?: { + /** + * @deprecated 不再支持theme的配置,统一在`themeSettings.codeBlockTheme`中配置 + */ + // theme: 'dark', // 默认为深色主题 + wrap?: boolean, // 超出长度是否换行,false则显示滚动条 + lineNumber?: boolean, // 默认显示行号 + copyCode?: boolean, // 是否显示“复制”按钮 + editCode?: boolean, // 是否显示“编辑”按钮 + changeLang?: boolean, // 是否显示“切换语言”按钮 + expandCode?: boolean, // 是否展开/收起代码块,当代码块行数大于10行时,会自动收起代码块 + selfClosing?: boolean, // 自动闭合,为true时,当md中有奇数个```时,会自动在md末尾追加一个``` + customRenderer?: { + // 自定义语法渲染器 + }, + mermaid?: { + svg2img?: boolean, // 是否将mermaid生成的画图变成img格式 + }, + /** + * indentedCodeBlock是缩进代码块是否启用的开关 + * + * 在6.X之前的版本中默认不支持该语法。 + * 因为cherry的开发团队认为该语法太丑了(容易误触) + * 开发团队希望用```代码块语法来彻底取代该语法 + * 但在后续的沟通中,开发团队发现在某些场景下该语法有更好的显示效果 + * 因此开发团队在6.X版本中才引入了该语法 + * 已经引用6.x以下版本的业务如果想做到用户无感知升级,可以去掉该语法: + * indentedCodeBlock:false + */ + indentedCodeBlock?: boolean, + }, + emoji?: { + useUnicode?: boolean, // 是否使用unicode进行渲染 + }, + fontEmphasis?: { + /** + * 是否允许首尾空格 + * 首尾、前后的定义: 语法前**语法首+内容+语法尾**语法后 + * 例: + * true: + * __ hello __ ====> hello + * __hello__ ====> hello + * false: + * __ hello __ ====> _ hello _ + * __hello__ ====> hello + */ + allowWhitespace?: boolean, + selfClosing?: boolean, // 自动闭合,为true时,当输入**XXX时,会自动在末尾追加** + }, + strikethrough?: { + /** + * 是否必须有前后空格 + * 首尾、前后的定义: 语法前**语法首+内容+语法尾**语法后 + * 例: + * true: + * hello wor~~l~~d ====> hello wor~~l~~d + * hello wor ~~l~~ d ====> hello wor l d + * false: + * hello wor~~l~~d ====> hello world + * hello wor ~~l~~ d ====> hello wor l d + */ + needWhitespace?: boolean, + }, + mathBlock?: { + engine?: 'katex' | 'MathJax', // katex或MathJax + src?: string, + plugins?: boolean, // 加载插件 + }, + inlineMath?: { + engine?: 'katex' | 'MathJax', // katex或MathJax + src?: string, + }, + toc?: { + /** 默认只渲染一个目录 */ + allowMultiToc?: boolean, + /** 是否显示自增序号 */ + showAutoNumber?: boolean, + }, + header?: { + /** + * 标题的样式: + * - default 默认样式,标题前面有锚点 + * - autonumber 标题前面有自增序号锚点 + * - none 标题没有锚点 + */ + anchorStyle?: 'default' | 'autonumber' | 'none', + }, + }; /** 自定义语法 */ customSyntax?: Record; }