add-molab-badge
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAdd 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:
- Find all marimo notebook files (files) in the repository. Use
.pywith patterns likeGloband then check for the marimo header (**/*.pyorimport marimo) to confirm they are marimo notebooks.app = marimo.App - If the README already has links to notebooks (e.g., via links or existing badges), replace those.
marimo.app - Otherwise, ask the user which notebooks should be linked.
- Find all marimo notebook files (
用户可通过以下两种方式提供笔记本链接:
- 用户直接提供链接:用户粘贴笔记本的URL,直接使用这些链接即可,无需进行发现操作。
- 笔记本自动发现(仅针对README目标):如果用户要求为仓库的README添加徽章但未指定具体笔记本,请按以下步骤自动发现:
- 查找仓库中所有marimo笔记本文件(文件)。使用
.py工具匹配Glob模式,然后检查是否包含marimo头部(**/*.py或import marimo)来确认是否为marimo笔记本。app = marimo.App - 如果README中已存在指向笔记本的链接(例如链接或现有徽章),替换这些链接。
marimo.app - 否则,询问用户应链接哪些笔记本。
- 查找仓库中所有marimo笔记本文件(
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}- : the GitHub owner and repository name. Determine from the git remote (
{owner}/{repo}), the user-provided URL, or by asking the user.git remote get-url origin - : typically
{branch}. Confirm from the repository's default branch.main - : the path to the
{path_to_notebook}notebook file relative to the repository root..py
为每个笔记本按照以下格式构建molab URL:
https://molab.marimo.io/github/{owner}/{repo}/blob/{branch}/{path_to_notebook}- :GitHub仓库的所有者和仓库名称。可通过git远程地址(
{owner}/{repo})、用户提供的URL或询问用户来确定。git remote get-url origin - :通常为
{branch}。请根据仓库的默认分支确认。main - :
{path_to_notebook}笔记本文件相对于仓库根目录的路径。.py
3. Apply the /wasm
suffix rules
/wasm3. 应用/wasm
后缀规则
/wasm- If replacing an existing link, append
marimo.appto the molab URL. This is because/wasmruns notebooks client-side (WASM), so the molab equivalent needs themarimo.appsuffix to preserve that behavior./wasm - If adding a new badge (not replacing a link), do not append
marimo.appunless the user explicitly requests it./wasm
- 如果替换现有的链接,请在molab URL后追加
marimo.app。这是因为/wasm通过客户端(WASM)运行笔记本,因此对应的molab链接需要添加marimo.app后缀以保持相同的行为。/wasm - 如果是添加新徽章(而非替换链接),除非用户明确要求,否则不要追加
marimo.app。/wasm
4. Format the badge
4. 格式化徽章
Use the following markdown badge format:
markdown
[](URL)Where is the constructed molab URL (with or without per the rules above).
URL/wasmFor HTML targets, use:
html
<a href="URL"><img src="https://marimo.io/molab-shield.svg" alt="Open in molab" /></a>使用以下Markdown徽章格式:
markdown
[](URL)其中是构建好的molab URL(根据上述规则决定是否添加后缀)。
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 URLs with the equivalent
marimo.appURLs.molab.marimo.io - Replace old shield image URLs (e.g., or camo-proxied versions) with
https://marimo.io/shield.svg.https://marimo.io/molab-shield.svg - Set the alt text to .
Open in molab - Preserve surrounding text and structure.
- Replace
- 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.
- 替换现有徽章或链接时:
- 将URL替换为对应的
marimo.appURL。molab.marimo.io - 将旧的徽章图片URL(例如或camo代理版本)替换为
https://marimo.io/shield.svg。https://marimo.io/molab-shield.svg - 将替代文本设置为。
Open in molab - 保留周围的文本和结构。
- 将
- 直接编辑目标文件,不要重写无关部分。
- 如果用户仅需要徽章的Markdown/HTML代码(而非编辑文件),直接输出代码即可。
Examples
示例
Replacing a marimo.app badge in a README:
Before:
markdown
[](https://marimo.app/github.com/owner/repo/blob/main/notebook.py)After:
markdown
[](https://molab.marimo.io/github/owner/repo/blob/main/notebook.py/wasm)Note: is appended because this replaces a link.
/wasmmarimo.appAdding a new badge from user-provided links:
User says: "Add molab badges for these notebooks: , "
https://github.com/owner/repo/blob/main/demo.pyhttps://github.com/owner/repo/blob/main/tutorial.pyOutput:
markdown
[](https://molab.marimo.io/github/owner/repo/blob/main/demo.py)
[](https://molab.marimo.io/github/owner/repo/blob/main/tutorial.py)Note: no suffix by default for new badges.
/wasm替换README中的marimo.app徽章:
替换前:
markdown
[](https://marimo.app/github.com/owner/repo/blob/main/notebook.py)替换后:
markdown
[](https://molab.marimo.io/github/owner/repo/blob/main/notebook.py/wasm)注意:由于是替换链接,因此追加了后缀。
marimo.app/wasm根据用户提供的链接添加新徽章:
用户要求:“为这些笔记本添加molab徽章:, ”
https://github.com/owner/repo/blob/main/demo.pyhttps://github.com/owner/repo/blob/main/tutorial.py输出:
markdown
[](https://molab.marimo.io/github/owner/repo/blob/main/demo.py)
[](https://molab.marimo.io/github/owner/repo/blob/main/tutorial.py)注意:默认情况下,新徽章不添加后缀。
/wasm