Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

900 B
Raw Blame
/* Copyright 2026 Marimo. All rights reserved. */
import { DEFAULT_CELL_NAME } from "@/core/cells/names";

export function createCellLink(cellName: string): string {
  const url = new URL(window.location.href);
  // Add the cell name to the hash parameter
  url.hash = `scrollTo=${encodeURIComponent(cellName)}`;
  return url.toString();
}

/**
 * Extract cell name from URL hash
 */
export function extractCellNameFromHash(hash: string): string | null {
  const scrollToMatch = hash.match(/scrollTo=([^&]+)/);
  const cellName = scrollToMatch?.[1];
  if (cellName) {
    return decodeURIComponent(cellName.split("&")[0]);
  }
  return null;
}

/**
 * Check if a cell can be linked to (requires a name)
 */
export function canLinkToCell(cellName: string | undefined): boolean {
  if (cellName === DEFAULT_CELL_NAME) {
    return false;
  }
  return Boolean(cellName && cellName.trim().length > 0);
}