add-molab-badge

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Add molab badge

添加molab徽章

Add "Open in molab" badge(s) linking to marimo notebooks. The badge can be added to any target: a GitHub README, documentation site, blog post, webpage, or any other markdown/HTML file.
添加指向marimo笔记本的「在molab中打开」徽章。该徽章可添加到任意目标:GitHub README、文档站点、博客文章、网页或其他任何Markdown/HTML文件。

Instructions

操作步骤

1. Determine the notebook links

1. 确定笔记本链接

The user may provide notebook links in one of two ways:
  • User provides links directly. The user pastes URLs to notebooks. Use these as-is — no discovery needed.
  • Notebook discovery (README target only). If the user asks you to add badges to a repository's README and doesn't specify which notebooks, discover them:
    1. Find all marimo notebook files (
      .py
      files) in the repository. Use
      Glob
      with patterns like
      **/*.py
      and then check for the marimo header (
      import marimo
      or
      app = marimo.App
      ) to confirm they are marimo notebooks.
    2. If the README already has links to notebooks (e.g., via
      marimo.app
      links or existing badges), replace those.
    3. Otherwise, ask the user which notebooks should be linked.
用户可通过以下两种方式提供笔记本链接:
  • 用户直接提供链接:用户粘贴笔记本的URL,直接使用这些链接即可,无需进行发现操作。
  • 笔记本自动发现(仅针对README目标):如果用户要求为仓库的README添加徽章但未指定具体笔记本,请按以下步骤自动发现:
    1. 查找仓库中所有marimo笔记本文件(
      .py
      文件)。使用
      Glob
      工具匹配
      **/*.py
      模式,然后检查是否包含marimo头部(
      import marimo
      app = marimo.App
      )来确认是否为marimo笔记本。
    2. 如果README中已存在指向笔记本的链接(例如
      marimo.app
      链接或现有徽章),替换这些链接。
    3. 否则,询问用户应链接哪些笔记本。

2. Construct the molab URL

2. 构建molab URL

For each notebook, construct the molab URL using this format:
https://molab.marimo.io/github/{owner}/{repo}/blob/{branch}/{path_to_notebook}
  • {owner}/{repo}
    : the GitHub owner and repository name. Determine from the git remote (
    git remote get-url origin
    ), the user-provided URL, or by asking the user.
  • {branch}
    : typically
    main
    . Confirm from the repository's default branch.
  • {path_to_notebook}
    : the path to the
    .py
    notebook file relative to the repository root.
为每个笔记本按照以下格式构建molab URL:
https://molab.marimo.io/github/{owner}/{repo}/blob/{branch}/{path_to_notebook}
  • {owner}/{repo}
    :GitHub仓库的所有者和仓库名称。可通过git远程地址(
    git remote get-url origin
    )、用户提供的URL或询问用户来确定。
  • {branch}
    :通常为
    main
    。请根据仓库的默认分支确认。
  • {path_to_notebook}
    .py
    笔记本文件相对于仓库根目录的路径。

3. Apply the
/wasm
suffix rules

3. 应用
/wasm
后缀规则

  • If replacing an existing
    marimo.app
    link, append
    /wasm
    to the molab URL. This is because
    marimo.app
    runs notebooks client-side (WASM), so the molab equivalent needs the
    /wasm
    suffix to preserve that behavior.
  • If adding a new badge (not replacing a
    marimo.app
    link), do not append
    /wasm
    unless the user explicitly requests it.
  • 如果替换现有的
    marimo.app
    链接,请在molab URL后追加
    /wasm
    。这是因为
    marimo.app
    通过客户端(WASM)运行笔记本,因此对应的molab链接需要添加
    /wasm
    后缀以保持相同的行为。
  • 如果是添加徽章(而非替换
    marimo.app
    链接),除非用户明确要求,否则不要追加
    /wasm

4. Format the badge

4. 格式化徽章

