mirror of
https://github.com/LingChair/LingChair-V0.git
synced 2025-12-07 17:45:49 +08:00
feat: markdown support
This commit is contained in:
@@ -52,3 +52,36 @@ Stickyfill.add($("*").filter((a, b) => $(b).css('position') === 'sticky'))
|
||||
ChatMsgAdapter.initMsgElementEvents()
|
||||
|
||||
ChatMsgAdapter.initInputResizer()
|
||||
|
||||
const showLinkDialog = (link) => mdui.alert(decodeURI(link) + "<br/>如果你确认此链接是安全的, 那么请<a class=\"mdui-text-color-theme-accent\" href=\"" + link + "\">点我</a>", '链接', () => { }, { confirmText: "关闭" })
|
||||
|
||||
const showImageDialog = (link, id, alt) => mdui.alert(`此图片链接来源未知: ${decodeURI(link)}<br/>如果你希望加载, 请<a class="mdui-text-color-theme-accent" mdui-dialog-close onclick="$('#${id}').html('<img src=\\'${link}\\' alt=\\'${decodeURI(alt)}\\'></img>')">点我</a>`, '外部图片', () => { }, { confirmText: "关闭" })
|
||||
|
||||
const renderer = {
|
||||
heading(text, level) {
|
||||
return text
|
||||
},
|
||||
paragraph(text) {
|
||||
return text
|
||||
},
|
||||
blockquote(text) {
|
||||
return text
|
||||
},
|
||||
link(href, title, text) {
|
||||
return `<a class="mdui-text-color-theme-accent" onclick="showLinkDialog('${encodeURI(href)}')">${text}</a>`
|
||||
},
|
||||
image(href, title, text) {
|
||||
let h = Hash.sha256(href)
|
||||
if (new URL(href).hostname === new URL(location.href))
|
||||
return `<img src="${encodeURI(href)}" alt="${text}"></img>`
|
||||
else
|
||||
return `<div id="${h}"><a class="mdui-text-color-theme-accent" onclick="showImageDialog('${encodeURI(href)}', '${h}', '${encodeURI(text)}')">[外部图片] ${text}</a></div>`
|
||||
}
|
||||
}
|
||||
|
||||
marked.use({
|
||||
gfm: true,
|
||||
renderer: renderer,
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -390,16 +390,16 @@ class ChatMsgAdapter {
|
||||
* 添加聊天记录
|
||||
* @param {String} name
|
||||
* @param {String} msg
|
||||
* @param {String} type
|
||||
* @param {String} type
|
||||
* @param {String} 是否加到头部
|
||||
* @param {String or int} 消息id
|
||||
* @param {String || int} 消息id
|
||||
* @returns {jQuery} 消息元素
|
||||
*/
|
||||
static async addMsg(name, m, t, re, msgid) {
|
||||
|
||||
let nick = await NickCache.getNick(name) // re.data == null ? name : re.data.nick
|
||||
|
||||
let msg = escapeHTML(m)
|
||||
let msg = marked.parse(m)
|
||||
|
||||
let temp
|
||||
if (name === localStorage.userName)
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<script src="https://cdn.jsdelivr.net/gh/wilddeer/stickyfill@2.1.0/dist/stickyfill.min.js"></script>
|
||||
<script src="https://unpkg.com/jquery@3.7.1/dist/jquery.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.11/dist/clipboard.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||
<link rel="icon" href="res/icon.ico" />
|
||||
<title>铃之椅</title>
|
||||
</head>
|
||||
|
||||
Reference in New Issue
Block a user