Skip to content

Fix multiline YAML description parsing#70

Open
jvanderwee wants to merge 1 commit intonumman-ali:mainfrom
jvanderwee:jv/multiline-description
Open

Fix multiline YAML description parsing#70
jvanderwee wants to merge 1 commit intonumman-ali:mainfrom
jvanderwee:jv/multiline-description

Conversation

@jvanderwee
Copy link

@jvanderwee jvanderwee commented Feb 10, 2026

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:

---
name: apollo-kotlin
description: >
  Guide for building applications with Apollo Kotlin, the GraphQL client library for Android and Kotlin. Use this skill when:
  (1) setting up Apollo Kotlin in a Gradle project for Android, Kotlin/JVM, or KMP,
  (2) configuring schema download and codegen for GraphQL services,
  (3) configuring an ApolloClient with auth, interceptors, and caching,
  (4) writing queries, mutations, or subscriptions,
---

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-matter library, which properly handles:

  • ✅ Folded scalars (>) - newlines folded into spaces
  • ✅ Literal scalars (|) - newlines preserved
  • ✅ Quoted strings with special characters
  • ✅ All YAML edge cases and spec compliance

Changes

  1. Added dependency: gray-matter (~38KB, 3.6M weekly downloads, built-in TypeScript types)
  2. Updated src/utils/yaml.ts:
    • Replaced regex pattern with gray-matter parsing
    • Added proper type handling and error fallback
    • Maintained backward compatibility (same function signature)
  3. Enhanced tests/utils/yaml.test.ts:
    • Added test for folded scalar (>) - the exact bug scenario
    • Added test for literal scalar (|)
    • Added test for complex multiline with indentation
    • Fixed existing "colons in values" test to use proper YAML syntax
    • Renamed misleading test name to be more accurate

Testing

  • ✅ All 106 tests pass
  • ✅ TypeScript compilation successful
  • ✅ Build successful
  • ✅ New tests verify multiline parsing works correctly

Backward Compatibility

  • Same extractYamlField(content, field) function signature
  • Same return type (string)
  • Same error behavior (returns empty string on failure)
  • All existing tests pass without modification

Files Changed

  • package.json - Added gray-matter dependency
  • package-lock.json - Dependency lock file update
  • src/utils/yaml.ts - Replaced regex parser with gray-matter
  • tests/utils/yaml.test.ts - Added comprehensive multiline tests

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Multiline description in frontmatter not parsed correctly

1 participant