import { htmlToPlainText } from '@/utils/exportTableWord'; import { normalizeReferencePublicationDetails } from '@/utils/exportManuscriptWord'; const REF_COPY_DOI_COLOR = '0082AA'; const REF_COPY_FONT = 'Charis SIL, Georgia, Times New Roman, serif'; function escapeHtml(text) { return String(text || '') .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"'); } function hasItalicHtmlTag(html) { return /' + raw + ''); } else { parts.push(raw); } if (suffix) { parts.push(escapeHtml(suffix)); } } /** 将接口参考文献转为可编辑 HTML(支持后续粘贴带 的内容) */ export function referenceRecordToEditableHtml(ref) { if (!ref) { return ''; } const referType = String(ref.refer_type || 'journal').toLowerCase(); if (!ref.author && ref.refer_frag) { let html = stripAvailableAtSuffix(ref.refer_frag); const link = normalizeReferenceLink(ref.doilink || getReferenceIsbnValue(ref)); if (link) { html += ' Available at:' + escapeHtml(ref.doilink || ref.isbn || link); } return html; } const parts = []; if (referType === 'book') { if (ref.author) { appendHtmlField(parts, ref.author, ' '); } if (ref.title) { appendHtmlField(parts, ref.title, '. ', { italics: true }); } if (ref.dateno) { appendHtmlField(parts, ref.dateno, '. '); } const isbnValue = getReferenceIsbnValue(ref); if (isbnValue) { parts.push(' Available at:ISBN: ' + escapeHtml(isbnValue)); } return parts.join(''); } if (referType === 'other') { let html = stripAvailableAtSuffix(ref.refer_frag); const link = normalizeReferenceLink(ref.doilink); if (link) { html += ' Available at:' + escapeHtml(ref.doilink || link); } return html; } if (ref.author) { appendHtmlField(parts, ref.author, ' '); } if (ref.title) { appendHtmlField(parts, ref.title, '. '); } if (ref.joura) { appendHtmlField(parts, ref.joura, '. ', { italics: !hasItalicHtmlTag(ref.joura) }); } if (ref.dateno) { appendHtmlField(parts, ref.dateno, '. '); } const doiLink = normalizeReferenceLink(ref.doilink); if (doiLink) { parts.push(' Available at:' + escapeHtml(ref.doilink || doiLink)); } return parts.join(''); } export function buildReferencesEditableHtml(references, labels) { const list = (references || []).filter(Boolean); const L = labels || {}; const pageTitle = L.pageTitle || 'References Editor'; const intro = L.intro || ''; const saveTip = L.saveTip || ''; const downloadBtn = L.downloadEdited || 'Download edited HTML'; const refTitle = L.referencesTitle || 'References'; const bulkHint = L.bulkHint || ''; const bulkContent = buildReferencesBulkHtml(list); return ( '' + '' + '' + escapeHtml(pageTitle) + '' + '' + '' + escapeHtml(refTitle) + '' + '' + escapeHtml(intro) + '' + '' + '' + escapeHtml(downloadBtn) + '' + '' + '' + escapeHtml(saveTip) + '' + '' + '' + '' + escapeHtml(bulkHint) + '' + '' + bulkContent + '' + '
' + escapeHtml(bulkHint) + '