diff --git a/src/utils/markdown-it-plugins/inlineFence.js b/src/utils/markdown-it-plugins/inlineFence.js deleted file mode 100644 index 0a5e500..0000000 --- a/src/utils/markdown-it-plugins/inlineFence.js +++ /dev/null @@ -1,44 +0,0 @@ -function parseInlineFence(state, silent) { - let pos = state.pos - let max = state.posMax - let src = state.src.slice(pos, max) - - if(pos + 6 > max || state.src.charCodeAt(pos) !== 0x60) { - return false - } - - - if(!src.startsWith('```') || !src.endsWith('```')) { - return false - } - - pos += 3 - - const marker = state.src.slice(state.pos, pos); - - let matchEnd = pos - let matchStart = pos - while ((matchStart = state.src.indexOf('```', matchEnd)) !== -1) { - console.log(matchStart, state) - matchEnd = matchStart + 1 - - if(!silent) { - const token = state.push('fence', 'code', 0) - token.markup = marker - token.content = state.src.slice(pos, matchStart) - .replace(/\n/g, ' ') - .replace(/^ (.+) $/, '$1'); - } - state.pos = matchEnd + 2 - return true - } - - if(!silent) { - state.pending += marker - } - state.pos += 3 - return true -} -export default function inlineFence(md, opts) { - md.inline.ruler.before('backticks', 'inline_fence', parseInlineFence) -} \ No newline at end of file diff --git a/src/utils/messageFormatter.js b/src/utils/messageFormatter.js index 66f2cc3..d577f22 100644 --- a/src/utils/messageFormatter.js +++ b/src/utils/messageFormatter.js @@ -1,45 +1,48 @@ -import twemoji from 'twemoji' -import emojiParser from '@/utils/emojiParser'; +import twemoji from "twemoji"; +import emojiParser from "@/utils/emojiParser"; import config from "@/config.js"; -import customEmoji from './markdown-it-plugins/customEmoji' -import formatLink from './markdown-it-plugins/formatLink' -import formatCode from './markdown-it-plugins/formatCode' -import normalizeFence from './markdown-it-plugins/normalizeFence' -import inlineFence from './markdown-it-plugins/inlineFence' +import customEmoji from "./markdown-it-plugins/customEmoji"; +import formatLink from "./markdown-it-plugins/formatLink"; +import formatCode from "./markdown-it-plugins/formatCode"; +import normalizeFence from "./markdown-it-plugins/normalizeFence"; -import hljs from 'highlight.js' +import hljs from "highlight.js"; -import MarkdownIt from 'markdown-it' -import chatPlugin from 'markdown-it-chat-formatter/dist-src/plugin' +import MarkdownIt from "markdown-it"; +import chatPlugin from "markdown-it-chat-formatter/dist-src/plugin"; const markdown = new MarkdownIt({ - highlight: function (str, lang) { + highlight: function(str, lang) { if (lang && hljs.getLanguage(lang)) { try { - return '
' + - hljs.highlight(lang, str, true).value + - '
'; + return ( + '
' + + hljs.highlight(lang, str, true).value + + "
" + ); } catch (err) { - console.error(err) + console.error(err); } } - return '
' + markdown.utils.escapeHtml(str) + '
'; + return ( + '
' + + markdown.utils.escapeHtml(str) + + "
" + ); } }) .use(normalizeFence) .use(chatPlugin) - .use(customEmoji) + .use(customEmoji) .use(formatLink) - .use(formatCode) - .use(inlineFence) + .use(formatCode); -export default (message) => { +export default message => { + message = markdown.render(message).trim(); - message = markdown.render(message).trim(); + message = emojiParser.replaceEmojis(message); - message = emojiParser.replaceEmojis(message); - - return message; -} \ No newline at end of file + return message; +};