From a39973bb5c117240b44bad9c92bb142e558922e9 Mon Sep 17 00:00:00 2001 From: MoonLeeeaf <150461955+MoonLeeeaf@users.noreply.github.com> Date: Tue, 11 Jun 2024 22:03:41 +0800 Subject: [PATCH] feat: markdown support --- ling_chair_http/finally.js | 33 +++++++++++++++++++++++++++++++++ ling_chair_http/handler.js | 6 +++--- ling_chair_http/index.html | 1 + 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/ling_chair_http/finally.js b/ling_chair_http/finally.js index adeab88..28c4d57 100644 --- a/ling_chair_http/finally.js +++ b/ling_chair_http/finally.js @@ -52,3 +52,36 @@ Stickyfill.add($("*").filter((a, b) => $(b).css('position') === 'sticky')) ChatMsgAdapter.initMsgElementEvents() ChatMsgAdapter.initInputResizer() + +const showLinkDialog = (link) => mdui.alert(decodeURI(link) + "
如果你确认此链接是安全的, 那么请点我", '链接', () => { }, { confirmText: "关闭" }) + +const showImageDialog = (link, id, alt) => mdui.alert(`此图片链接来源未知: ${decodeURI(link)}
如果你希望加载, 请点我`, '外部图片', () => { }, { confirmText: "关闭" }) + +const renderer = { + heading(text, level) { + return text + }, + paragraph(text) { + return text + }, + blockquote(text) { + return text + }, + link(href, title, text) { + return `${text}` + }, + image(href, title, text) { + let h = Hash.sha256(href) + if (new URL(href).hostname === new URL(location.href)) + return `${text}` + else + return `
[外部图片] ${text}
` + } +} + +marked.use({ + gfm: true, + renderer: renderer, +}) + + diff --git a/ling_chair_http/handler.js b/ling_chair_http/handler.js index 15f38bd..de40364 100644 --- a/ling_chair_http/handler.js +++ b/ling_chair_http/handler.js @@ -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) diff --git a/ling_chair_http/index.html b/ling_chair_http/index.html index e05cf15..6a140c2 100644 --- a/ling_chair_http/index.html +++ b/ling_chair_http/index.html @@ -25,6 +25,7 @@ + 铃之椅