Skip to content

Commit 9eee203

Browse files
committed
feat: Supports Markdown preview
1 parent 762d1dc commit 9eee203

File tree

6 files changed

+43
-12
lines changed

6 files changed

+43
-12
lines changed

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@codemirror/lang-yaml": "^6.1.1",
2020
"@codemirror/theme-one-dark": "^6.1.2",
2121
"codemirror": "6.0.1",
22+
"marked": "^14.1.2",
2223
"pinia": "^2.2.2",
2324
"vue": "^3.5.6",
2425
"vue-codemirror6": "^1.3.4",

frontend/pnpm-lock.yaml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/components/CodeViewer/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const props = withDefaults(defineProps<Props>(), {
2626
const ready = ref(false)
2727
const appSettings = useAppSettingsStore()
2828
29-
const lang = { json, javascript, yaml }[props.lang]()
29+
const lang = { json, javascript, yaml }[props.lang]?.()
3030
const linter = props.lang === 'json' ? jsonParseLinter() : undefined
3131
3232
const completion = computed(() =>

frontend/src/components/Confirm/index.vue

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
<script setup lang="ts">
2+
import { computed } from 'vue'
3+
import { marked } from 'marked'
4+
25
import useI18n from '@/lang'
36
7+
export type Options = {
8+
type: 'text' | 'markdown'
9+
}
10+
411
interface Props {
512
title: string
613
message: string | Record<string, any>
14+
options?: Options
715
cancel?: boolean
816
}
917
10-
const props = withDefaults(defineProps<Props>(), { cancel: true })
18+
const props = withDefaults(defineProps<Props>(), {
19+
cancel: true,
20+
options: () => ({ type: 'text' })
21+
})
1122
1223
const emits = defineEmits(['confirm', 'cancel', 'finish'])
1324
@@ -23,19 +34,22 @@ const handleCancel = () => {
2334
emits('finish')
2435
}
2536
26-
const getMessage = () => {
27-
if (typeof props.message === 'string') {
37+
const message = computed(() => {
38+
if (typeof props.message !== 'string') {
39+
return props.message
40+
}
41+
if (props.options.type === 'text') {
2842
return t(props.message)
2943
}
30-
return props.message
31-
}
44+
return marked.use().parse(props.message)
45+
})
3246
</script>
3347

3448
<template>
3549
<Transition name="slide-down" appear>
3650
<div class="confirm">
3751
<div class="title">{{ t(title) }}</div>
38-
<div class="message select-text">{{ getMessage() }}</div>
52+
<div class="message select-text" v-html="message"></div>
3953
<div class="form-action">
4054
<Button v-if="cancel" @click="handleCancel" size="small">{{ t('common.cancel') }}</Button>
4155
<Button @click="handleConfirm" size="small" type="primary">
@@ -54,6 +68,8 @@ const getMessage = () => {
5468
background: var(--toast-bg);
5569
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
5670
border-radius: 4px;
71+
display: flex;
72+
flex-direction: column;
5773
5874
.title {
5975
font-weight: bold;
@@ -66,8 +82,8 @@ const getMessage = () => {
6682
padding: 6px;
6783
word-break: break-all;
6884
white-space: pre-wrap;
69-
max-height: 300px;
7085
overflow-y: auto;
86+
flex: 1;
7187
}
7288
}
7389
</style>

frontend/src/hooks/useAlert.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { render, createVNode } from 'vue'
22

3-
import ConfirmComp from '@/components/Confirm/index.vue'
3+
import ConfirmComp, { type Options } from '@/components/Confirm/index.vue'
44

5-
const createAlert = (title: string, message: string) => {
5+
const createAlert = (title: string, message: string, options: Partial<Options> = {}) => {
66
return new Promise((resolve) => {
77
const dom = document.createElement('div')
88
dom.style.cssText = `
@@ -13,10 +13,12 @@ const createAlert = (title: string, message: string) => {
1313
right: 0;
1414
display: flex;
1515
justify-content: center;
16+
max-height: 70%;
1617
`
1718
const vnode = createVNode(ConfirmComp, {
1819
title,
1920
message,
21+
options,
2022
cancel: false,
2123
onConfirm: resolve,
2224
onFinish: () => {

frontend/src/hooks/useConfirm.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { render, createVNode } from 'vue'
22

3-
import ConfirmComp from '@/components/Confirm/index.vue'
3+
import ConfirmComp, { type Options } from '@/components/Confirm/index.vue'
44

5-
const createConfirm = (title: string, message: string) => {
5+
const createConfirm = (title: string, message: string, options: Partial<Options> = {}) => {
66
return new Promise((resolve, reject) => {
77
const dom = document.createElement('div')
88
dom.style.cssText = `
@@ -13,10 +13,12 @@ const createConfirm = (title: string, message: string) => {
1313
right: 0;
1414
display: flex;
1515
justify-content: center;
16+
max-height: 70%;
1617
`
1718
const vnode = createVNode(ConfirmComp, {
1819
title,
1920
message,
21+
options,
2022
onConfirm: resolve,
2123
onCancel: () => reject('cancelled'),
2224
onFinish: () => {

0 commit comments

Comments
 (0)