Skip to content

Commit

Permalink
Don't write image descriptions twice
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-karatsiuba committed Mar 23, 2023
1 parent 9a2c38f commit 51c6946
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/util/saveArticles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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
}

Expand Down

0 comments on commit 51c6946

Please sign in to comment.