Get depth of current block in a document list
545139
function getItemDepth(opts: Options, value: Value, block?: Block): number {
    const { document, startBlock } = value;
    block = block || startBlock;

    const currentItem = getCurrentItem(opts, value, block);
    if (!currentItem) {
        return 0;
    }

    const list = document.getParent(currentItem.key);

    return 1 + getItemDepth(opts, value, list);
}
285634
def getoneblock(astr, start, end):
    """"""
    alist = astr.split(start)
    astr = alist[-1]
    alist = astr.split(end)
    astr = alist[0]
    return astr
556465
def depthtospace(attrs, inputs, proto_obj):
    """"""
    new_attrs = translation_utils._fix_attribute_names(attrs, {'blocksize':'block_size'})

    return "depth_to_space", new_attrs, inputs
388216
def get_contents_dynamic(self, block_alias, context):
        """"""
        dynamic_block = get_dynamic_blocks().get(block_alias, [])
        if not dynamic_block:
            return ''

        dynamic_block = choice(dynamic_block)
        return dynamic_block(block_alias=block_alias, block_context=context)
1064012
function getDepths(depths, callback) {

    async.parallel([
        async.apply(store.getStore().getDepth.bind(store.getStore()), depths.parentUrl),
        async.apply(store.getStore().getDepth.bind(store.getStore()), depths.linkUri)
    ],
    function(error, results){
        if (error) {
          return callback(error);
        }
        depths.parentDepth = results[0];
        depths.linkDepth = results[1];
        callback(null, depths);
    });
}
368943
function getNodesMetaData(rootEl) {
    let elMeta = [];

    let toVisit = [rootEl];
    let current = {el: rootEl, path: [], isPre: $.tag(rootEl) === 'PRE'};

    //generate paths for comment and text nodes. There's no way to quickly retrieve them
    //need to deeply traverse the DOM tree
    while (current) {
        let {el, isPre, path} = current;
        let childNodes = $.childNodes(el);

        for (let i = 0; i < childNodes.length; i++) {
            let childNode = childNodes[i];

            if ($.isText(childNode)) {
                let {meta, delta} = getTextMetaData(rootEl, i, childNode, path, !isPre);
                elMeta.push(...meta);
                i += delta;
            } else if ($.isElement(childNode)) {
                let name = $.getAttr(childNode, ATTR);
                if (name && $.tag(childNode) === 'SCRIPT') {
                    let {meta, delta} = getContainerMetaData(rootEl, i, childNode, path, name);
                    elMeta.push(...meta);
                    i += delta;
                } else {
                    toVisit.push({
                        el: childNode,
                        path: path.concat(i),
                        isPre: current.isPre || $.tag(childNode) === 'PRE'
                    });
                }
            }
        }

        toVisit.shift();
        current = toVisit[0];
    }

    let elementMeta = getElementsMetaData(rootEl);
    elMeta.push(...elementMeta);

    //we need to sort the elements in order of their depth, so that they can be updated
    //from bottom up when ultimately passed to a component.
    return elMeta.sort((a, b) => b.depth - a.depth);
}
99266
def get_subcols(module_ident, plpy):
    """"""
    plan = plpy.prepare('''
    WITH RECURSIVE t(node, parent, path, document) AS (
        SELECT tr.nodeid, tr.parent_id, ARRAY[tr.nodeid], tr.documentid
        FROM trees tr
        WHERE tr.documentid = $1 and tr.is_collated = 'False'
    UNION ALL
        SELECT c.nodeid, c.parent_id, path || ARRAY[c.nodeid], c.documentid
        FROM trees c JOIN t ON (c.nodeid = t.parent)
        WHERE not c.nodeid = ANY(t.path)
    )
    SELECT DISTINCT m.module_ident
    FROM t JOIN modules m ON (t.document = m.module_ident)
    WHERE m.portal_type  = 'SubCollection'
    ORDER BY m.module_ident
    ''', ('integer',))
    for i in plpy.execute(plan, (module_ident,)):
        yield i['module_ident']
338831
function fullPath(el){
  var names = [];
  while (el.parentNode){
    if (el.id){
      names.unshift('#'+el.id);
      break;
    }else{
      if (el==el.ownerDocument.documentElement) names.unshift(el.tagName);
      else{
        for (var c=1,e=el;e.previousElementSibling;e=e.previousElementSibling,c++);
        names.unshift(el.tagName+":nth-child("+c+")");
      }
      el=el.parentNode;
    }
  }
  return names.join(" > ");
}
572779
function getPreviousItem(opts: Options, value: Value, block?: Block): ?Block {
    const { document, startBlock } = value;
    block = block || startBlock;

    const currentItem = getCurrentItem(opts, value, block);
    if (!currentItem) {
        return null;
    }

    const previousSibling = document.getPreviousSibling(currentItem.key);

    if (!previousSibling) {
        return null;
    } else if (previousSibling.type === opts.typeItem) {
        return previousSibling;
    }
    return null;
}
1355376
function(block) {
  if (block.hasOwnProperty('htmlslabs')) {
    return outputSlabsAsText(block.htmlslabs);
  } else {
    if (block.format === 'section') {
      return block.blocks.reduce(function(previousValue, currentValue, currentIndex, array) {
        return previousValue + extractTextBlockText(currentValue);
      }, '');
    } else {
      return '';
    }
  }
}
359857
def GetItemContainerLink(link):
    
    link = TrimBeginningAndEndingSlashes(link) + '/'

    index = IndexOfNth(link, '/', 4)
    
    if index != -1:
        return link[0:index]
    else:
        raise ValueError('Unable to parse document collection link from ' + link)
