mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-18 01:06:39 +08:00
opt: optimize markdown image parser, identify image and blockquote tags
This commit is contained in:
parent
39fdfae541
commit
861f11af66
@ -102,6 +102,13 @@ export default defineComponent({
|
|||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
|
||||||
|
img {
|
||||||
|
max-width: 600px;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin 10px 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color #20a0ff
|
color #20a0ff
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@ import {ref} from "vue";
|
|||||||
import {ElMessage} from "element-plus";
|
import {ElMessage} from "element-plus";
|
||||||
import {httpGet, httpPost} from "@/utils/http";
|
import {httpGet, httpPost} from "@/utils/http";
|
||||||
import {PictureFilled, Plus} from "@element-plus/icons-vue";
|
import {PictureFilled, Plus} from "@element-plus/icons-vue";
|
||||||
|
import {isImage} from "@/utils/libs";
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
userId: String,
|
userId: String,
|
||||||
@ -69,11 +70,6 @@ const fetchFiles = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const isImage = (ext) => {
|
|
||||||
const expr = /\.(jpg|jpeg|png|gif|bmp|svg)$/i;
|
|
||||||
return expr.test(ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
const getFileIcon = (ext) => {
|
const getFileIcon = (ext) => {
|
||||||
const files = {
|
const files = {
|
||||||
".docx": "doc.png",
|
".docx": "doc.png",
|
||||||
|
@ -161,3 +161,8 @@ export function substr(str, length) {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isImage(url) {
|
||||||
|
const expr = /\.(jpg|jpeg|png|gif|bmp|svg)$/i;
|
||||||
|
return expr.test(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ import {
|
|||||||
VideoPause
|
VideoPause
|
||||||
} from '@element-plus/icons-vue'
|
} from '@element-plus/icons-vue'
|
||||||
import 'highlight.js/styles/a11y-dark.css'
|
import 'highlight.js/styles/a11y-dark.css'
|
||||||
import {dateFormat, isMobile, randString, removeArrayItem, UUID} from "@/utils/libs";
|
import {dateFormat, isImage, isMobile, randString, removeArrayItem, UUID} from "@/utils/libs";
|
||||||
import {ElMessage, ElMessageBox} from "element-plus";
|
import {ElMessage, ElMessageBox} from "element-plus";
|
||||||
import hl from "highlight.js";
|
import hl from "highlight.js";
|
||||||
import {getSessionId, getUserToken, removeUserToken} from "@/store/session";
|
import {getSessionId, getUserToken, removeUserToken} from "@/store/session";
|
||||||
@ -636,7 +636,7 @@ const connect = function (chat_id, role_id) {
|
|||||||
lineBuffer.value += data.content;
|
lineBuffer.value += data.content;
|
||||||
const reply = chatData.value[chatData.value.length - 1]
|
const reply = chatData.value[chatData.value.length - 1]
|
||||||
reply['orgContent'] = lineBuffer.value;
|
reply['orgContent'] = lineBuffer.value;
|
||||||
reply['content'] = md.render(processBlankQuote(lineBuffer.value));
|
reply['content'] = md.render(processContent(lineBuffer.value));
|
||||||
}
|
}
|
||||||
// 将聊天框的滚动条滑动到最底部
|
// 将聊天框的滚动条滑动到最底部
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
@ -712,7 +712,7 @@ const sendMessage = function () {
|
|||||||
type: "prompt",
|
type: "prompt",
|
||||||
id: randString(32),
|
id: randString(32),
|
||||||
icon: loginUser.value.avatar,
|
icon: loginUser.value.avatar,
|
||||||
content: md.render(prompt.value),
|
content: md.render(processContent(prompt.value)),
|
||||||
created_at: new Date().getTime(),
|
created_at: new Date().getTime(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -778,7 +778,7 @@ const loadChatHistory = function (chatId) {
|
|||||||
showHello.value = false
|
showHello.value = false
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
data[i].orgContent = data[i].content;
|
data[i].orgContent = data[i].content;
|
||||||
data[i].content = md.render(processBlankQuote(data[i].content))
|
data[i].content = md.render(processContent(data[i].content))
|
||||||
chatData.value.push(data[i]);
|
chatData.value.push(data[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -792,7 +792,22 @@ const loadChatHistory = function (chatId) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const processBlankQuote = (content) => {
|
const processContent = (content) => {
|
||||||
|
//process img url
|
||||||
|
const linkRegex = /(https?:\/\/\S+)/g;
|
||||||
|
const links = content.match(linkRegex);
|
||||||
|
if (links) {
|
||||||
|
for (let link of links) {
|
||||||
|
if (isImage(link)) {
|
||||||
|
const index = content.indexOf(link)
|
||||||
|
if (content.substring(index - 1, 2) !== "]") {
|
||||||
|
content = content.replace(link, "\n\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理引用块
|
||||||
if (content.indexOf("\n") === -1) {
|
if (content.indexOf("\n") === -1) {
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user