This tool maps cell IDs to their corresponding headings and content. Standalone TOC Generator for Google Colab Copyright (c) 2026 1abcdefggs Licensed under the MIT License Source: https://github.com/1abcdefggs/cell-id-call GitHub: https://github.com/1abcdefggs This article describes a standalone Python script called `standalone_toc.py` that generates a table of contents for Google Colab notebooks. The tool helps users map cell IDs to their corresponding headings and content, making it easier to understand which cell an AI assistant like Gemini is referencing. Users can customize the output by filtering by cell type, searching by keyword or cell ID, and adjusting preview settings. standalone toc.py This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters Copyright c 2026 1abcdefggs Licensed under the MIT License See LICENSE file in the project root for full license information /usr/bin/env python3 """ Standalone TOC Generator for Google Colab This script generates a table of contents for Colab notebooks without requiring external modules. Background: When working with AI assistants like Gemini in Colab, they often reference Cell IDs when explaining code or content. This tool helps you map Cell IDs to their corresponding headings and content, making it easier to understand which cell the AI is referring to. Usage: 1. Copy this code to a new cell in your Colab notebook 2. Run the cell to generate a table of contents 3. Customize parameters in generate standalone toc as needed: - filter type: "All", "Code", or "Markdown" - keyword: Search keyword empty string for all cells - match mode: "Cell-ID" or "Content" - limit: Preview character limit default: 70 - show jump: Show jump links True/False - show stats: Show statistics True/False - save log: Save to "TOC Preview.md" True/False Source: https://github.com/1abcdefggs/cell-id-call """ import IPython import json import os from google.colab import message from IPython.display import display, HTML def extract heading preview standalone source, cell type, limit : """Extract heading preview from cell source.""" text = "".join source if isinstance source, list else str source text = text.strip .replace "\n", " " if cell type == "markdown" and text.startswith " " : cleaned = text.lstrip " " .strip if not cleaned: return " Empty heading " return f" {cleaned :limit } " if len cleaned limit else f" {cleaned} " return f"{text :limit }..." if len text limit else text def generate standalone toc filter type, keyword, match mode, limit, show jump, show stats, save log : """Generate standalone TOC for Colab notebook.""" resp = message.blocking request 'get ipynb' if not resp or 'ipynb' not in resp: return cells = resp 'ipynb' .get 'cells', Precise ID and Alignment Logic processed ids = for c in cells: meta = c.get 'metadata', {} cid = meta.get 'colab', {} .get 'id' or c.get 'id' or meta.get 'id' or "unknown" processed ids.append str cid max id len = max len cid for cid in processed ids if processed ids else 12 Dynamic Column Width Calculation jump link base = " Jump scrollTo= " w jump = max len "Jump Link" , max id len + len jump link base w id = max len "Cell ID" , max id len + 2 h jump = f" { 'Jump Link' .ljust w jump } |" if show jump else "" s jump = f" { ':---' .ljust w jump, '-' } |" if show jump else "" header = f"| Type | Index |{h jump} { 'Cell ID' .ljust w id } | Heading / Preview |" sep = f"| :--- | :--- |{s jump} { ':---' .ljust w id, '-' } | :--- |" md table = " 🔍 TOC Preview. Quick Navigation Standalone ", f"Mode: {match mode} , Filter: {filter type} ", header, sep stats = {'markdown': 0, 'code': 0, 'total': len cells } match count = 0 for idx, cell in enumerate cells : c type = cell.get 'cell type', 'unknown' stats c type = stats.get c type, 0 + 1 if filter type == "Code" and c type = 'code': continue if filter type == "Markdown" and c type = 'markdown': continue cell id = processed ids idx source text = "".join cell.get 'source', if keyword: if match mode == "Cell-ID": if keyword = cell id: continue else: if keyword.lower not in source text.lower : continue match count += 1 preview = extract heading preview standalone source text, c type, limit icon = "📝" if c type == 'markdown' else "💻" row = f"| {icon} | {idx:03d} |" if show jump: row += f" {f' Jump scrollTo={cell id} '.ljust w jump } |" row += f" {f' {cell id} '.ljust w id } | {preview} |" md table.append row full md = "\n".join md table if save log: with open "TOC Preview.md", "w", encoding="utf-8" as f: f.write full md if show stats: print f"📊 Total: {stats 'total' } | Matches: {match count}" UI Button with improved JS for copying js content = json.dumps full md button id = "copy btn standalone" html btn = f'''