解决表格斜体加粗
This commit is contained in:
@@ -343,12 +343,14 @@
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i].trim()
|
||||
// 检测表格行:以 | 开头和结尾
|
||||
const isTableLine = /^\|.+|$/.test(line) && line.includes('|')
|
||||
// 检测表格行:以 | 开头并以 | 结尾
|
||||
// 修复:原正则 /^\|.+|&/ 中 | 未转义,导致匹配所有行
|
||||
const isTableLine = /^\|.+\|$/.test(line)
|
||||
|
||||
if (isTableLine) {
|
||||
// 分隔行(如 |---|---|)
|
||||
if (/^\|[\s\-:]+\|[\s\-:|]+\|$/.test(line)) {
|
||||
// 分隔行(如 |---|---| 或 |:---:|)
|
||||
// 修复:原正则在字符类中包含了 | 导致分隔行误判
|
||||
if (/^\|[\s\-:]+\|[\s\-:]+\|$/.test(line)) {
|
||||
alignments = line.split('|').filter(c => c.trim()).map(c => {
|
||||
if (c.trim().startsWith(':') && c.trim().endsWith(':')) return 'center'
|
||||
if (c.trim().endsWith(':')) return 'right'
|
||||
@@ -385,8 +387,12 @@
|
||||
html += '<tr>'
|
||||
cells.forEach((cell, ci) => {
|
||||
const align = alignments[ci] ? ` style="text-align:${alignments[ci]}"` : ''
|
||||
// 修复:转义表格单元格中的 _ 和 *,防止 snarkdown 将其解析为斜体/加粗
|
||||
let cellContent = cell.trim()
|
||||
.replace(/_/g, '_')
|
||||
.replace(/\*/g, '*')
|
||||
html +=
|
||||
`<${tag}${align} style="padding:6px 10px;border:1px solid #ddd">${cell.trim()}</${tag}>`
|
||||
`<${tag}${align} style="padding:6px 10px;border:1px solid #ddd">${cellContent}</${tag}>`
|
||||
})
|
||||
html += '</tr>'
|
||||
})
|
||||
@@ -394,6 +400,19 @@
|
||||
return html
|
||||
}
|
||||
|
||||
// 转义所有单独的 _,但保护 __(双下划线粗体)
|
||||
// snarkdown 的 [_*] 没有任何单词边界限制,会把单词中的 _ 误解析为斜体标记
|
||||
// 如 watermark_mcp、char_spacing 中的 _ 会打开永不闭合的 <em>,导致后面全部斜体
|
||||
const escapeLoneUnderscores = (text) => {
|
||||
// 1. 先用占位符保护 __ 双下划线(snarkdown 的粗体语法)
|
||||
text = text.replace(/__/g, '\x00\x00')
|
||||
// 2. 将剩余的单个 _ 转为 HTML 实体,snarkdown 不会处理实体
|
||||
text = text.replace(/_/g, '_')
|
||||
// 3. 还原 __ 占位符
|
||||
text = text.replace(/\x00\x00/g, '__')
|
||||
return text
|
||||
}
|
||||
|
||||
// Markdown转HTML节点
|
||||
const pareseMarkdown = (content) => {
|
||||
if (!content) return ''
|
||||
@@ -401,14 +420,12 @@
|
||||
content = sanitizeContent(content)
|
||||
|
||||
try {
|
||||
// 转义单词中的单下划线,防止 snarkdown 误解析为斜体
|
||||
content = escapeLoneUnderscores(content)
|
||||
// 先转换表格,再用 snarkdown 处理其他 Markdown
|
||||
content = convertMarkdownTable(content)
|
||||
const html = snarkdown(content)
|
||||
return html
|
||||
// // 过滤掉可能导致问题的 Unicode 属性
|
||||
// const safeHtml = html.replace(/\\p\{[LN]\}/g, '')
|
||||
|
||||
// return safeHtml
|
||||
} catch (e) {
|
||||
console.error('解析失败', e)
|
||||
return content
|
||||
@@ -1164,7 +1181,7 @@
|
||||
const takeConversationMessages = async () => {
|
||||
try {
|
||||
allmessages.value = await getConversationMessages(userToken.value, currentSessionId.value) || [];
|
||||
// console.log("获取到的所有消息:", JSON.stringify(allmessages.value) );
|
||||
console.log("获取到的所有消息:", JSON.stringify(allmessages.value) );
|
||||
// currentMessages.value = allmessages.value.slice(-pageInfoNumber);
|
||||
// 数据获取后执行滚动
|
||||
scrollToBottom();
|
||||
@@ -1178,7 +1195,7 @@
|
||||
const takeFriendMessages = async () => {
|
||||
try {
|
||||
allmessages.value = await getFriendMessages(currentSessionId.value) || [];
|
||||
console.log("好友消息:", JSON.stringify(allmessages.value));
|
||||
// console.log("好友消息:", JSON.stringify(allmessages.value));
|
||||
// 数据获取后执行滚动
|
||||
scrollToBottom();
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user