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

Function createScriptElement

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

Source from the content-addressed store, hash-verified

8import { parseJs } from './import_js'
9
10function createScriptElement(domElement: Element): SplootHtmlScriptElement {
11 const splootNode = new SplootHtmlScriptElement(null)
12 domElement.childNodes.forEach((childNode: ChildNode) => {
13 if (childNode.nodeType !== Node.TEXT_NODE) {
14 console.warn('Found non-text node inside script tag??')
15 } else {
16 const jsNode = parseJs((childNode as Text).textContent) as JavascriptFile
17 jsNode.getBody().children.forEach((node: SplootNode) => {
18 splootNode.getContent().addChild(node)
19 })
20 }
21 })
22 const attrs = domElement.attributes
23 for (let i = 0; i < attrs.length; i++) {
24 const attr = attrs.item(i)
25 // TODO: Detect if this should be a string, number or javascript node.
26 const strLiteral = new StringLiteral(null, attr.value)
27 const newAttrNode = new SplootHtmlAttribute(null, attr.name)
28 newAttrNode.getValue().addChild(strLiteral)
29 splootNode.getAttributes().addChild(newAttrNode)
30 }
31 return splootNode
32}
33
34function createDomElement(domElement: Element): SplootNode {
35 switch (domElement.tagName.toLowerCase()) {

Callers 1

createDomElementFunction · 0.85

Calls 6

getContentMethod · 0.95
getValueMethod · 0.95
getAttributesMethod · 0.95
parseJsFunction · 0.90
addChildMethod · 0.80
getBodyMethod · 0.45

Tested by

no test coverage detected