Fix multiline YAML description parsing#70
Open
jvanderwee wants to merge 1 commit intonumman-ali:mainfrom
Open
Conversation
Replace manual regex parsing with gray-matter to reliably extract frontmatter fields (including folded > and literal | multiline scalars). Update extractYamlField to handle different value types, trim results, and return empty string on parse failure. Add gray-matter to dependencies and expand tests to cover single-line and multiple multiline cases, complex indentation, and colon/URL handling (fixes multiline parsing bug referenced in tests).
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.
Fixes #69
Problem
Multiline YAML descriptions using folded scalar syntax (
>) were not being parsed correctly. The regex-based parser only captured content on the same line as the field name, resulting in just">"being extracted instead of the full multiline description.Example of the bug:
Actual behavior: Description was
">"Expected behavior: Description should contain the full multiline text
Solution
Replaced the custom regex-based YAML parser with the battle-tested
gray-matterlibrary, which properly handles:>) - newlines folded into spaces|) - newlines preservedChanges
gray-matter(~38KB, 3.6M weekly downloads, built-in TypeScript types)src/utils/yaml.ts:gray-matterparsingtests/utils/yaml.test.ts:>) - the exact bug scenario|)Testing
Backward Compatibility
extractYamlField(content, field)function signatureFiles Changed
package.json- Added gray-matter dependencypackage-lock.json- Dependency lock file updatesrc/utils/yaml.ts- Replaced regex parser with gray-mattertests/utils/yaml.test.ts- Added comprehensive multiline tests