From 185b102668cc4af96b2368111d278482b210b8c5 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..fd4f961ab 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 (var i = 0, n = innerNodes.length; i < n; i++) { + 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 }