fix: copy of mermaid (#470)
All checks were successful
Build and Deploy / build-and-deploy (push) Has been skipped

Co-authored-by: Libin YANG <szuyanglb@outlook.com>
This commit is contained in:
YangFong 2024-12-13 14:40:41 +08:00 committed by GitHub
parent a62fa1f29b
commit b83968b657
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 67 additions and 115 deletions

View File

@ -131,6 +131,17 @@ $$
Mermaid 是强大的可视化工具,可以在 Markdown 中创建流程图、时序图等。 Mermaid 是强大的可视化工具,可以在 Markdown 中创建流程图、时序图等。
```mermaid
graph LR
A[GraphCommand] --> B[update]
A --> C[goto]
A --> D[send]
B --> B1[更新状态]
C --> C1[流程控制]
D --> D1[消息传递]
```
```mermaid ```mermaid
graph TD; graph TD;
A-->B; A-->B;

View File

@ -126,6 +126,7 @@ function copy() {
.replaceAll(`var(--blockquote-background)`, `#f7f7f7`) .replaceAll(`var(--blockquote-background)`, `#f7f7f7`)
.replaceAll(`var(--md-primary-color)`, primaryColor.value) .replaceAll(`var(--md-primary-color)`, primaryColor.value)
.replaceAll(/--md-primary-color:.+?;/g, ``) .replaceAll(/--md-primary-color:.+?;/g, ``)
.replace(/<span class="nodeLabel"([^>]*)><p[^>]*>(.*?)<\/p><\/span>/g, `<span class="nodeLabel"$1>$2</span>`)
clipboardDiv.focus() clipboardDiv.focus()
@ -137,6 +138,22 @@ function copy() {
p.innerHTML = `&nbsp;` p.innerHTML = `&nbsp;`
clipboardDiv.insertBefore(p, clipboardDiv.firstChild) clipboardDiv.insertBefore(p, clipboardDiv.firstChild)
// Mermaid
const nodes = clipboardDiv.querySelectorAll(`.nodeLabel`)
nodes.forEach((node) => {
const parent = node.parentElement!
const xmlns = parent.getAttribute(`xmlns`)!
const style = parent.getAttribute(`style`)!
const section = document.createElement(`section`)
section.setAttribute(`xmlns`, xmlns)
section.setAttribute(`style`, style)
section.innerHTML = parent.innerHTML
const grand = parent.parentElement!
grand.innerHTML = ``
grand.appendChild(section)
})
window.getSelection()!.removeAllRanges() window.getSelection()!.removeAllRanges()
const range = document.createRange() const range = document.createRange()
@ -183,8 +200,7 @@ function customStyle() {
<MenubarTrigger> 格式 </MenubarTrigger> <MenubarTrigger> 格式 </MenubarTrigger>
<MenubarContent class="w-60" align="start"> <MenubarContent class="w-60" align="start">
<MenubarItem <MenubarItem
v-for="{ label, kbd, emitArgs } in formatItems" v-for="{ label, kbd, emitArgs } in formatItems" :key="label"
:key="label"
@click="emitArgs[0] === 'addFormat' ? $emit(emitArgs[0], emitArgs[1]) : $emit(emitArgs[0])" @click="emitArgs[0] === 'addFormat' ? $emit(emitArgs[0], emitArgs[1]) : $emit(emitArgs[0])"
> >
<el-icon class="mr-2 h-4 w-4" /> <el-icon class="mr-2 h-4 w-4" />
@ -221,14 +237,9 @@ function customStyle() {
<h2>主题</h2> <h2>主题</h2>
<div class="grid grid-cols-3 justify-items-center gap-2"> <div class="grid grid-cols-3 justify-items-center gap-2">
<Button <Button
v-for="{ label, value } in themeOptions" v-for="{ label, value } in themeOptions" :key="value" class="w-full" variant="outline" :class="{
:key="value"
class="w-full"
variant="outline"
:class="{
'border-black dark:border-white': store.theme === value, 'border-black dark:border-white': store.theme === value,
}" }" @click="store.themeChanged(value)"
@click="store.themeChanged(value)"
> >
{{ label }} {{ label }}
</Button> </Button>
@ -238,10 +249,7 @@ function customStyle() {
<h2>字体</h2> <h2>字体</h2>
<div class="grid grid-cols-3 justify-items-center gap-2"> <div class="grid grid-cols-3 justify-items-center gap-2">
<Button <Button
v-for="{ label, value } in fontFamilyOptions" v-for="{ label, value } in fontFamilyOptions" :key="value" variant="outline" class="w-full"
:key="value"
variant="outline"
class="w-full"
:class="{ 'border-black dark:border-white': store.fontFamily === value }" :class="{ 'border-black dark:border-white': store.fontFamily === value }"
@click="store.fontChanged(value)" @click="store.fontChanged(value)"
> >
@ -253,14 +261,9 @@ function customStyle() {
<h2>字号</h2> <h2>字号</h2>
<div class="grid grid-cols-5 justify-items-center gap-2"> <div class="grid grid-cols-5 justify-items-center gap-2">
<Button <Button
v-for="{ value, desc } in fontSizeOptions" v-for="{ value, desc } in fontSizeOptions" :key="value" variant="outline" class="w-full" :class="{
:key="value"
variant="outline"
class="w-full"
:class="{
'border-black dark:border-white': store.fontSize === value, 'border-black dark:border-white': store.fontSize === value,
}" }" @click="store.sizeChanged(value)"
@click="store.sizeChanged(value)"
> >
{{ desc }} {{ desc }}
</Button> </Button>
@ -270,18 +273,12 @@ function customStyle() {
<h2>主题色</h2> <h2>主题色</h2>
<div class="grid grid-cols-3 justify-items-center gap-2"> <div class="grid grid-cols-3 justify-items-center gap-2">
<Button <Button
v-for="{ label, value } in colorOptions" v-for="{ label, value } in colorOptions" :key="value" class="w-full" variant="outline" :class="{
:key="value"
class="w-full"
variant="outline"
:class="{
'border-black dark:border-white': store.primaryColor === value, 'border-black dark:border-white': store.primaryColor === value,
}" }" @click="store.colorChanged(value)"
@click="store.colorChanged(value)"
> >
<span <span
class="mr-2 inline-block h-4 w-4 rounded-full" class="mr-2 inline-block h-4 w-4 rounded-full" :style="{
:style="{
background: value, background: value,
}" }"
/> />
@ -292,30 +289,18 @@ function customStyle() {
<div class="space-y-2"> <div class="space-y-2">
<h2>自定义主题色</h2> <h2>自定义主题色</h2>
<div> <div>
<el-color-picker <el-color-picker v-model="primaryColor" :teleported="false" show-alpha @change="store.colorChanged" />
v-model="primaryColor"
:teleported="false"
show-alpha
@change="store.colorChanged"
/>
</div> </div>
</div> </div>
<div class="space-y-2"> <div class="space-y-2">
<h2>代码块主题</h2> <h2>代码块主题</h2>
<div> <div>
<Select <Select v-model="store.codeBlockTheme" @update:model-value="store.codeBlockThemeChanged">
v-model="store.codeBlockTheme"
@update:model-value="store.codeBlockThemeChanged"
>
<SelectTrigger> <SelectTrigger>
<SelectValue placeholder="Select a fruit" /> <SelectValue placeholder="Select a fruit" />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectItem <SelectItem v-for="{ label, value } in codeBlockThemeOptions" :key="label" :value="value">
v-for="{ label, value } in codeBlockThemeOptions"
:key="label"
:value="value"
>
{{ label }} {{ label }}
</SelectItem> </SelectItem>
</SelectContent> </SelectContent>
@ -326,14 +311,9 @@ function customStyle() {
<h2>图注格式</h2> <h2>图注格式</h2>
<div class="grid grid-cols-3 justify-items-center gap-2"> <div class="grid grid-cols-3 justify-items-center gap-2">
<Button <Button
v-for="{ label, value } in legendOptions" v-for="{ label, value } in legendOptions" :key="value" class="w-full" variant="outline" :class="{
:key="value"
class="w-full"
variant="outline"
:class="{
'border-black dark:border-white': store.legend === value, 'border-black dark:border-white': store.legend === value,
}" }" @click="store.legendChanged(value)"
@click="store.legendChanged(value)"
> >
{{ label }} {{ label }}
</Button> </Button>
@ -344,22 +324,16 @@ function customStyle() {
<h2>Mac 代码块</h2> <h2>Mac 代码块</h2>
<div class="grid grid-cols-5 justify-items-center gap-2"> <div class="grid grid-cols-5 justify-items-center gap-2">
<Button <Button
class="w-full" class="w-full" variant="outline" :class="{
variant="outline"
:class="{
'border-black dark:border-white': store.isMacCodeBlock, 'border-black dark:border-white': store.isMacCodeBlock,
}" }" @click="!store.isMacCodeBlock && store.macCodeBlockChanged()"
@click="!store.isMacCodeBlock && store.macCodeBlockChanged()"
> >
开启 开启
</Button> </Button>
<Button <Button
class="w-full" class="w-full" variant="outline" :class="{
variant="outline"
:class="{
'border-black dark:border-white': !store.isMacCodeBlock, 'border-black dark:border-white': !store.isMacCodeBlock,
}" }" @click="store.isMacCodeBlock && store.macCodeBlockChanged()"
@click="store.isMacCodeBlock && store.macCodeBlockChanged()"
> >
关闭 关闭
</Button> </Button>
@ -369,22 +343,16 @@ function customStyle() {
<h2>微信外链转底部引用</h2> <h2>微信外链转底部引用</h2>
<div class="grid grid-cols-5 justify-items-center gap-2"> <div class="grid grid-cols-5 justify-items-center gap-2">
<Button <Button
class="w-full" class="w-full" variant="outline" :class="{
variant="outline"
:class="{
'border-black dark:border-white': store.isCiteStatus, 'border-black dark:border-white': store.isCiteStatus,
}" }" @click="!store.isCiteStatus && store.citeStatusChanged()"
@click="!store.isCiteStatus && store.citeStatusChanged()"
> >
开启 开启
</Button> </Button>
<Button <Button
class="w-full" class="w-full" variant="outline" :class="{
variant="outline"
:class="{
'border-black dark:border-white': !store.isCiteStatus, 'border-black dark:border-white': !store.isCiteStatus,
}" }" @click="store.isCiteStatus && store.citeStatusChanged()"
@click="store.isCiteStatus && store.citeStatusChanged()"
> >
关闭 关闭
</Button> </Button>
@ -394,22 +362,16 @@ function customStyle() {
<h2>段落首行缩进</h2> <h2>段落首行缩进</h2>
<div class="grid grid-cols-5 justify-items-center gap-2"> <div class="grid grid-cols-5 justify-items-center gap-2">
<Button <Button
class="w-full" class="w-full" variant="outline" :class="{
variant="outline"
:class="{
'border-black dark:border-white': store.isUseIndent, 'border-black dark:border-white': store.isUseIndent,
}" }" @click="!store.isUseIndent && store.useIndentChanged()"
@click="!store.isUseIndent && store.useIndentChanged()"
> >
开启 开启
</Button> </Button>
<Button <Button
class="w-full" class="w-full" variant="outline" :class="{
variant="outline"
:class="{
'border-black dark:border-white': !store.isUseIndent, 'border-black dark:border-white': !store.isUseIndent,
}" }" @click="store.isUseIndent && store.useIndentChanged()"
@click="store.isUseIndent && store.useIndentChanged()"
> >
关闭 关闭
</Button> </Button>
@ -419,22 +381,16 @@ function customStyle() {
<h2>自定义 CSS 面板</h2> <h2>自定义 CSS 面板</h2>
<div class="grid grid-cols-5 justify-items-center gap-2"> <div class="grid grid-cols-5 justify-items-center gap-2">
<Button <Button
class="w-full" class="w-full" variant="outline" :class="{
variant="outline"
:class="{
'border-black dark:border-white': displayStore.isShowCssEditor, 'border-black dark:border-white': displayStore.isShowCssEditor,
}" }" @click="!displayStore.isShowCssEditor && customStyle()"
@click="!displayStore.isShowCssEditor && customStyle()"
> >
开启 开启
</Button> </Button>
<Button <Button
class="w-full" class="w-full" variant="outline" :class="{
variant="outline"
:class="{
'border-black dark:border-white': !displayStore.isShowCssEditor, 'border-black dark:border-white': !displayStore.isShowCssEditor,
}" }" @click="displayStore.isShowCssEditor && customStyle()"
@click="displayStore.isShowCssEditor && customStyle()"
> >
关闭 关闭
</Button> </Button>
@ -444,22 +400,16 @@ function customStyle() {
<h2>编辑区位置</h2> <h2>编辑区位置</h2>
<div class="grid grid-cols-5 justify-items-center gap-2"> <div class="grid grid-cols-5 justify-items-center gap-2">
<Button <Button
class="w-full" class="w-full" variant="outline" :class="{
variant="outline"
:class="{
'border-black dark:border-white': store.isEditOnLeft, 'border-black dark:border-white': store.isEditOnLeft,
}" }" @click="!store.isEditOnLeft && store.toggleEditOnLeft()"
@click="!store.isEditOnLeft && store.toggleEditOnLeft()"
> >
左侧 左侧
</Button> </Button>
<Button <Button
class="w-full" class="w-full" variant="outline" :class="{
variant="outline"
:class="{
'border-black dark:border-white': !store.isEditOnLeft, 'border-black dark:border-white': !store.isEditOnLeft,
}" }" @click="store.isEditOnLeft && store.toggleEditOnLeft()"
@click="store.isEditOnLeft && store.toggleEditOnLeft()"
> >
右侧 右侧
</Button> </Button>
@ -469,22 +419,16 @@ function customStyle() {
<h2>模式</h2> <h2>模式</h2>
<div class="grid grid-cols-5 justify-items-center gap-2"> <div class="grid grid-cols-5 justify-items-center gap-2">
<Button <Button
class="w-full" class="w-full" variant="outline" :class="{
variant="outline"
:class="{
'border-black dark:border-white': !isDark, 'border-black dark:border-white': !isDark,
}" }" @click="store.toggleDark(false)"
@click="store.toggleDark(false)"
> >
<Sun class="h-4 w-4" /> <Sun class="h-4 w-4" />
</Button> </Button>
<Button <Button
class="w-full" class="w-full" variant="outline" :class="{
variant="outline"
:class="{
'border-black dark:border-white': isDark, 'border-black dark:border-white': isDark,
}" }" @click="store.toggleDark(true)"
@click="store.toggleDark(true)"
> >
<Moon class="h-4 w-4" /> <Moon class="h-4 w-4" />
</Button> </Button>
@ -493,10 +437,7 @@ function customStyle() {
<div class="space-y-2"> <div class="space-y-2">
<h2>样式配置</h2> <h2>样式配置</h2>
<div> <div>
<Button <Button class="w-full" @click="store.resetStyleConfirm()">
class="w-full"
@click="store.resetStyleConfirm()"
>
重置 重置
</Button> </Button>
</div> </div>