feat: Add cell metadata compatibility and tests#16
Merged
Conversation
|
🎉 This PR is included in version 1.9.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
This PR adds compatibility and round-trip idempotency to the four formats (in particular MyST and Percent by supporting more complex metadata).
Code Changes:
MyST Format (.md):
-Updated
parseMystMd.tsto parse code cell metadata using theparseYAMLBlockhelper rather than the line-by-line regex-basedparseOptions. This fixes reading nested configuration parameters (like nbgrader settings).-Updated
toMystMd.tsto serialize cell metadata conditionally: flat/simple metadata goes to compact colon format (with blank line padding), while nested metadata goes to standard YAML blocks (with no blank line padding).Percent Format (.py):
-Updated
parsePy.tsto handle inline JSON block options and space-separated key-value pairs in cell delimiter lines.-Updated
toPy.tsto extract cell name/title first and write it as a positional argument, then serialize the remaining metadata using JSON or key-value pairs depending on complexity.New helper functions (
utils.ts):-Added
preprocessYamlLinesto support parsing multi-line arrays in YAML headers.-Added
cleanCellMetadatato filter out transient/session-only cell metadata keys (like trusted, collapsed, scrolled, ExecuteTime, execution, etc.) to match Jupytext's serialization filters while fully preserving functional metadata (such aslockedandnbgrader).-Added
parseDoubleQuotedStringandescapeNonAsciiYAMLto decode and restorePyYAMLhex-encoded sequences (preserving special characters like "é" for example).-Added
pythonStyleJSONto format serialized JSON cell metadata with spaces after colons/commas to mirror Python's default representation.-Renamed
parseFrontMattertoparseYAMLBlockbecause its usage is more generic now as it can parse cell YAML blocks.Demo Updates (
App.tsx)Added
VARIABLES_MYST_SAMPLE(the C++17 variables notebook with custom metadata) to the React demo application's samples.Tests:
Created a new
roundtrip.test.tsfile to test round-trips across all four plaintext formats.Screencast:
Screencast.from.2026-06-10.14-28-03.mp4
I still need to figure out an analogue for
jupytext.tomlfiles which can have metadata filter configurations.