fix: [lock:] 已解锁内容剥离内联标签(admin/作者视角不再透出 [lock:xxx] 原文)
This commit is contained in:
@@ -19,6 +19,17 @@ function fileTag(filename) {
|
||||
<span class="material-icons" style="font-size:18px">attachment</span> ${escapeHtml(filename)}</a>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 剥离内联 [lock:] 成对标签,保留块内内容(只去标签不去内容)。
|
||||
* - 已解锁块:后端在剥离后的 content 里原样保留 [lock:type]...[/lock] 标签,
|
||||
* 读者视角不该看到标签本身 → 去标签留内容
|
||||
* - 未解锁块:后端已替换为 @@LOCK<n>@@ 占位符(不匹配此正则),不受影响
|
||||
* - 支持 [lock](无参数)与 [lock:type]、[lock:type:参数] 形态;幂等,可重复调用
|
||||
*/
|
||||
export function stripLockTags(content) {
|
||||
return String(content).replace(/\[lock(?::[^\]]*)?\]([\s\S]*?)\[\/lock\]/g, '$1');
|
||||
}
|
||||
|
||||
/**
|
||||
* 内容渲染:useMarkdown=false 走纯文本(转义 + 标签替换 + <br>);
|
||||
* useMarkdown=true 先抽取 [image:]/[file:] 标签,marked 渲染后再还原(照搬 render.js)。
|
||||
@@ -26,6 +37,9 @@ function fileTag(filename) {
|
||||
*/
|
||||
export function renderContent(content, useMarkdown) {
|
||||
if (content == null) return '';
|
||||
// 最前段剥离内联 [lock:] 成对标签:已解锁块的标签透出问题(保留块内内容)。
|
||||
// 未解锁块是 @@LOCK<n>@@ 占位(不匹配),先后顺序与占位分段无冲突
|
||||
content = stripLockTags(content);
|
||||
|
||||
if (!useMarkdown) {
|
||||
let html = escapeHtml(content);
|
||||
@@ -107,9 +121,9 @@ function buildNodes({ content, useMarkdown, locks, unlocked, lockContent, onUnlo
|
||||
return nodes;
|
||||
}
|
||||
|
||||
// 编辑器作者预览:锁定块直接展开内容(作者视角)
|
||||
// 编辑器作者预览:锁定块直接展开内容(作者视角;stripLockTags 幂等,renderContent 内还会再处理一次)
|
||||
if (previewMode) {
|
||||
const stripped = str.replace(/\[lock:(\w+)\]([\s\S]*?)\[\/lock\]/g, '$2');
|
||||
const stripped = stripLockTags(str);
|
||||
return [<RawBlock key="text0" html={renderContent(stripped, useMarkdown)} />];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user