5 examples of 'nodejs dom parser' in JavaScript

Every line of 'nodejs dom parser' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
56function parseHTMLToDOM (html_str) {
57 /* Parses a string with HTML and returns a DOM element.
58 *
59 * Forked from vdom_parser:
60 * https://github.com/bitinn/vdom-parser
61 */
62 if (typeof html_str !== 'string') {
63 throw new Error('Invalid parameter type in parseHTMLToDOM');
64 }
65 if ( !('DOMParser' in window) ) {
66 throw new Error(
67 'DOMParser is not available, '+
68 'so parsing string to DOM node is not possible.');
69 }
70 if (!html_str) {
71 return document.createTextNode('');
72 }
73 domParser = domParser || new DOMParser();
74 const doc = domParser.parseFromString(html_str, 'text/html');
75
76 // most tags default to body
77 if (doc.body.firstChild) {
78 return doc.getElementsByTagName('body')[0].firstChild;
79
80 // some tags, like script and style, default to head
81 } else if (doc.head.firstChild && (doc.head.firstChild.tagName !== 'TITLE' || doc.title)) {
82 return doc.head.firstChild;
83
84 // special case for html comment, cdata, doctype
85 } else if (doc.firstChild && doc.firstChild.tagName !== 'HTML') {
86 return doc.firstChild;
87
88 // other element, such as whitespace, or html/body/head tag, fallback to empty text node
89 } else {
90 return document.createTextNode('');
91 }
92}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

436function domGetSource() {
437 return eTextarea.value;
438},
903createParser() {
904 return new jtree.TreeNode.Parser(lineOfHtmlContentNode, undefined, undefined)
905}
537createParser() {
538 return new jtree.TreeNode.Parser(catchAllMultilineStringConstantNode, undefined, undefined)
539}
28isTextNode(node) {
29 return node.nodeType === Node.TEXT_NODE;
30}

Related snippets