($node, $, tag = 'p')
| 1 | import { getAttrs } from 'utils/dom'; |
| 2 | |
| 3 | export default function convertNodeTo($node, $, tag = 'p') { |
| 4 | const node = $node.get(0); |
| 5 | if (!node) { |
| 6 | return $; |
| 7 | } |
| 8 | const attrs = getAttrs(node) || {}; |
| 9 | |
| 10 | const attribString = Reflect.ownKeys(attrs) |
| 11 | .map(key => `${key}=${attrs[key]}`) |
| 12 | .join(' '); |
| 13 | let html; |
| 14 | |
| 15 | if ($.browser) { |
| 16 | // In the browser, the contents of noscript tags aren't rendered, therefore |
| 17 | // transforms on the noscript tag (commonly used for lazy-loading) don't work |
| 18 | // as expected. This test case handles that |
| 19 | html = |
| 20 | node.tagName.toLowerCase() === 'noscript' ? $node.text() : $node.html(); |
| 21 | } else { |
| 22 | html = $node.contents(); |
| 23 | } |
| 24 | $node.replaceWith(`<${tag} ${attribString}>${html}</${tag}>`); |
| 25 | return $; |
| 26 | } |
no test coverage detected