MCPcopy Create free account
hub / github.com/SplootCode/splootcode / createDomElement

Function createDomElement

packages/language-web/code_io/import_html.ts:34–58  ·  view source on GitHub ↗
(domElement: Element)

Source from the content-addressed store, hash-verified

32}
33
34function 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
60function createTextNode(textElement: Text): StringLiteral {
61 if (textElement.textContent.trim().length === 0) {

Callers 1

createNodeFromDomNodeFunction · 0.85

Calls 6

getContentMethod · 0.95
getValueMethod · 0.95
getAttributesMethod · 0.95
createScriptElementFunction · 0.85
createNodeFromDomNodeFunction · 0.85
addChildMethod · 0.80

Tested by

no test coverage detected