提交
This commit is contained in:
@@ -466,12 +466,31 @@ export default {
|
||||
if (!body) return { replaced: 0 };
|
||||
let replaced = 0;
|
||||
ed.undoManager.transact(() => {
|
||||
// 先把被拆成多个 span 的 [13, 16, 21–23] 规整成单段文本,再做自动匹配
|
||||
this.normalizeSplitBracketCitesInTableCells(body);
|
||||
replaced = this._replaceBracketCitesInDocOrder(body, doc, maps, { tableOffset: 0 });
|
||||
});
|
||||
this.renderAutociteInEditor(ed);
|
||||
ed.fire('change');
|
||||
return { replaced };
|
||||
},
|
||||
/**
|
||||
* TinyMCE/粘贴可能把单元格里的 [1, 2–3] 拆成多个内联节点(span/text 混排),
|
||||
* 导致按文本节点匹配的自动链接无法命中。这里在匹配前把该类节点规整回纯文本。
|
||||
*/
|
||||
normalizeSplitBracketCitesInTableCells(root) {
|
||||
if (!root || !root.querySelectorAll) return;
|
||||
const cells = root.querySelectorAll('td, th');
|
||||
cells.forEach((cell) => {
|
||||
if (!cell || !cell.querySelectorAll) return;
|
||||
if (cell.querySelector('mycite, autocite, wmath')) return;
|
||||
if (!cell.querySelector('span')) return;
|
||||
const raw = (cell.textContent || '').replace(/\u200b/g, '');
|
||||
const compact = raw.replace(/\s+/g, ' ').trim();
|
||||
if (!/^\[[\d\s,,\-–—]+\]$/.test(compact)) return;
|
||||
cell.textContent = compact;
|
||||
});
|
||||
},
|
||||
/** 底部「自动链接参考文献」按钮,与原先工具栏 autoLinkRefs 行为一致 */
|
||||
handleAutoLinkRefsClick() {
|
||||
const r = this.convertPlainBracketCitesToAutocite();
|
||||
|
||||
Reference in New Issue
Block a user