fix text extraction for cells with partial styling

This commit is contained in:
Hannaeko 2025-09-22 16:32:03 +02:00
parent 02d5338634
commit 9748ccb1f0
3 changed files with 38 additions and 28 deletions

View File

@ -33,7 +33,7 @@ function extraxtODSCellText(cell) {
text += pChild.nodeValue; // Append text inside <text:p>
} else if (pChild.nodeName === 'text:line-break') {
text += '\n'; // Append newline for <text:line-break />
} else if (pChild.nodeName === 'text:a') {
} else if (pChild.nodeName === 'text:a' || pChild.nodeName === 'text:span') {
text += pChild.textContent
}
}

BIN
tests/fixtures/cellule avec style.ods vendored Normal file

Binary file not shown.

View File

@ -76,3 +76,13 @@ test('.ods cells with mails should be recognized', async t => {
t.deepEqual(row3[0].value, 'Fanny')
t.deepEqual(row3[1].value, 'lemaildeFanny@example.com')
});
test('.ods cells with partially styled content should be recognized', async t => {
const odsFileWithStyle = (await readFile('./tests/fixtures/cellule avec style.ods')).buffer;
const table = await getODSTableRawContent(odsFileWithStyle);
const feuille1 = table.get('Feuille1');
const row1 = feuille1[0];
t.deepEqual(row1[0].value, 'Toto titi');
});