Fix ipynb title extraction stripping leading # from heading text#2052
Open
LeSingh1 wants to merge 1 commit into
Open
Fix ipynb title extraction stripping leading # from heading text#2052LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
The title was extracted with line.lstrip("# "), which strips any
combination of leading "#" and space characters rather than the single
"# " heading marker. A heading whose text begins with "#" (for example
"# #100DaysOfCode") lost those characters and produced "100DaysOfCode".
Remove only the "# " marker prefix via slicing so the heading text is
preserved. Add tests covering a leading "#" in the title and extra
internal spacing after the marker.
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.
Problem
When converting a Jupyter notebook, the document title is taken from the first Markdown
#heading. The extraction uses:str.lstrip(chars)treats its argument as a set of characters to strip, not a prefix. So it removes every leading#and space character, not just the single"# "marker. A heading whose text itself begins with#loses those characters.Example: a notebook whose first heading is
# #100DaysOfCodeproduces the title100DaysOfCodeinstead of#100DaysOfCode.Fix
Strip only the
"# "marker by slicing off its known length:The line already passed
line.startswith("# "), so the prefix is guaranteed present. Outer whitespace is still trimmed by.strip().Tests
Added
tests/test_ipynb_converter.py:#keeps it (# #100DaysOfCode->#100DaysOfCode)All three pass; the first fails on the old code.
Disclosure: I used AI assistance while preparing this change. I reproduced the bug and verified the fix and tests locally.