(node, parent)
| 99 | const htmlTree = isFragment ? parse5.parseFragment(contents) : parse5.parse(contents); |
| 100 | traverse(htmlTree, { |
| 101 | pre(node, parent) { |
| 102 | if (node.attrs) { |
| 103 | // Check if content text should be localized based on presense of data-loc-id attribute |
| 104 | let locId = node.attrs.find(attribute => attribute.name.toLowerCase() == dataLocIdAttribute); |
| 105 | if (locId) { |
| 106 | let locHint = node.attrs.find(attribute => attribute.name.toLowerCase() == dataLocHintAttribute); |
| 107 | nodeCallback(locId.value, locHint?.value, node); |
| 108 | } |
| 109 | // Check if an attribute should be localized based on presense of data-loc-id-<attribute_name> attribute |
| 110 | node.attrs.forEach(attribute => { |
| 111 | if (attribute.name.startsWith(`${dataLocIdAttribute}-`)) { |
| 112 | let targetAttributeName = attribute.name.substring(dataLocIdAttribute.length + 1); |
| 113 | let targetAttribute = node.attrs.find(a => a.name == targetAttributeName); |
| 114 | if (targetAttribute) { |
| 115 | let hint = node.attrs.find(a => a.name.toLowerCase() == `${dataLocHintAttribute}-${targetAttributeName}`); |
| 116 | attributeCallback(attribute.value, hint?.value, targetAttribute); |
| 117 | } |
| 118 | } |
| 119 | }); |
| 120 | } |
| 121 | } |
| 122 | }); |
| 123 | return htmlTree; |
| 124 | }; |
nothing calls this directly
no test coverage detected