Fix heading detection in fenced code blocks #9
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.
Fix heading detection in fenced code blocks
Summary
This PR introduces improvements to code parsing reliability by fixing issues with heading detection inside fenced code blocks, updates development dependencies to their latest versions, and makes minor code quality improvements throughout the codebase.
Related Issues
Closes #7
Files Changed
.vscode/settings.json
: Disabled Biome linter integration to prevent conflicts with the existing ESLint setup.bin/md-tree.js
: Fixed critical bug where markdown headings inside code blocks were incorrectly parsed as actual document headings. Also improvedparseInt
calls by explicitly specifying radix parameter and reorganized imports alphabetically.index.js
: Reordered export statements alphabetically for better code organization.package.json
&package-lock.json
: Updated version to 1.6.1 and upgraded development dependencies to latest versions.pnpm-lock.yaml
: Updated lockfile to reflect dependency changes.test/test-cli.js
: Added new test case to verify correct handling of hash symbols inside code blocks.test/test.js
: Minor import statement reordering for consistency.Code Changes
Critical Bug Fix - Code Block Parsing
parseInt Improvements
Reason for Changes
Code Block Bug Fix: Users reported that markdown documents containing code examples with bash comments (starting with
#
) were being incorrectly parsed, causing sections to be truncated when using theexplode
command. This was a critical issue affecting document integrity.parseInt Radix: Added explicit radix parameter (base 10) to all
parseInt
calls to follow JavaScript best practices and avoid potential parsing issues with strings that could be interpreted as octal or hexadecimal.Dependency Updates: Updated ESLint, Prettier, and Node.js types to benefit from latest bug fixes and improvements.
Code Organization: Alphabetized imports and exports for better maintainability and consistency across the codebase.
Impact of Changes
Functionality: The
explode
and section extraction commands now correctly handle markdown documents containing code blocks with hash symbols, preventing data loss and ensuring document integrity.Reliability: Explicit radix in
parseInt
calls eliminates edge cases where numeric strings could be misinterpreted.Development Experience: Updated development dependencies provide better linting, formatting, and type checking capabilities.
Performance: No performance impact expected; changes are primarily bug fixes and code organization improvements.
Test Plan
Added comprehensive test case
CLI explode handles # inside code blocks
that:Existing tests continue to pass, confirming backward compatibility.
Additional Notes
extractAllSections
andadjustHeadingLevels
methods to ensure consistent behavior across all CLI commands.