diff --git a/package.json b/package.json index c8dab2b8..f7f7882c 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@form-create/designer": "^3.1.3", "@form-create/element-ui": "^3.1.24", "@iconify/iconify": "^3.1.1", + "@iktakahiro/markdown-it-katex": "^4.0.1", "@microsoft/fetch-event-source": "^2.0.1", "@videojs-player/vue": "^1.0.0", "@vueuse/core": "^10.9.0", @@ -52,7 +53,7 @@ "highlight.js": "^11.9.0", "jsencrypt": "^3.3.2", "lodash-es": "^4.17.21", - "marked": "^12.0.2", + "markdown-it": "^14.1.0", "min-dash": "^4.1.1", "mitt": "^3.0.1", "nprogress": "^0.2.0", diff --git a/src/assets/ai/copy-style2.svg b/src/assets/ai/copy-style2.svg new file mode 100644 index 00000000..2d56a87f --- /dev/null +++ b/src/assets/ai/copy-style2.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/MdPreview/copy.ts b/src/components/MdPreview/copy.ts new file mode 100644 index 00000000..e2f53bc2 --- /dev/null +++ b/src/components/MdPreview/copy.ts @@ -0,0 +1,22 @@ +export const copyText = (content: string) => {//复制 + // content = content.replace(/^\s/,'') + navigator.clipboard.writeText(content).then(function () { + ElMessage({ + message: '复制成功!', + type: 'success', + }) + }).catch(function () { + (function (content) { + document.oncopy = function (e) { + e.clipboardData?.setData('text', content); + e.preventDefault(); + document.oncopy = null; + ElMessage({ + message: '复制成功!', + type: 'success', + }) + }; + })(content); + document.execCommand('copy'); + }); +}; diff --git a/src/components/MdPreview/index.vue b/src/components/MdPreview/index.vue new file mode 100644 index 00000000..882d59e4 --- /dev/null +++ b/src/components/MdPreview/index.vue @@ -0,0 +1,225 @@ + + + + + diff --git a/src/components/MdPreview/md.ts b/src/components/MdPreview/md.ts new file mode 100644 index 00000000..81aa7b65 --- /dev/null +++ b/src/components/MdPreview/md.ts @@ -0,0 +1,30 @@ + +// @ts-ignore +import markdownit from 'markdown-it'; +import hljs from 'highlight.js'; // https://highlightjs.org +import katexPlugin from '@iktakahiro/markdown-it-katex'; +const codeTool = (text: string) => ``; + +const md = markdownit({ + html: true, + linkfy: true, + highlight: function (str: string, lang: string) { + const baseText = str + if (lang && hljs.getLanguage(lang)) { + try { + return '
' +
+                    hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
+                    '' + codeTool(baseText) + '
'; + } catch (__) { } + } + return '
' + md.utils.escapeHtml(str) + '' + codeTool(baseText) + '
'; + } +}); + +md.use(katexPlugin); + +export default md; diff --git a/src/views/ai/chat/index.vue b/src/views/ai/chat/index.vue index 2e5cead6..317f6838 100644 --- a/src/views/ai/chat/index.vue +++ b/src/views/ai/chat/index.vue @@ -98,11 +98,12 @@ {{formatDate(item.createTime)}}
-
+ +
- + 复制
@@ -124,7 +125,7 @@ {{formatDate(item.createTime)}}
-
+
{{item.content}}
@@ -161,21 +162,30 @@