From 51c6946e72da333f551fe5cc8dc023d29cd30f94 Mon Sep 17 00:00:00 2001 From: Pavlo Karatsiuba Date: Thu, 23 Mar 2023 18:33:49 +0100 Subject: [PATCH] Don't write image descriptions twice --- src/util/saveArticles.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/util/saveArticles.ts b/src/util/saveArticles.ts index 93bfb5db9..8894a5d3b 100644 --- a/src/util/saveArticles.ts +++ b/src/util/saveArticles.ts @@ -773,6 +773,16 @@ function makeThumbDiv(dump: Dump, parsoidDoc: DominoElement, imageNode: DominoEl return thumbDiv } +function getInnerTextFromElement(domElement: DominoElement) { + const innerNodes = domElement.childNodes + for (const i in innerNodes) { + if (innerNodes[i].nodeType === domElement.TEXT_NODE) { + return innerNodes[i].textContent.trim() + } + } + return null +} + function treatImageFrames(mw: MediaWiki, dump: Dump, parsoidDoc: DominoElement, imageNode: DominoElement) { const image = imageNode.getElementsByTagName('img')[0] || imageNode.getElementsByTagName('video')[0] @@ -795,7 +805,7 @@ function treatImageFrames(mw: MediaWiki, dump: Dump, parsoidDoc: DominoElement, thumbcaptionDiv.setAttribute('class', 'thumbcaption') const autoAlign = dump.mwMetaData.textDir === 'ltr' ? 'left' : 'right' thumbcaptionDiv.setAttribute('style', `text-align: ${autoAlign}`) - if (description) { + if (description && getInnerTextFromElement(imageNode.parentNode) !== getInnerTextFromElement(description)) { thumbcaptionDiv.innerHTML = description.innerHTML }