(domElement: Element)
| 32 | } |
| 33 | |
| 34 | function createDomElement(domElement: Element): SplootNode { |
| 35 | switch (domElement.tagName.toLowerCase()) { |
| 36 | case 'script': |
| 37 | return createScriptElement(domElement) |
| 38 | default: |
| 39 | break |
| 40 | } |
| 41 | const splootNode = new SplootHtmlElement(null, domElement.tagName.toLowerCase()) |
| 42 | domElement.childNodes.forEach((childNode: ChildNode) => { |
| 43 | const newNode = createNodeFromDomNode(childNode) |
| 44 | if (newNode !== null) { |
| 45 | splootNode.getContent().addChild(newNode) |
| 46 | } |
| 47 | }) |
| 48 | const attrs = domElement.attributes |
| 49 | for (let i = 0; i < attrs.length; i++) { |
| 50 | const attr = attrs.item(i) |
| 51 | // TODO: Detect if this should be a string, number or javascript node. |
| 52 | const strLiteral = new StringLiteral(null, attr.value) |
| 53 | const newAttrNode = new SplootHtmlAttribute(null, attr.name) |
| 54 | newAttrNode.getValue().addChild(strLiteral) |
| 55 | splootNode.getAttributes().addChild(newAttrNode) |
| 56 | } |
| 57 | return splootNode |
| 58 | } |
| 59 | |
| 60 | function createTextNode(textElement: Text): StringLiteral { |
| 61 | if (textElement.textContent.trim().length === 0) { |
no test coverage detected