Extract text inside a text:a tag (#21)
* Extract text inside a text:a tag * Extract text inside a text:a tag and create a test * Fix test regression * Use example domain name for mails * nettoyage console.log --------- Co-authored-by: David Bruant <davidbruant@protonmail.com>
This commit is contained in:
parent
0938a97a83
commit
8cc74a6fe6
@ -799,7 +799,7 @@ export default function fillOdtElementTemplate(rootElements, compartment, addIma
|
|||||||
} else {
|
} else {
|
||||||
const imageMarker = findImageMarker(currentNode.data, compartment)
|
const imageMarker = findImageMarker(currentNode.data, compartment)
|
||||||
if (imageMarker){
|
if (imageMarker){
|
||||||
console.log({imageMarker}, "dans le if imageMarker")
|
//console.log({imageMarker}, "dans le if imageMarker")
|
||||||
if (imageMarker.odfjsImage) {
|
if (imageMarker.odfjsImage) {
|
||||||
const href = addImageToOdtFile(imageMarker.odfjsImage)
|
const href = addImageToOdtFile(imageMarker.odfjsImage)
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,6 @@ const TEXT_NODE = 3
|
|||||||
function extraxtODSCellText(cell) {
|
function extraxtODSCellText(cell) {
|
||||||
let text = '';
|
let text = '';
|
||||||
const childNodes = cell.childNodes;
|
const childNodes = cell.childNodes;
|
||||||
|
|
||||||
for (const child of Array.from(childNodes)) {
|
for (const child of Array.from(childNodes)) {
|
||||||
if (child.nodeType === TEXT_NODE) {
|
if (child.nodeType === TEXT_NODE) {
|
||||||
// Direct text node, append the text directly
|
// Direct text node, append the text directly
|
||||||
@ -34,6 +33,8 @@ function extraxtODSCellText(cell) {
|
|||||||
text += pChild.nodeValue; // Append text inside <text:p>
|
text += pChild.nodeValue; // Append text inside <text:p>
|
||||||
} else if (pChild.nodeName === 'text:line-break') {
|
} else if (pChild.nodeName === 'text:line-break') {
|
||||||
text += '\n'; // Append newline for <text:line-break />
|
text += '\n'; // Append newline for <text:line-break />
|
||||||
|
} else if (pChild.nodeName === 'text:a') {
|
||||||
|
text += pChild.textContent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (child.nodeName === 'text:line-break') {
|
} else if (child.nodeName === 'text:line-break') {
|
||||||
|
|||||||
BIN
tests/fixtures/cellules avec emails.ods
vendored
Normal file
BIN
tests/fixtures/cellules avec emails.ods
vendored
Normal file
Binary file not shown.
@ -55,4 +55,24 @@ Pourquoi t'aimeraient-ils seulement comme tu es ? (hein)
|
|||||||
Si t'es pas comme eux quand t'es naturel`
|
Si t'es pas comme eux quand t'es naturel`
|
||||||
|
|
||||||
t.deepEqual(feuille1[0][0].value, expectedValue)
|
t.deepEqual(feuille1[0][0].value, expectedValue)
|
||||||
|
});
|
||||||
|
|
||||||
|
test('.ods cells with mails should be recognized', async t => {
|
||||||
|
const odsFileWithEmails = (await readFile('./tests/fixtures/cellules avec emails.ods')).buffer
|
||||||
|
const table = await getODSTableRawContent(odsFileWithEmails);
|
||||||
|
|
||||||
|
const feuille1 = table.get('Feuille1')
|
||||||
|
|
||||||
|
const row1 = feuille1[0]
|
||||||
|
t.deepEqual(row1[0].value, 'Nom')
|
||||||
|
t.deepEqual(row1[1].value, 'Email')
|
||||||
|
|
||||||
|
const row2 = feuille1[1]
|
||||||
|
|
||||||
|
t.deepEqual(row2[0].value, 'Dav')
|
||||||
|
t.deepEqual(row2[1].value, 'david@example.org')
|
||||||
|
|
||||||
|
const row3 = feuille1[2]
|
||||||
|
t.deepEqual(row3[0].value, 'Fanny')
|
||||||
|
t.deepEqual(row3[1].value, 'lemaildeFanny@example.com')
|
||||||
});
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user