fix(ipynb): handle string and null cell sources in IpynbConverter#2239
Open
hsusul wants to merge 1 commit into
Open
fix(ipynb): handle string and null cell sources in IpynbConverter#2239hsusul wants to merge 1 commit into
hsusul wants to merge 1 commit into
Conversation
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
sourcefield representations (str,list[str],None, or missing) inIpynbConverter.TypeErrorand conversion failure when cell sources areNoneor missing.Problem
According to the Jupyter notebook specification (nbformat v4), cell
sourcefields may be represented either as a list of strings or as a single string (orNone).When
sourceis a string (e.g.,"# Title\nSome markdown"),IpynbConverter._convert()previously iterated oversource_linescharacter-by-character ('#',' ', ...). As a result, heading detection (line.startswith("# ")) never matched, failing to extract the document title.Additionally, if a cell
sourceisNoneor missing,"".join(None)raised aTypeErrorwrapped in aFileConversionException, causingMarkItDownto crash or fall back to raw plain text output.Furthermore, if
metadatain the notebook JSON isnull,notebook_content.get("metadata", {}).get("title", title)raised anAttributeError.Root cause
IpynbConverter._convert()assumedcell.get("source", [])is always a list of line strings, without normalizing string orNonevalues.Fix
_get_source_lines(source: Any) -> list[str]helper method to normalize cell sources (str,list,None) into a list of line strings with preserved line endings._get_source_lines()across all cell types (markdown,code,raw).metadata: null.test_ipynb_converter_string_and_none_sourcecovering string, list, andNonecell sources.Testing
pytest packages/markitdown/tests/test_module_misc.py -k test_ipynb_converter_string_and_none_source— PASSpytest packages/markitdown/tests/test_module_vectors.py— PASS (109 passed)git diff --check— PASS (clean, no trailing whitespace)Compatibility
100% backward compatible. All existing tests pass.