Repository navigation
fix(ipynb): extract titles from string cell sources - #2768
Open
Vasyl Smutok (vsmutok) wants to merge 1 commit into
Open
Vasyl Smutok (vsmutok) wants to merge 1 commit into
Vasyl Smutok (vsmutok) wants to merge 1 commit into
Conversation
nbformat allows a cell's `source` to be either a list of strings or a
single string. `IpynbConverter` iterated over `source` as if it were a
list of lines, so for the single-string form it walked the characters
one by one and `line.startswith("# ")` never matched, silently dropping
the notebook title.
Normalize string sources into a list of lines (keeping line endings so
the rendered markdown is unchanged) before the title scan.
Fixes microsoft#2762
Author
@microsoft-github-policy-service agree [company="{your company}"] |
Author
|
@microsoft-github-policy-service agree |
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
nbformat allows a cell's
sourceto be either a list of strings or a single string, and both forms validate.IpynbConverteriterated oversourceassuming it was a list of lines, so with the single-string form it walked the characters one at a time andline.startswith("# ")never matched — the notebook title was silently dropped while the body still converted correctly.This normalizes string sources into a list of lines with
splitlines(keepends=True)before the title scan. Line endings are preserved, so the generated markdown is byte-for-byte identical for both forms.Before / after
Tests
Added two regression tests in
packages/markitdown/tests/test_module_misc.py:test_ipynb_string_source_extracts_title— reproduces the issue.test_ipynb_string_and_list_sources_convert_identically— asserts both source forms produce the same markdown (markdown/code/raw cells, including a source without a trailing newline).Both fail on
mainand pass with the fix. Full suite locally on Python 3.14:Fixes #2762