MCPcopy Index your code
hub / github.com/deepnote/deepnote / parseYamlFrontmatter

Function parseYamlFrontmatter

packages/convert/src/quarto-to-deepnote.ts:144–169  ·  view source on GitHub ↗

* Parses YAML frontmatter string into a QuartoFrontmatter object. * Uses the yaml package to properly handle nested objects, arrays, and all YAML features.

(yamlString: string)

Source from the content-addressed store, hash-verified

142 * Uses the yaml package to properly handle nested objects, arrays, and all YAML features.
143 */
144function parseYamlFrontmatter(yamlString: string): QuartoFrontmatter {
145 // Handle empty input
146 if (!yamlString || yamlString.trim() === '') {
147 return {}
148 }
149
150 try {
151 const parsed = parseYaml(yamlString)
152
153 // If parsing returns null or undefined, return empty object
154 if (parsed === null || parsed === undefined) {
155 return {}
156 }
157
158 // Ensure the result is an object (not a primitive or array)
159 if (typeof parsed !== 'object' || Array.isArray(parsed)) {
160 return {}
161 }
162
163 return parsed as QuartoFrontmatter
164 } catch {
165 // If YAML parsing fails, return empty object
166 // In production, you might want to log this error
167 return {}
168 }
169}
170
171/**
172 * Parses Quarto cell options from #| lines.

Callers 1

parseQuartoFormatFunction · 0.85

Calls 1

parseYamlFunction · 0.85

Tested by

no test coverage detected