def METHOD_NAME(md, tokens, state):
    headings = state.get('toc_headings')
    if not headings:
        return tokens
    # add TOC items into the given location
    default_depth = state.get('toc_depth', 3)
    headings = list(_cleanup_headings_text(md.inline, headings, state))
    for tok in tokens:
        if tok['type'] == 'toc':
            params = tok['params']
            depth = params[1] or default_depth
            items = [d for d in headings if d[2] <= depth]
            tok['raw'] = items
    return tokens