You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
836 B
JavaScript
29 lines
836 B
JavaScript
import { getAttrs } from 'utils/dom';
|
|
|
|
export default function convertNodeTo($node, $, tag = 'p') {
|
|
const node = $node.get(0);
|
|
if (!node) {
|
|
return $;
|
|
}
|
|
const attrs = getAttrs(node) || {};
|
|
// console.log(attrs)
|
|
|
|
const attribString = Reflect.ownKeys(attrs)
|
|
.map(key => `${key}=${attrs[key]}`)
|
|
.join(' ');
|
|
let html;
|
|
|
|
if ($.browser) {
|
|
// In the browser, the contents of noscript tags aren't rendered, therefore
|
|
// transforms on the noscript tag (commonly used for lazy-loading) don't work
|
|
// as expected. This test case handles that
|
|
html = node.tagName.toLowerCase() === 'noscript' ? $node.text() : $node.html();
|
|
} else {
|
|
html = $node.contents();
|
|
}
|
|
$node.replaceWith(
|
|
`<${tag} ${attribString}>${html}</${tag}>`
|
|
);
|
|
return $;
|
|
}
|