mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 11:19:56 +00:00
perf: 自动识别md格式发送
This commit is contained in:
parent
3596475790
commit
0e5b44baad
@ -156,7 +156,11 @@
|
||||
</div>
|
||||
<div class="chat-input-popover-item" @click="onSend('md')">
|
||||
<i class="taskfont"></i>
|
||||
{{$L('Markdown 格式发送')}}
|
||||
{{$L('MD 格式发送')}}
|
||||
</div>
|
||||
<div class="chat-input-popover-item" @click="onSend('normal')">
|
||||
<i class="taskfont"></i>
|
||||
{{$L('正常发送')}}
|
||||
</div>
|
||||
</EPopover>
|
||||
</li>
|
||||
@ -214,6 +218,7 @@ import touchmouse from "../../../../directives/touchmouse";
|
||||
import TransferDom from "../../../../directives/transfer-dom";
|
||||
import clickoutside from "../../../../directives/clickoutside";
|
||||
import longpress from "../../../../directives/longpress";
|
||||
import {isMarkdownFormat} from "../../../../store/markdown";
|
||||
import {Store} from "le5le-store";
|
||||
|
||||
export default {
|
||||
@ -356,6 +361,7 @@ export default {
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.quill) {
|
||||
this.quill.getModule("mention")?.hideMentionList();
|
||||
this.quill = null
|
||||
}
|
||||
if (this.recordRec) {
|
||||
@ -1036,7 +1042,7 @@ export default {
|
||||
this.showMenu = true;
|
||||
},
|
||||
|
||||
onSend(type) {
|
||||
onSend(type = 'auto') {
|
||||
this.emojiTimer && clearTimeout(this.emojiTimer)
|
||||
this.emojiQuickShow = false;
|
||||
//
|
||||
@ -1047,6 +1053,13 @@ export default {
|
||||
this.hidePopover('send')
|
||||
this.rangeIndex = 0
|
||||
this.clearSearchKey()
|
||||
//
|
||||
if (type === 'auto') {
|
||||
type = isMarkdownFormat(this.value) ? 'md' : ''
|
||||
}
|
||||
if (type === 'normal') {
|
||||
type = ''
|
||||
}
|
||||
if (type) {
|
||||
this.$emit('on-send', null, type)
|
||||
} else {
|
||||
@ -1286,7 +1299,7 @@ export default {
|
||||
if (this.userId === data.userid || this.quoteData.userid !== data.userid) {
|
||||
return
|
||||
}
|
||||
if (new RegExp(`<span[^>]*?class="mention"[^>]*?data-id="${data.userid}"[^>]*?>`).test(this.$refs.editor.firstChild.innerHTML)) {
|
||||
if (new RegExp(`<span[^>]+?class="mention"[^>]+?data-id="${data.userid}"[^>]*?>`).test(this.$refs.editor.firstChild.innerHTML)) {
|
||||
return
|
||||
}
|
||||
this.addMention({
|
||||
|
||||
29
resources/assets/js/store/markdown.js
vendored
29
resources/assets/js/store/markdown.js
vendored
@ -51,3 +51,32 @@ export function MarkdownPreview(text) {
|
||||
}
|
||||
return MarkdownUtils.mds.render(text)
|
||||
}
|
||||
|
||||
export function isMarkdownFormat(html) {
|
||||
if (html === '') {
|
||||
return false
|
||||
}
|
||||
if (/<\/(strong|s|em|u|ol|ul|li|blockquote|pre|img|a)>/i.test(html)) {
|
||||
return false
|
||||
}
|
||||
if (/<span[^>]+?class="mention"[^>]*?>/i.test(html)) {
|
||||
return false
|
||||
}
|
||||
//
|
||||
const text = html.replace(/<[^>]+?>/g, '')
|
||||
if (
|
||||
/(^|\s+)#+\s(.*)$/m.test(text) // 标题
|
||||
|| /\*\*(.*)\*\*/m.test(text) // 粗体
|
||||
|| /__(.*)__/m.test(text) // 粗体
|
||||
|| /\*(.*)\*/m.test(text) // 斜体
|
||||
|| /_(.*)_/m.test(text) // 斜体
|
||||
|| /~~(.*)~~/m.test(text) // 删除线
|
||||
|| /\[(.*?)\]\((.*?)\)/m.test(text) // 链接
|
||||
|| /!\[(.*?)\]\((.*?)\)/m.test(text) // 图片
|
||||
|| /`(.*?)`/m.test(text) // 行内代码
|
||||
|| /```([\s\S]*?)```/m.test(text) // 代码块
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user