tijiao
This commit is contained in:
@@ -1115,10 +1115,10 @@ a {
|
||||
/* 自动调整列宽 */
|
||||
text-align: left;
|
||||
font-family: 'Charis SIL' !important;
|
||||
font-size: 7.5pt !important;
|
||||
font-size: 12px !important;
|
||||
mso-font-kerning: 1pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
|
||||
.wordTableHtml table td,
|
||||
@@ -1131,10 +1131,10 @@ a {
|
||||
word-break: normal;
|
||||
|
||||
font-family: 'Charis SIL' !important;
|
||||
font-size: 7.5pt !important;
|
||||
font-size: 12px !important;
|
||||
mso-font-kerning: 1pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
|
||||
.wordTableHtml table tbody tr td {
|
||||
@@ -1160,38 +1160,38 @@ a {
|
||||
align-items: center;
|
||||
margin: 0;
|
||||
font-family: 'Charis SIL' !important;
|
||||
font-size: 7.5pt !important;
|
||||
font-size: 12px !important;
|
||||
mso-font-kerning: 1pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
|
||||
.wordTableHtml table span {
|
||||
color: #000000;
|
||||
text-align: left !important;
|
||||
font-family: 'Charis SIL' !important;
|
||||
font-size: 7.5pt !important;
|
||||
mso-font-kerning: 1pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
font-size:12px !important;
|
||||
|
||||
line-height: 20px !important;
|
||||
|
||||
}
|
||||
|
||||
.wordTableHtml table .color-highlight {
|
||||
color: rgb(0, 130, 170) !important;
|
||||
font-family: 'Charis SIL' !important;
|
||||
font-size: 7.5pt !important;
|
||||
font-size: 12px !important;
|
||||
mso-font-kerning: 1pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
|
||||
.wordTableHtml table blue {
|
||||
color: rgb(0, 130, 170) !important;
|
||||
font-family: 'Charis SIL' !important;
|
||||
font-size: 7.5pt !important;
|
||||
font-size: 12px !important;
|
||||
mso-font-kerning: 1pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
|
||||
.wordTableHtml table tr:first-child td {
|
||||
@@ -1258,10 +1258,10 @@ a {
|
||||
/* 自动调整列宽 */
|
||||
text-align: left;
|
||||
font-family: 'Charis SIL' !important;
|
||||
font-size: 7.5pt !important;
|
||||
font-size: 12px !important;
|
||||
mso-font-kerning: 1pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
|
||||
.word-container table td,
|
||||
@@ -1274,10 +1274,10 @@ a {
|
||||
/* 长单词自动换行 */
|
||||
word-break: normal;
|
||||
font-family: 'Charis SIL' !important;
|
||||
font-size: 7.5pt !important;
|
||||
font-size: 12px !important;
|
||||
mso-font-kerning: 1pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
|
||||
.word-container table tbody tr td {
|
||||
@@ -1303,29 +1303,29 @@ a {
|
||||
|
||||
margin: 0;
|
||||
font-family: 'Charis SIL' !important;
|
||||
font-size: 7.5pt !important;
|
||||
font-size: 12px !important;
|
||||
mso-font-kerning: 1pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
|
||||
.word-container table span {
|
||||
color: #000000;
|
||||
text-align: left !important;
|
||||
font-family: 'Charis SIL' !important;
|
||||
font-size: 7.5pt !important;
|
||||
font-size: 12px !important;
|
||||
mso-font-kerning: 1pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
|
||||
.word-container table .color-highlight {
|
||||
color: rgb(0, 130, 170) !important;
|
||||
font-family: 'Charis SIL' !important;
|
||||
font-size: 7.5pt !important;
|
||||
font-size: 12px !important;
|
||||
mso-font-kerning: 1pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
|
||||
.word-container table tr:first-child td {
|
||||
|
||||
@@ -161,90 +161,152 @@ export default {
|
||||
callback([]);
|
||||
}
|
||||
},
|
||||
|
||||
async extractWordTablesToArrays(file, callback) {
|
||||
const Zip = new JSZip();
|
||||
const namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
||||
try {
|
||||
// 解压 Word 文档
|
||||
const Zip = new JSZip();
|
||||
const zip = await Zip.loadAsync(file);
|
||||
const documentXml = await zip.file("word/document.xml").async("string");
|
||||
|
||||
// 解析 XML
|
||||
console.log("解压后的文件:", Object.keys(zip.files));
|
||||
|
||||
const documentFile = zip.file("word/document.xml");
|
||||
if (!documentFile) {
|
||||
console.error("❌ 找不到 word/document.xml,无法解析 Word 文件");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentXml = await documentFile.async("string");
|
||||
const parser = new DOMParser();
|
||||
const documentDoc = parser.parseFromString(documentXml, "application/xml");
|
||||
|
||||
// 获取命名空间
|
||||
const namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
||||
const numberingXml = await zip.file("word/numbering.xml").async("string");
|
||||
let numberingDoc = null;
|
||||
if (numberingXml) {
|
||||
numberingDoc = parser.parseFromString(numberingXml, "application/xml");
|
||||
console.log("解析的 XML 结构:", new XMLSerializer().serializeToString(documentDoc));
|
||||
|
||||
const numberingFile = zip.file("word/numbering.xml");
|
||||
let numberingMap = {};
|
||||
if (numberingFile) {
|
||||
const numberingXml = await numberingFile.async("string");
|
||||
const numberingDoc = parser.parseFromString(numberingXml, "application/xml");
|
||||
numberingMap = this.parseNumbering(numberingDoc);
|
||||
} else {
|
||||
console.warn("⚠️ word/numbering.xml 不存在,跳过编号解析");
|
||||
}
|
||||
|
||||
// 获取编号定义
|
||||
const numberingMap = this.parseNumbering(numberingDoc);
|
||||
|
||||
// 获取所有表格
|
||||
const tables = documentDoc.getElementsByTagNameNS(namespace, "tbl");
|
||||
const allTables = []; // 存储所有表格的二维数组
|
||||
const allTables = [];
|
||||
|
||||
if (!tables || tables.length === 0) {
|
||||
console.warn("未找到表格内容,请检查 XML 结构");
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
for (const table of tables) {
|
||||
|
||||
const prevParagraph = table.previousElementSibling;
|
||||
if (prevParagraph) {
|
||||
console.log(`表格前的段落: ${prevParagraph.textContent}`);
|
||||
}
|
||||
const rows = table.getElementsByTagNameNS(namespace, "tr");
|
||||
const tableArray = []; // 当前表格的二维数组
|
||||
const tableArray = [];
|
||||
|
||||
for (const row of rows) {
|
||||
let rowSpanMap = [];
|
||||
|
||||
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
|
||||
const row = rows[rowIndex];
|
||||
const cells = row.getElementsByTagNameNS(namespace, "tc");
|
||||
const rowArray = []; // 当前行的数据
|
||||
const rowArray = [];
|
||||
|
||||
// 存储已合并的单元格
|
||||
let colSpanInfo = [];
|
||||
if (!rowSpanMap[rowIndex]) {
|
||||
rowSpanMap[rowIndex] = [];
|
||||
}
|
||||
|
||||
let cellIndex = 0;
|
||||
|
||||
for (let i = 0; i < cells.length; i++) {
|
||||
while (rowSpanMap[rowIndex][cellIndex]) {
|
||||
rowArray.push(null);
|
||||
cellIndex++;
|
||||
}
|
||||
|
||||
const cell = cells[i];
|
||||
let cellText = "";
|
||||
// const paragraphs = cell.getElementsByTagNameNS(namespace, "p");
|
||||
const paragraphs = cell.getElementsByTagName("w:p");
|
||||
// 检查合并单元格属性
|
||||
|
||||
const gridSpan = cell.getElementsByTagNameNS(namespace, "gridSpan")[0];
|
||||
const vMerge = cell.getElementsByTagNameNS(namespace, "vMerge")[0];
|
||||
|
||||
// 获取合并信息
|
||||
let colspan = gridSpan ? parseInt(gridSpan.getAttribute("w:val"), 10) : 1;
|
||||
let rowspan = 1;
|
||||
var colspan = gridSpan ? parseInt(gridSpan.getAttribute("w:val"), 10) : 1;
|
||||
var rowspan = 1;
|
||||
|
||||
if (vMerge && vMerge.getAttribute("w:val") === "restart") {
|
||||
rowspan = 2; // 假设合并两行
|
||||
} else if (vMerge && !vMerge.getAttribute("w:val")) {
|
||||
continue; // 如果是合并单元格的继续部分,则跳过
|
||||
// if (vMerge) {
|
||||
// if (vMerge.getAttribute("w:val") === "restart") {
|
||||
// rowspan = 4;
|
||||
// } else {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
if (vMerge) {
|
||||
if (vMerge.getAttribute("w:val") === "restart") {
|
||||
rowspan = 1; // 初始化 rowspan
|
||||
let nextRowIdx = rowIndex + 1;
|
||||
let maxRowspan = rows.length - rowIndex; // 确保 rowspan 不会超过剩余行数
|
||||
|
||||
while (nextRowIdx < rows.length) {
|
||||
const nextRowCells = rows[nextRowIdx].getElementsByTagNameNS(namespace, "tc");
|
||||
console.log(`🔍 检查下一行单元格 at row ${nextRowIdx}, col ${cellIndex}:`, nextRowCells);
|
||||
|
||||
if (nextRowCells.length > cellIndex) {
|
||||
const nextCell = nextRowCells[cellIndex];
|
||||
|
||||
if (!nextCell) {
|
||||
console.warn(`⚠️ nextCell 未定义 at row ${nextRowIdx}, col ${cellIndex}`);
|
||||
break;
|
||||
}
|
||||
|
||||
const nextVMerge = nextCell.getElementsByTagNameNS(namespace, "vMerge")[0];
|
||||
console.log(`🔍 检查 nextVMerge at row ${nextRowIdx}, col ${cellIndex}:`, nextVMerge);
|
||||
|
||||
// **如果 nextVMerge 为空,则不应继续增长 rowspan**
|
||||
if (!nextVMerge) {
|
||||
console.log(`⚠️ nextVMerge 为空 at row ${nextRowIdx}, col ${cellIndex} - 停止扩展`);
|
||||
break;
|
||||
}
|
||||
|
||||
// **解析 nextVMerge 的值**
|
||||
const vMergeVal = nextVMerge.getAttribute("w:val");
|
||||
|
||||
if (!vMergeVal || vMergeVal === "continue") {
|
||||
if (rowspan < maxRowspan) { // 限制 rowspan 最大值
|
||||
rowspan++;
|
||||
console.log(`✅ rowspan 扩展到: ${rowspan} (row: ${nextRowIdx}, col: ${cellIndex})`);
|
||||
nextRowIdx++;
|
||||
} else {
|
||||
console.log(`⛔ 最大 rowspan 限制 ${rowspan},在 row ${nextRowIdx} 停止`);
|
||||
break;
|
||||
}
|
||||
} else if (vMergeVal === "restart") {
|
||||
console.log(`⛔ 停止 rowspan 扩展 at row ${nextRowIdx}, 因为 w:val="restart"`);
|
||||
break;
|
||||
} else {
|
||||
console.log(`⚠️ 未知 w:val="${vMergeVal}" at row ${nextRowIdx},停止合并`);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
console.warn(`⚠️ Row ${nextRowIdx} 没有足够的列 cellIndex ${cellIndex}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理单元格内容
|
||||
// let cellText = "";
|
||||
|
||||
|
||||
// 为当前单元格初始化计数器
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
console.log('rowspan at line 265:', rowspan)
|
||||
const currentLevelNumbers = {};
|
||||
for (const paragraph of paragraphs) {
|
||||
// 提取段落编号
|
||||
let listPrefix = "";
|
||||
const numPr = paragraph.getElementsByTagName("w:numPr")[0];
|
||||
if (numPr) {
|
||||
console.log('numPr at line 54:', numPr)
|
||||
const numIdElement = numPr.getElementsByTagName("w:numId")[0];
|
||||
console.log('numIdElement at line 56:', numIdElement)
|
||||
const ilvlElement = numPr.getElementsByTagName("w:ilvl")[0];
|
||||
console.log('ilvlElement at line 58:', ilvlElement)
|
||||
if (numIdElement && ilvlElement) {
|
||||
const numId = numIdElement.getAttribute("w:val");
|
||||
const ilvl = ilvlElement.getAttribute("w:val");
|
||||
@@ -252,7 +314,6 @@ export default {
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化当前段落文本
|
||||
let paragraphText = listPrefix ? `${listPrefix} ` : "";
|
||||
|
||||
const runs = paragraph.getElementsByTagName("w:r");
|
||||
@@ -263,7 +324,6 @@ export default {
|
||||
textContent += text.textContent;
|
||||
}
|
||||
|
||||
// 检查格式
|
||||
const rPr = run.getElementsByTagName("w:rPr")[0];
|
||||
let formattedText = textContent;
|
||||
|
||||
@@ -288,83 +348,286 @@ export default {
|
||||
}
|
||||
}
|
||||
|
||||
// 替换负号
|
||||
formattedText = replaceNegativeSign(formattedText);
|
||||
|
||||
// 首字母大写
|
||||
formattedText = capitalizeFirstLetter(formattedText);
|
||||
|
||||
// 添加蓝色标签
|
||||
|
||||
|
||||
|
||||
const regex = /\[(\d+(?:–\d+)?(?:, ?\d+(?:–\d+)?)*)\]/g;
|
||||
|
||||
formattedText = formattedText.replace(/<blue>/g, '').replace(/<\/blue>/g, ''); // 先去掉所有的 <blue> 标签
|
||||
formattedText = formattedText.replace(/<blue>/g, '').replace(/<\/blue>/g, '');
|
||||
|
||||
if (regex.test(formattedText)) {
|
||||
formattedText = formattedText.replace(regex, function (match) {
|
||||
// 提取出方括号中的内容,并进行匹配
|
||||
const content = match.slice(1, match.length - 1); // 去掉方括号
|
||||
const content = match.slice(1, match.length - 1);
|
||||
|
||||
// 判断是否符合条件,纯数字、逗号后有空格、连字符
|
||||
if (/^\d+$/.test(content) || /, ?/.test(content) || /–/.test(content)) {
|
||||
return `<blue>${match}</blue>`; // 如果符合条件则加上蓝色标签
|
||||
return `<blue>${match}</blue>`;
|
||||
}
|
||||
return match; // 如果不符合条件,则保持原样
|
||||
return match;
|
||||
});
|
||||
}
|
||||
console.log("After replacement:", formattedText); // 调试:查看替换后的文本
|
||||
|
||||
|
||||
|
||||
console.log("After replacement:", formattedText);
|
||||
|
||||
paragraphText += formattedText;
|
||||
}
|
||||
|
||||
// 处理换行符
|
||||
const breaks = paragraph.getElementsByTagName("w:br");
|
||||
for (const br of breaks) {
|
||||
paragraphText += "<br>";
|
||||
}
|
||||
|
||||
cellText += paragraphText; // 将段落文本添加到单元格文本
|
||||
cellText += paragraphText;
|
||||
}
|
||||
|
||||
// 更新合并单元格的信息
|
||||
if (colSpanInfo[i]) {
|
||||
colspan = colSpanInfo[i].colspan;
|
||||
}
|
||||
|
||||
// 保存当前单元格信息
|
||||
rowArray.push({
|
||||
text: cellText,
|
||||
colspan: colspan,
|
||||
rowspan: rowspan
|
||||
});
|
||||
|
||||
// 记录跨列合并
|
||||
if (colspan > 1) {
|
||||
for (let j = 1; j < colspan; j++) {
|
||||
colSpanInfo[i + j] = { colspan: 0 }; // 用 0 填充后续的列合并
|
||||
if (rowspan > 1) {
|
||||
for (let j = 1; j < rowspan; j++) {
|
||||
if (!rowSpanMap[rowIndex + j]) {
|
||||
rowSpanMap[rowIndex + j] = [];
|
||||
}
|
||||
rowSpanMap[rowIndex + j][cellIndex] = true;
|
||||
}
|
||||
}
|
||||
|
||||
cellIndex++;
|
||||
}
|
||||
|
||||
tableArray.push(rowArray); // 添加当前行到表格数组
|
||||
tableArray.push(rowArray.filter(item => item !== null));
|
||||
|
||||
}
|
||||
|
||||
allTables.push(tableArray); // 添加当前表格到所有表格数组
|
||||
allTables.push(tableArray);
|
||||
}
|
||||
|
||||
console.log("解析后的二维数组:", allTables);
|
||||
callback(allTables); // 返回处理后的 HTML
|
||||
callback(allTables);
|
||||
|
||||
} catch (error) {
|
||||
console.error("解析 Word 文件失败:", error);
|
||||
return [];
|
||||
callback([]);
|
||||
}
|
||||
},
|
||||
|
||||
// async extractWordTablesToArrays(file, callback) {
|
||||
|
||||
// const namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
||||
// try {
|
||||
// const Zip = new JSZip();
|
||||
// // 解压 ZIP
|
||||
// const zip = await Zip.loadAsync(file);
|
||||
|
||||
// // **检查解压的文件列表**
|
||||
// console.log("解压后的文件:", Object.keys(zip.files));
|
||||
|
||||
// const documentFile = zip.file("word/document.xml");
|
||||
// if (!documentFile) {
|
||||
// console.error("❌ 找不到 word/document.xml,无法解析 Word 文件");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// const documentXml = await documentFile.async("string");
|
||||
// const parser = new DOMParser();
|
||||
// const documentDoc = parser.parseFromString(documentXml, "application/xml");
|
||||
|
||||
// // **打印 XML 结构以检查表格**
|
||||
// console.log("解析的 XML 结构:", new XMLSerializer().serializeToString(documentDoc));
|
||||
|
||||
// // **检查 word/numbering.xml 是否存在**
|
||||
// const numberingFile = zip.file("word/numbering.xml");
|
||||
// let numberingMap = {};
|
||||
// if (numberingFile) {
|
||||
// const numberingXml = await numberingFile.async("string");
|
||||
// const numberingDoc = parser.parseFromString(numberingXml, "application/xml");
|
||||
// numberingMap = parseNumbering(numberingDoc); // 解析编号信息
|
||||
// } else {
|
||||
// console.warn("⚠️ word/numbering.xml 不存在,跳过编号解析");
|
||||
// }
|
||||
|
||||
// const tables = documentDoc.getElementsByTagNameNS(namespace, "tbl");
|
||||
// const allTables = []; // 存储所有表格的二维数组
|
||||
|
||||
// if (!tables || tables.length === 0) {
|
||||
// console.warn("未找到表格内容,请检查 XML 结构");
|
||||
// return [];
|
||||
// }
|
||||
|
||||
|
||||
// for (const table of tables) {
|
||||
|
||||
// const prevParagraph = table.previousElementSibling;
|
||||
// if (prevParagraph) {
|
||||
// console.log(`表格前的段落: ${prevParagraph.textContent}`);
|
||||
// }
|
||||
// const rows = table.getElementsByTagNameNS(namespace, "tr");
|
||||
// const tableArray = []; // 当前表格的二维数组
|
||||
|
||||
// for (const row of rows) {
|
||||
// const cells = row.getElementsByTagNameNS(namespace, "tc");
|
||||
// const rowArray = []; // 当前行的数据
|
||||
|
||||
// // 存储已合并的单元格
|
||||
// let colSpanInfo = [];
|
||||
|
||||
// for (let i = 0; i < cells.length; i++) {
|
||||
// const cell = cells[i];
|
||||
// let cellText = "";
|
||||
// // const paragraphs = cell.getElementsByTagNameNS(namespace, "p");
|
||||
// const paragraphs = cell.getElementsByTagName("w:p");
|
||||
// // 检查合并单元格属性
|
||||
// const gridSpan = cell.getElementsByTagNameNS(namespace, "gridSpan")[0];
|
||||
// const vMerge = cell.getElementsByTagNameNS(namespace, "vMerge")[0];
|
||||
|
||||
// // 获取合并信息
|
||||
// let colspan = gridSpan ? parseInt(gridSpan.getAttribute("w:val"), 10) : 1;
|
||||
// let rowspan = 1;
|
||||
|
||||
// if (vMerge && vMerge.getAttribute("w:val") === "restart") {
|
||||
// rowspan = 4; // 假设合并两行
|
||||
// } else if (vMerge && !vMerge.getAttribute("w:val")) {
|
||||
// continue; // 如果是合并单元格的继续部分,则跳过
|
||||
// }
|
||||
|
||||
// // 处理单元格内容
|
||||
// // let cellText = "";
|
||||
|
||||
|
||||
// // 为当前单元格初始化计数器
|
||||
// const currentLevelNumbers = {};
|
||||
// for (const paragraph of paragraphs) {
|
||||
// // 提取段落编号
|
||||
// let listPrefix = "";
|
||||
// const numPr = paragraph.getElementsByTagName("w:numPr")[0];
|
||||
// if (numPr) {
|
||||
// console.log('numPr at line 54:', numPr)
|
||||
// const numIdElement = numPr.getElementsByTagName("w:numId")[0];
|
||||
// console.log('numIdElement at line 56:', numIdElement)
|
||||
// const ilvlElement = numPr.getElementsByTagName("w:ilvl")[0];
|
||||
// console.log('ilvlElement at line 58:', ilvlElement)
|
||||
// if (numIdElement && ilvlElement) {
|
||||
// const numId = numIdElement.getAttribute("w:val");
|
||||
// const ilvl = ilvlElement.getAttribute("w:val");
|
||||
// listPrefix = this.getListNumber(numId, ilvl, numberingMap, currentLevelNumbers);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 初始化当前段落文本
|
||||
// let paragraphText = listPrefix ? `${listPrefix} ` : "";
|
||||
|
||||
// const runs = paragraph.getElementsByTagName("w:r");
|
||||
// for (const run of runs) {
|
||||
// let textContent = "";
|
||||
// const texts = run.getElementsByTagName("w:t");
|
||||
// for (const text of texts) {
|
||||
// textContent += text.textContent;
|
||||
// }
|
||||
|
||||
// // 检查格式
|
||||
// const rPr = run.getElementsByTagName("w:rPr")[0];
|
||||
// let formattedText = textContent;
|
||||
|
||||
// if (rPr) {
|
||||
// const bold = rPr.getElementsByTagName("w:b").length > 0;
|
||||
// const italic = rPr.getElementsByTagName("w:i").length > 0;
|
||||
// const vertAlignElement = rPr.getElementsByTagName("w:vertAlign")[0];
|
||||
|
||||
// if (bold) {
|
||||
// formattedText = `<b>${formattedText}</b>`;
|
||||
// }
|
||||
// if (italic) {
|
||||
// formattedText = `<i>${formattedText}</i>`;
|
||||
// }
|
||||
// if (vertAlignElement) {
|
||||
// const vertAlign = vertAlignElement.getAttribute("w:val");
|
||||
// if (vertAlign === "superscript") {
|
||||
// formattedText = `<sup>${formattedText}</sup>`;
|
||||
// } else if (vertAlign === "subscript") {
|
||||
// formattedText = `<sub>${formattedText}</sub>`;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 替换负号
|
||||
// formattedText = replaceNegativeSign(formattedText);
|
||||
|
||||
// // 首字母大写
|
||||
// formattedText = capitalizeFirstLetter(formattedText);
|
||||
|
||||
// // 添加蓝色标签
|
||||
|
||||
|
||||
|
||||
// const regex = /\[(\d+(?:–\d+)?(?:, ?\d+(?:–\d+)?)*)\]/g;
|
||||
|
||||
// formattedText = formattedText.replace(/<blue>/g, '').replace(/<\/blue>/g, ''); // 先去掉所有的 <blue> 标签
|
||||
|
||||
// if (regex.test(formattedText)) {
|
||||
// formattedText = formattedText.replace(regex, function (match) {
|
||||
// // 提取出方括号中的内容,并进行匹配
|
||||
// const content = match.slice(1, match.length - 1); // 去掉方括号
|
||||
|
||||
// // 判断是否符合条件,纯数字、逗号后有空格、连字符
|
||||
// if (/^\d+$/.test(content) || /, ?/.test(content) || /–/.test(content)) {
|
||||
// return `<blue>${match}</blue>`; // 如果符合条件则加上蓝色标签
|
||||
// }
|
||||
// return match; // 如果不符合条件,则保持原样
|
||||
// });
|
||||
// }
|
||||
// console.log("After replacement:", formattedText); // 调试:查看替换后的文本
|
||||
|
||||
|
||||
|
||||
|
||||
// paragraphText += formattedText;
|
||||
// }
|
||||
|
||||
// // 处理换行符
|
||||
// const breaks = paragraph.getElementsByTagName("w:br");
|
||||
// for (const br of breaks) {
|
||||
// paragraphText += "<br>";
|
||||
// }
|
||||
|
||||
// cellText += paragraphText; // 将段落文本添加到单元格文本
|
||||
// }
|
||||
|
||||
// // 更新合并单元格的信息
|
||||
// if (colSpanInfo[i]) {
|
||||
// colspan = colSpanInfo[i].colspan;
|
||||
// }
|
||||
|
||||
// // 保存当前单元格信息
|
||||
// rowArray.push({
|
||||
// text: cellText,
|
||||
// colspan: colspan,
|
||||
// rowspan: rowspan
|
||||
// });
|
||||
|
||||
// // 记录跨列合并
|
||||
// if (colspan > 1) {
|
||||
// for (let j = 1; j < colspan; j++) {
|
||||
// colSpanInfo[i + j] = { colspan: 0 }; // 用 0 填充后续的列合并
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// tableArray.push(rowArray); // 添加当前行到表格数组
|
||||
// }
|
||||
|
||||
// allTables.push(tableArray); // 添加当前表格到所有表格数组
|
||||
// }
|
||||
|
||||
// console.log("解析后的二维数组:", allTables);
|
||||
// callback(allTables); // 返回处理后的 HTML
|
||||
|
||||
// } catch (error) {
|
||||
// console.error("解析 Word 文件失败:", error);
|
||||
// return [];
|
||||
// }
|
||||
|
||||
// },
|
||||
transformHtmlString(inputHtml) {
|
||||
|
||||
// inputHtml = inputHtml.replace(/(<[^>]+) style="[^"]*"/g, '$1'); // 移除style属性
|
||||
@@ -388,39 +651,39 @@ export default {
|
||||
|
||||
},
|
||||
|
||||
cleanAndParseWordContent(content) {
|
||||
cleanAndParseWordContent(content) {
|
||||
// 1️⃣ 解析成 <p> 段落数组
|
||||
let tempDiv = document.createElement('div');
|
||||
tempDiv.innerHTML = content; // 解析 HTML 内容
|
||||
let paragraphs = tempDiv.querySelectorAll("p"); // 选取所有 <p> 作为数据项
|
||||
|
||||
|
||||
// 2️⃣ 将 <p> 内容转换为数组,处理空标签对
|
||||
let parsedData = Array.from(paragraphs).map(p => {
|
||||
let text = p.innerHTML.trim(); // 获取内容,去除两端空格
|
||||
|
||||
|
||||
// 3️⃣ 移除 <o:p>(Word 复制的无效标签)
|
||||
text = text.replace(/<\/?o:p>/g, "");
|
||||
|
||||
|
||||
// 4️⃣ 移除 style="..."(防止 Word 带入无用样式)
|
||||
text = text.replace(/\s*style="[^"]*"/g, "");
|
||||
|
||||
|
||||
// 5️⃣ 替换 <strong> 为 <b>
|
||||
text = text.replace(/<strong>/g, "<b>").replace(/<\/strong>/g, "</b>");
|
||||
|
||||
|
||||
// 6️⃣ 替换 <em> 为 <i>
|
||||
text = text.replace(/<em>/g, "<i>").replace(/<\/em>/g, "</i>");
|
||||
|
||||
|
||||
// 7️⃣ 处理空标签对:<i> </i>、<b> </b>、<span> </span> 等
|
||||
text = text.replace(/<[^>]+>\s*<\/[^>]+>/g, "");
|
||||
|
||||
|
||||
// 8️⃣ 如果最终内容为空,则替换为 `""`
|
||||
return text.trim() === "" ? "" : text;
|
||||
});
|
||||
|
||||
|
||||
console.log(parsedData); // 输出数组,方便调试
|
||||
return parsedData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
,
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
//记得切换
|
||||
|
||||
//正式
|
||||
const mediaUrl = '/public/';
|
||||
const baseUrl = '/';
|
||||
// const mediaUrl = '/public/';
|
||||
// const baseUrl = '/';
|
||||
|
||||
|
||||
// const mediaUrl = 'https://submission.tmrjournals.com/public/';
|
||||
// const baseUrl = '/api';
|
||||
const mediaUrl = 'https://submission.tmrjournals.com/public/';
|
||||
const baseUrl = '/api';
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ const tableStyle = ` b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table td, table th {
|
||||
padding: 5px;
|
||||
@@ -55,8 +55,8 @@ const tableStyle = ` b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table tbody tr td{
|
||||
|
||||
@@ -82,8 +82,8 @@ const tableStyle = ` b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table span{
|
||||
|
||||
@@ -91,16 +91,16 @@ const tableStyle = ` b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table .color-highlight{
|
||||
color:rgb(0,130,170) !important;
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table tr:first-child td {
|
||||
border-top:1.0000pt solid #000 !important;mso-border-top-alt:0.5000pt solid #000 !important;border-bottom:1.0000pt solid #000 !important;mso-border-bottom-alt:0.5000pt solid #000 !important;
|
||||
|
||||
@@ -43,8 +43,8 @@ const tableStyle = ` b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table td, table th {
|
||||
padding: 5px;
|
||||
@@ -55,8 +55,8 @@ const tableStyle = ` b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table tbody tr td{
|
||||
|
||||
@@ -84,8 +84,8 @@ const tableStyle = ` b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table span{
|
||||
|
||||
@@ -93,16 +93,16 @@ const tableStyle = ` b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table .color-highlight{
|
||||
color:rgb(0,130,170) !important;
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table tr:first-child td {
|
||||
border-top:1.0000pt solid #000 !important;mso-border-top-alt:0.5000pt solid #000 !important;border-bottom:1.0000pt solid #000 !important;mso-border-bottom-alt:0.5000pt solid #000 !important;
|
||||
|
||||
@@ -94,8 +94,8 @@ b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table td, table th {
|
||||
padding: 5px;
|
||||
@@ -106,8 +106,8 @@ b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table tbody tr td{
|
||||
|
||||
@@ -136,8 +136,8 @@ b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table span{
|
||||
|
||||
@@ -145,16 +145,16 @@ b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table .color-highlight{
|
||||
color:rgb(0,130,170) !important;
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table tr:first-child td {
|
||||
border-top:1.0000pt solid #000 !important;mso-border-top-alt:0.5000pt solid #000 !important;border-bottom:1.0000pt solid #000 !important;mso-border-bottom-alt:0.5000pt solid #000 !important;
|
||||
|
||||
@@ -375,8 +375,8 @@ b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table td, table th {
|
||||
padding: 5px;
|
||||
@@ -387,8 +387,8 @@ b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table tbody tr td{
|
||||
|
||||
@@ -415,8 +415,8 @@ b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table span{
|
||||
|
||||
@@ -424,16 +424,16 @@ b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table .color-highlight{
|
||||
color:rgb(0,130,170) !important;
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table tr:first-child td {
|
||||
border-top:1.0000pt solid #000 !important;mso-border-top-alt:0.5000pt solid #000 !important;border-bottom:1.0000pt solid #000 !important;mso-border-bottom-alt:0.5000pt solid #000 !important;
|
||||
|
||||
@@ -517,8 +517,8 @@ b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table td, table th {
|
||||
padding: 5px;
|
||||
@@ -529,8 +529,8 @@ b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table tbody tr td{
|
||||
|
||||
@@ -557,8 +557,8 @@ b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table span{
|
||||
|
||||
@@ -566,16 +566,16 @@ b span{
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table .color-highlight{
|
||||
color:rgb(0,130,170) !important;
|
||||
font-family:'Charis SIL' !important;
|
||||
font-size: 7.5000pt !important;
|
||||
mso-font-kerning: 1.0000pt !important;
|
||||
line-height: 10pt !important;
|
||||
mos-line-height: 10pt !important;
|
||||
line-height: 20px !important;
|
||||
mos-line-height: 20px !important;
|
||||
}
|
||||
table tr:first-child td {
|
||||
border-top:1.0000pt solid #000 !important;mso-border-top-alt:0.5000pt solid #000 !important;border-bottom:1.0000pt solid #000 !important;mso-border-bottom-alt:0.5000pt solid #000 !important;
|
||||
|
||||
Reference in New Issue
Block a user