301225
function getDepth(node) {
  var level = 1; // level: 0
  while (node.parent) {
    level += 1;
    node = node.parent;
  }
  return level;
}
508389
function get_children(layer) {

            // Build array of children
            var children = [];
            for (var index in layer.children)
                children.push(layer.children[index]);

            // Sort
            children.sort(function children_comparator(a, b) {

                // Compare based on Z order
                var diff = a.z - b.z;
                if (diff !== 0)
                    return diff;

                // If Z order identical, use document order
                var a_element = a.getElement();
                var b_element = b.getElement();
                var position = b_element.compareDocumentPosition(a_element);

                if (position & Node.DOCUMENT_POSITION_PRECEDING) return -1;
                if (position & Node.DOCUMENT_POSITION_FOLLOWING) return  1;

                // Otherwise, assume same
                return 0;

            });

            // Done
            return children;

        }
778740
def lastAnchor(self, block, column):
        
        currentPos = -1
        currentBlock = None
        currentColumn = None
        currentChar = None
        for char in '({[':
            try:
                foundBlock, foundColumn = self.findBracketBackward(block, column, char)
            except ValueError:
                continue
            else:
                pos = foundBlock.position() + foundColumn
                if pos > currentPos:
                    currentBlock = foundBlock
                    currentColumn = foundColumn
                    currentChar = char
                    currentPos = pos

        return currentBlock, currentColumn, currentChar
115213
function indexOfDeepestElement (elements) {
        var dropzone,
            deepestZone = elements[0],
            index = deepestZone? 0: -1,
            parent,
            deepestZoneParents = [],
            dropzoneParents = [],
            child,
            i,
            n;

        for (i = 1; i < elements.length; i++) {
            dropzone = elements[i];

            // an element might belong to multiple selector dropzones
            if (!dropzone || dropzone === deepestZone) {
                continue;
            }

            if (!deepestZone) {
                deepestZone = dropzone;
                index = i;
                continue;
            }

            // check if the deepest or current are document.documentElement or document.rootElement
            // - if the current dropzone is, do nothing and continue
            if (dropzone.parentNode === dropzone.ownerDocument) {
                continue;
            }
            // - if deepest is, update with the current dropzone and continue to next
            else if (deepestZone.parentNode === dropzone.ownerDocument) {
                deepestZone = dropzone;
                index = i;
                continue;
            }

            if (!deepestZoneParents.length) {
                parent = deepestZone;
                while (parent.parentNode && parent.parentNode !== parent.ownerDocument) {
                    deepestZoneParents.unshift(parent);
                    parent = parent.parentNode;
                }
            }

            // if this element is an svg element and the current deepest is
            // an HTMLElement
            if (deepestZone instanceof HTMLElement
                && dropzone instanceof SVGElement
                && !(dropzone instanceof SVGSVGElement)) {

                if (dropzone === deepestZone.parentNode) {
                    continue;
                }

                parent = dropzone.ownerSVGElement;
            }
            else {
                parent = dropzone;
            }

            dropzoneParents = [];

            while (parent.parentNode !== parent.ownerDocument) {
                dropzoneParents.unshift(parent);
                parent = parent.parentNode;
            }

            n = 0;

            // get (position of last common ancestor) + 1
            while (dropzoneParents[n] && dropzoneParents[n] === deepestZoneParents[n]) {
                n++;
            }

            var parents = [
                dropzoneParents[n - 1],
                dropzoneParents[n],
                deepestZoneParents[n]
            ];

            child = parents[0].lastChild;

            while (child) {
                if (child === parents[1]) {
                    deepestZone = dropzone;
                    index = i;
                    deepestZoneParents = [];

                    break;
                }
                else if (child === parents[2]) {
                    break;
                }

                child = child.previousSibling;
            }
        }

        return index;
    }
759042
def getCountLT(self, item):
        """"""
        index = bisect.bisect_left(self._list, item)
        return index
773862
def depth(self) -> int:
        
        if len(self.children):
            return 1 + max([child.depth for child in self.children])
        else:
            return 1