Comparing version 2.4.2 to 2.4.3
@@ -398,4 +398,6 @@ (function (global, factory) { | ||
var getAltText = function getAltText(node, placeholderCharacter, placeholderLength) { | ||
var altText = node.getAttribute('alt'); | ||
var _node$getAttribute; | ||
var altText = (_node$getAttribute = node.getAttribute('alt')) === null || _node$getAttribute === void 0 ? void 0 : _node$getAttribute.trim(); | ||
if (!altText) { | ||
@@ -421,3 +423,4 @@ var altTextPlaceholder = placeholderCharacter.repeat(placeholderLength); | ||
var tagNameLowerCase = tagName.toLowerCase(); | ||
return tagNameLowerCase === 'img' || tagNameLowerCase === 'image' || tagNameLowerCase === 'area'; | ||
var elementsWithAltText = ['area', 'img', 'input', 'canvas']; | ||
return elementsWithAltText.includes(tagNameLowerCase); | ||
}; | ||
@@ -564,2 +567,8 @@ | ||
if (node.tagName.toLowerCase() === 'svg' && isOpening) { | ||
var _altText = getAltText(node, this.options.placeholderString, this.options.placeholderCopies); | ||
this.text.push(" ".concat(_altText, " ")); | ||
} | ||
this.processBlockConstruct(tag, isOpening); | ||
@@ -852,2 +861,11 @@ return false; | ||
if (node.tagName.toLowerCase() === 'svg' && isOpening) { | ||
var _altText = getAltText(node, this.options.placeholderString, this.options.placeholderCopies); | ||
this.text.push({ | ||
node: node, | ||
string: " ".concat(_altText, " ") | ||
}); | ||
} | ||
this.processBlockConstruct(node, isOpening); | ||
@@ -941,3 +959,11 @@ return false; | ||
} else { | ||
nodeContent = entity.node.textContent.normalize(); | ||
nodeContent = ''; | ||
if (entity.node.tagName === 'svg') { | ||
var _altText2 = getAltText(entity.node, this.options.placeholderString, this.options.placeholderCopies).normalize(); | ||
nodeContent = _altText2; | ||
} | ||
nodeContent += entity.node.textContent.normalize(); | ||
} | ||
@@ -944,0 +970,0 @@ |
{ | ||
"name": "degausser", | ||
"version": "2.4.2", | ||
"version": "2.4.3", | ||
"description": "Transforms HTML to plain text by eliminating tags from a document.", | ||
@@ -5,0 +5,0 @@ "author": "FlowPub", |
@@ -222,2 +222,11 @@ import { | ||
if (node.tagName.toLowerCase() === 'svg' && isOpening) { | ||
const altText = getAltText( | ||
node, | ||
this.options.placeholderString, | ||
this.options.placeholderCopies | ||
) | ||
this.text.push({ node, string: ` ${altText} ` }) | ||
} | ||
this.processBlockConstruct(node, isOpening) | ||
@@ -308,3 +317,12 @@ | ||
} else { | ||
nodeContent = entity.node.textContent.normalize() | ||
nodeContent = '' | ||
if (entity.node.tagName === 'svg') { | ||
const altText = getAltText( | ||
entity.node, | ||
this.options.placeholderString, | ||
this.options.placeholderCopies | ||
).normalize() | ||
nodeContent = altText | ||
} | ||
nodeContent += entity.node.textContent.normalize() | ||
} | ||
@@ -311,0 +329,0 @@ |
@@ -153,2 +153,10 @@ import { | ||
} | ||
if (node.tagName.toLowerCase() === 'svg' && isOpening) { | ||
const altText = getAltText( | ||
node, | ||
this.options.placeholderString, | ||
this.options.placeholderCopies | ||
) | ||
this.text.push(` ${altText} `) | ||
} | ||
@@ -155,0 +163,0 @@ this.processBlockConstruct(tag, isOpening) |
@@ -315,3 +315,3 @@ function autoBind() { | ||
const getAltText = (node, placeholderCharacter, placeholderLength) => { | ||
const altText = node.getAttribute('alt') | ||
const altText = node.getAttribute('alt')?.trim() | ||
if (!altText) { | ||
@@ -336,3 +336,4 @@ const altTextPlaceholder = placeholderCharacter.repeat(placeholderLength) | ||
const tagNameLowerCase = tagName.toLowerCase() | ||
return tagNameLowerCase === 'img' || tagNameLowerCase === 'image' || tagNameLowerCase === 'area' | ||
const elementsWithAltText = ['area', 'img', 'input', 'canvas',] | ||
return elementsWithAltText.includes(tagNameLowerCase) | ||
} | ||
@@ -339,0 +340,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64101
1928