MCPcopy Create free account
hub / github.com/arfct/itty-bitty / traverseItem

Function traverseItem

docs/render/parse.js:183–202  ·  view source on GitHub ↗
(item, data)

Source from the content-addressed store, hash-verified

181 }
182
183 function traverseItem(item, data) {
184 for (const child of item.children) {
185 if (!child.hasAttribute('itemprop')) {
186 traverseItem(child, data);
187 continue;
188 }
189
190 const itemProps = child.getAttribute('itemprop').split(' ');
191 if (child.hasAttribute('itemscope')) {
192 const childData = parseItem(child)
193 itemProps.forEach(key => addValue(data, key, childData));
194 } else {
195 itemProps.forEach(key => {
196 let value = key === 'url' ? child.href : sanitize(child.content || child.textContent || child.src);
197 addValue(data, key, value)
198 });
199 traverseItem(child, data);
200 }
201 }
202 }
203
204 doc.querySelectorAll("[itemscope]").forEach(function(elem, i) {
205 if (!parsedElements.includes(elem)) {

Callers 1

parseItemFunction · 0.85

Calls 3

parseItemFunction · 0.85
addValueFunction · 0.85
sanitizeFunction · 0.85

Tested by

no test coverage detected