-
Notifications
You must be signed in to change notification settings - Fork 765
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(svg-image-alt): work with serial virtual nodes (#2397)
* fix(svg-image-alt): work with serial virtual nodes * fixes * more fixes * fix tests
- Loading branch information
Showing
5 changed files
with
121 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import visibleVirtual from '../../commons/text/visible-virtual'; | ||
|
||
function svgNonEmptyTitleEvaluate(node, options, virtualNode) { | ||
if (!virtualNode.children) { | ||
return undefined; | ||
} | ||
|
||
const titleNode = virtualNode.children.find(({ props }) => { | ||
return props.nodeName === 'title'; | ||
}); | ||
return !!titleNode && titleNode.actualNode.textContent.trim() !== ''; | ||
return !!titleNode && visibleVirtual(titleNode) !== ''; | ||
} | ||
|
||
export default svgNonEmptyTitleEvaluate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
function svgNamespaceMatches(node) { | ||
return node.namespaceURI === 'http://www.w3.org/2000/svg'; | ||
import { closest } from '../core/utils'; | ||
|
||
function svgNamespaceMatches(node, virtualNode) { | ||
try { | ||
const nodeName = virtualNode.props.nodeName; | ||
|
||
if (nodeName === 'svg') { | ||
return true; | ||
} | ||
|
||
// element is svg namespace if its parent is an svg element | ||
return !!closest(virtualNode, 'svg'); | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
export default svgNamespaceMatches; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters