docs(codelab): embed local images in generated Colab notebook#272
Merged
haiyuan-eng-google merged 1 commit intoJun 2, 2026
Conversation
The codelab references images by repo-relative path (so claat copies them into img/), but Colab can't resolve a repo path, leaving the checked-in notebook with a broken image ref. Teach the generator to rewrite local markdown image refs into base64 data URIs (resolved relative to the source markdown dir); remote/data/attachment refs are left unchanged, and a missing local image now fails loudly. Source markdown is unchanged, so claat still uses the relative path. Adds unit tests so a future local image can't drift back to a broken Colab ref; notebook regenerated with the CA screenshot embedded.
haiyuan-eng-google
approved these changes
Jun 2, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the broken image reference in the checked-in Colab notebook (the non-blocking caveat from #271). The codelab references images by repo-relative path (e.g.
images/ca-conversation.png) so claat copies them intoimg/— but Colab can't resolve a repo path, so the generated notebook's image was broken.Change:
scripts/generate_colab_from_codelab.pynow rewrites local markdown image refs into base64 data URIs during notebook generation (resolved relative to the source markdown's directory). The notebook then renders the image inline in Colab.img/.http(s)://),data:, andattachment:refs are left untouched.FileNotFoundError) so a broken ref can't slip through.examples/codelab/periodic_materialization/colab_notebook.ipynbregenerated — the CA screenshot is now embedded (1 data URI, 0 relative paths).Tests
New
tests/test_generate_colab_images.pypins the behavior so a future local image can't drift back to a broken Colab ref:data:image/png;base64,…(and round-trips to the original bytes)build_notebook(..., base_dir=...)embeds; withoutbase_dirit's a no-op (backward compatible)Test plan
tests/test_generate_colab_images.py— 5 pass--checkin syncbash autoformat.shclean (pyink + isort)