Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// var startTime = new Date().getTime()
const rootStack = [{
name: 'div',
type: 'block',
}];
const tagStack = [rootStack[0]];
const opts = {
recognizeSelfClosing: true,
lowerCaseAttributeNames: true,
lowerCaseTags: true,
decodeEntities: true,
};
const parser = new htmlparser.Parser({
onopentag: (tag, attrs) => {
// console.log('openTag:');
// console.log(name);
const father = tagStack[tagStack.length - 1];
if (!father.children) {
father.children = [];
}
if (indexOf(tag, blockTagArr)) {
father.children.push({
name: tag,
attribs: attrs,
type: 'block',
parent: father,
});
// console.log('???', parent && parent.attribs && parent.attribs.href, parent && parent.name, '====>')
return (
)
}
}
})
}
const handler = new htmlparser.DomHandler(function (err, dom) {
if (err) done(err)
done(null, domToElement(dom, null, !opts.shouldForceInline))
})
const parser = new htmlparser.Parser(handler)
parser.write(rawHtml)
parser.done()
}
)
} else {
log('渲染Text组件', inInsideView, node.name, depth)
let inlineNode = renderInlineNode(index, [], inInsideView)
// console.log('???', parent && parent.attribs && parent.attribs.href, parent && parent.name, '====>')
return (
)
}
}
})
}
const handler = new htmlparser.DomHandler(function (err, dom) {
if (err) done(err)
done(null, domToElement(dom, null, !opts.shouldForceInline))
})
const parser = new htmlparser.Parser(handler)
parser.write(rawHtml)
parser.done()
}
export default function parseHTML(content: string): HTMLNode {
const root: HTMLNode = new HTMLNode("div", {});
let last = root;
const html = new HTMLParser.Parser(
{
onopentag(name, attrs) {
const node = new HTMLNode(name, attrs);
last.append(node);
last = node;
},
ontext(text) {
if (!/^\s*$/.test(text)) {
last.append(text);
}
},
onclosetag() {
last = last.parentNode;
}
{linebreakBefore}
{listItemPrefix}
{domToElement(node.children, node)}
{linebreakAfter}
);
}
});
}
const handler = new htmlparser.DomHandler((err, dom) => {
if (err) done(err);
done(null, domToElement(dom));
});
const parser = new htmlparser.Parser(handler);
parser.write(rawHtml);
parser.done();
}
>
{linebreakBefore}
{listItemPrefix}
{domToElement(node.children, node)}
{linebreakAfter}
);
}
});
}
const handler = new htmlparser.DomHandler(function(err, dom) {
if (err) done(err);
done(null, domToElement(dom));
});
const parser = new htmlparser.Parser(handler);
parser.write(rawHtml);
parser.done();
}
const { NodeComponent } = opts;
return (
{linebreakBefore}
{listItemPrefix}
{domToElement(node.children, node)}
{linebreakAfter}
);
}
});
}
const handler = new htmlparser.DomHandler((err, dom) => {
if (err) done(err);
done(null, domToElement(dom));
});
const parser = new htmlparser.Parser(handler);
parser.write(rawHtml);
parser.done();
}
key={index}
onPress={linkPressHandler}
style={!node.parent ? styles[node.name] : null}
onLongPress={linkLongPressHandler}
>
{linebreakBefore}
{listItemPrefix}
{domToElement(node.children, node)}
{linebreakAfter}
);
}
});
}
const handler = new htmlparser.DomHandler(function(err, dom) {
if (err) done(err);
done(null, domToElement(dom));
});
const parser = new htmlparser.Parser(handler);
parser.write(rawHtml);
parser.done();
}