Use the following markdown badge format:
markdown
[![Open in molab](https://marimo.io/molab-shield.svg)](URL)
Where
URL
is the constructed molab URL (with or without
/wasm
per the rules above).
For HTML targets, use:
html
<a href="URL"><img src="https://marimo.io/molab-shield.svg" alt="Open in molab" /></a>
使用以下Markdown徽章格式:
markdown
[![Open in molab](https://marimo.io/molab-shield.svg)](URL)
其中
URL
是构建好的molab URL(根据上述规则决定是否添加
/wasm
后缀)。
对于HTML目标,使用以下格式:
html
<a href="URL"><img src="https://marimo.io/molab-shield.svg" alt="Open in molab" /></a>

5. Insert or replace badges in the target

5. 在目标中插入或替换徽章

  • When replacing existing badges or links:
    • Replace
      marimo.app
      URLs with the equivalent
      molab.marimo.io
      URLs.
    • Replace old shield image URLs (e.g.,
      https://marimo.io/shield.svg
      or camo-proxied versions) with
      https://marimo.io/molab-shield.svg
      .
    • Set the alt text to
      Open in molab
      .
    • Preserve surrounding text and structure.
  • Edit the target file in place. Do not rewrite unrelated sections.
  • If the user just wants the badge markdown/HTML (not editing a file), output it directly.
  • 替换现有徽章或链接时:
    • marimo.app
      URL替换为对应的
      molab.marimo.io
      URL。
    • 将旧的徽章图片URL(例如
      https://marimo.io/shield.svg
      或camo代理版本)替换为
      https://marimo.io/molab-shield.svg
    • 将替代文本设置为
      Open in molab
    • 保留周围的文本和结构。
  • 直接编辑目标文件,不要重写无关部分。
  • 如果用户仅需要徽章的Markdown/HTML代码(而非编辑文件),直接输出代码即可。

Examples

示例

Replacing a marimo.app badge in a README:
Before:
markdown
[![](https://marimo.io/shield.svg)](https://marimo.app/github.com/owner/repo/blob/main/notebook.py)
After:
markdown
[![Open in molab](https://marimo.io/molab-shield.svg)](https://molab.marimo.io/github/owner/repo/blob/main/notebook.py/wasm)
Note:
/wasm
is appended because this replaces a
marimo.app
link.
Adding a new badge from user-provided links:
User says: "Add molab badges for these notebooks:
https://github.com/owner/repo/blob/main/demo.py
,
https://github.com/owner/repo/blob/main/tutorial.py
"
Output:
markdown
[![Open in molab](https://marimo.io/molab-shield.svg)](https://molab.marimo.io/github/owner/repo/blob/main/demo.py)
[![Open in molab](https://marimo.io/molab-shield.svg)](https://molab.marimo.io/github/owner/repo/blob/main/tutorial.py)
Note: no
/wasm
suffix by default for new badges.
替换README中的marimo.app徽章:
替换前:
markdown
[![](https://marimo.io/shield.svg)](https://marimo.app/github.com/owner/repo/blob/main/notebook.py)
替换后:
markdown
[![Open in molab](https://marimo.io/molab-shield.svg)](https://molab.marimo.io/github/owner/repo/blob/main/notebook.py/wasm)
注意:由于是替换
marimo.app
链接,因此追加了
/wasm
后缀。
根据用户提供的链接添加新徽章:
用户要求:“为这些笔记本添加molab徽章:
https://github.com/owner/repo/blob/main/demo.py
,
https://github.com/owner/repo/blob/main/tutorial.py
输出:
markdown
[![Open in molab](https://marimo.io/molab-shield.svg)](https://molab.marimo.io/github/owner/repo/blob/main/demo.py)
[![Open in molab](https://marimo.io/molab-shield.svg)](https://molab.marimo.io/github/owner/repo/blob/main/tutorial.py)
注意:默认情况下,新徽章不添加
/wasm
后缀。