MCPcopy Create free account
hub / github.com/socketstream/socketstream / walk

Function walk

docs/js/google-code-prettify.js:527–557  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

525 var k = 0;
526
527 function walk(node) {
528 switch (node.nodeType) {
529 case 1: // Element
530 if (nocode.test(node.className)) { return; }
531 for (var child = node.firstChild; child; child = child.nextSibling) {
532 walk(child);
533 }
534 var nodeName = node.nodeName.toLowerCase();
535 if ('br' === nodeName || 'li' === nodeName) {
536 chunks[k] = '\n';
537 spans[k << 1] = length++;
538 spans[(k++ << 1) | 1] = node;
539 }
540 break;
541 case 3: case 4: // Text
542 var text = node.nodeValue;
543 if (text.length) {
544 if (!isPreformatted) {
545 text = text.replace(/[ \t\r\n]+/g, ' ');
546 } else {
547 text = text.replace(/\r\n?/g, '\n'); // Normalize newlines.
548 }
549 // TODO: handle tabs here?
550 chunks[k] = text;
551 spans[k << 1] = length;
552 length += text.length;
553 spans[(k++ << 1) | 1] = node;
554 }
555 break;
556 }
557 }
558
559 walk(node);
560

Callers 2

extractSourceSpansFunction · 0.85
numberLinesFunction · 0.85

Calls 1

breakAfterFunction · 0.85

Tested by

no test coverage detected