import MarkdownIt from "markdown-it";
import hljs from "highlight.js";
import mila from "markdown-it-link-attributes";
import mdKatex from "@traptitech/markdown-it-katex";
/**
* Markdown
*/
const MarkdownUtils = {
mdi: null,
mds: null,
/**
* 解析Markdown
* @param {*} text
* @returns
*/
formatMsg: (text) => {
const array = text.match(/]*?>/g);
if (array) {
array.some(res => {
text = text.replace(res, `
` }, } const MarkdownPluginUtils = { // 配置选项 config: { maxTitleLength: 200, maxDescLength: 1000, maxItems: 200, defaultTitle: '创建任务' }, // HTML转义函数 escapeHtml(unsafe) { return unsafe .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); }, // 验证输入 validateInput(value, maxLength) { if (!value) return ''; if (typeof value !== 'string') return ''; if (value.length > maxLength) { return value.substring(0, maxLength) + '...'; } return value; }, // 解析任务项 parseTaskItems(content) { const items = []; let currentItem = {}; let itemCount = 0; content.forEach(line => { line = line.trim(); if (!line) { if (Object.keys(currentItem).length > 0) { items.push(currentItem); currentItem = {}; itemCount++; } return; } if (itemCount >= this.config.maxItems) { return; } const [key, ...valueParts] = line.split(':'); const value = valueParts.join(':').trim(); if (key === 'title' && value) { if (Object.keys(currentItem).length > 0) { items.push(currentItem); currentItem = {}; itemCount++; } currentItem.title = this.validateInput(value, this.config.maxTitleLength); } else if (key === 'desc' && value) { currentItem.desc = this.validateInput(value, this.config.maxDescLength); } }); if (Object.keys(currentItem).length > 0 && itemCount < this.config.maxItems) { items.push(currentItem); } return items; }, // 生成HTML generateTaskHtml(items, status = null) { if (!Array.isArray(items) || items.length === 0) { return ''; } const html = [ '${lang}${$A.L('复制')}${str}
/g, '\n').replace(/(^|\s+)```([\s\S]*)```/gm, '') if (/<\/(strong|s|em|u|ol|ul|li|blockquote|pre|img|a)>/i.test(tmp)) { return false } if (/]+?class="mention"[^>]*?>/i.test(tmp)) { return false } // const el = document.createElement('div') el.style.position = 'fixed' el.style.top = '0' el.style.left = '0' el.style.width = '10px' el.style.height = '10px' el.style.overflow = 'hidden' el.style.zIndex = '-9999' el.style.opacity = '0' el.innerHTML = html document.body.appendChild(el) const text = el.innerText document.body.removeChild(el) // if ( /(^|\s+)#+\s(.*)$/m.test(text) // 标题 || /(^|\s+)\*\*(.*)\*\*/m.test(text) // 粗体 || /(^|\s+)__(.*)__/m.test(text) // 粗体 || /(^|\s+)\*(.*)\*/m.test(text) // 斜体 || /(^|\s+)_(.*)_/m.test(text) // 斜体 || /(^|\s+)~~(.*)~~/m.test(text) // 删除线 || /(^|\s+)\[(.*?)\]\((.*?)\)/m.test(text) // 链接 || /(^|\s+)!\[(.*?)\]\((.*?)\)/m.test(text) // 图片 || /(^|\s+)`(.*?)`/m.test(text) // 行内代码 || /(^|\s+)```([\s\S]*?)```/m.test(text) // 代码块 ) { return true } return false }