microsoft / microsoft/markitdown
bug: IpynbConverter loses document title when cell source is a string instead of list
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 186k
- Forks
- 13.7k
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 49
Description
Bug
The nbformat spec allows cell source to be either a list of strings or a plain string. When source is a plain string, IpynbConverter silently produces result.title = None even when the cell starts with a # Heading.
Reproduction
`python
import io, json
from markitdown import MarkItDown
md = MarkItDown()
source as LIST — works correctly
nb_list = {'nbformat': 4, 'nbformat_minor': 5,
'metadata': {'kernelspec': {'name': 'python3', 'display_name': 'Python 3', 'language': 'python'}},
'cells': [{'cell_type': 'markdown', 'source': ['# My Report\n', '\n', 'Content'], 'metadata': {}}]}
source as STRING — same content, valid per nbformat spec
nb_str = {'nbformat': 4, 'nbformat_minor': 5,
'metadata': {'kernelspec': {'name': 'python3', 'display_name': 'Python 3', 'language': 'python'}},
'cells': [{'cell_type': 'markdown', 'source': '# My Report\n\nContent', 'metadata': {}}]}
r1 = md.convert(io.BytesIO(json.dumps(nb_list).encode()), url='a.ipynb')
r2 = md.convert(io.BytesIO(json.dumps(nb_str).encode()), url='b.ipynb')
print(r1.title) # 'My Report' ✓
print(r2.title) # None ✗
`
Root cause
_ipynb_converter.py line 72 does for line in source_lines where source_lines is the raw source value from the cell. When source is a string, this iterates character by character, so line.startswith('# ') never matches.
Fix
Normalise string source to a list before processing:
python source = cell.get('source', []) if isinstance(source, str): source = source.splitlines(keepends=True) source_lines = source
PR: #2113
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in _ipynb_converter.py around line 72 and reproduce the issue with the string-valued cell source shown in the report. Compare it with the list-valued case and verify that conversion extracts the heading as the document title for both valid source forms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100