Skip to content

feat: Add cell metadata compatibility and tests#16

Merged
Yahiewi merged 3 commits into
notebook-link:mainfrom
Yahiewi:metadata
Jun 11, 2026
Merged

feat: Add cell metadata compatibility and tests#16
Yahiewi merged 3 commits into
notebook-link:mainfrom
Yahiewi:metadata

Conversation

@Yahiewi

@Yahiewi Yahiewi commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

This PR adds compatibility and round-trip idempotency to the four formats (in particular MyST and Percent by supporting more complex metadata).

Code Changes:

  1. Parsing & Serialization Enhancements:

MyST Format (.md):
-Updated parseMystMd.ts to parse code cell metadata using the parseYAMLBlock helper rather than the line-by-line regex-based parseOptions. This fixes reading nested configuration parameters (like nbgrader settings).
-Updated toMystMd.ts to 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.ts to handle inline JSON block options and space-separated key-value pairs in cell delimiter lines.
-Updated toPy.ts to 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.

  1. New helper functions (utils.ts):
    -Added preprocessYamlLines to support parsing multi-line arrays in YAML headers.
    -Added cleanCellMetadata to 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 as locked and nbgrader).
    -Added parseDoubleQuotedString and escapeNonAsciiYAML to decode and restore PyYAML hex-encoded sequences (preserving special characters like "é" for example).
    -Added pythonStyleJSON to format serialized JSON cell metadata with spaces after colons/commas to mirror Python's default representation.
    -Renamed parseFrontMatter to parseYAMLBlock because its usage is more generic now as it can parse cell YAML blocks.

  2. Demo Updates (App.tsx)
    Added VARIABLES_MYST_SAMPLE (the C++17 variables notebook with custom metadata) to the React demo application's samples.

  3. Tests:
    Created a new roundtrip.test.ts file 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.toml files which can have metadata filter configurations.

@Yahiewi Yahiewi changed the title Add cell metadata compatibility and tests feat: Add cell metadata compatibility and tests Jun 10, 2026
@Yahiewi Yahiewi merged commit fe596a6 into notebook-link:main Jun 11, 2026
2 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant