| | |
| | | return changed ? documentXml : null |
| | | } |
| | | |
| | | function clearDefaultSequenceUnderlines(xml) { |
| | | return xml.replace(resultTablePattern, table => { |
| | | if (!table.includes('序号') || !/(检测结果|检验结果)/.test(table)) return table |
| | | return table.replace(tableRowPattern, row => row.replace(tableCellPattern, (cell, offset) => { |
| | | if (offset !== row.indexOf('<w:tc')) return cell |
| | | const text = [...cell.matchAll(/<w:t\b(?![^>]*\/>)[^>]*>([\s\S]*?)<\/w:t>/g)] |
| | | .map(match => match[1]).join('').trim() |
| | | if (!/^\d+$/.test(text)) return cell |
| | | // 旧报告中的 <w:u w:color="auto"/> 默认会被解释成单下划线。 |
| | | // 显式设置了类型的下划线保留,允许用户自行修改序号格式。 |
| | | return cell.replace(/<w:u\b[^>]*\/>/g, tag => /\bw:val=/.test(tag) ? tag : '') |
| | | })) |
| | | }) |
| | | } |
| | | |
| | | export async function normalizeReportDocxForEditor(blob, reportCode) { |
| | | const zip = await JSZip.loadAsync(blob) |
| | | const documentPart = zip.file('word/document.xml') |
| | |
| | | const themeXml = themePart ? await themePart.async('string') : '' |
| | | const themeFonts = { major: chineseThemeFont(themeXml, 'major'), minor: chineseThemeFont(themeXml, 'minor') } |
| | | let normalizedXml = alignResultTable(documentXml) || documentXml |
| | | normalizedXml = clearDefaultSequenceUnderlines(normalizedXml) |
| | | normalizedXml = fitCoverCustomer(normalizedXml) || normalizedXml |
| | | normalizedXml = materializeChineseThemeFonts(normalizedXml, themeFonts) || normalizedXml |
| | | let changed = normalizedXml !== documentXml |