MCPcopy Create free account
hub / github.com/github/gh-aw / ExtractFrontmatterFromBuiltinFile

Function ExtractFrontmatterFromBuiltinFile

pkg/parser/frontmatter_content.go:229–242  ·  view source on GitHub ↗

ExtractFrontmatterFromBuiltinFile is a caching wrapper around ExtractFrontmatterFromContent for builtin virtual files. Because builtin files are registered once at startup and never change, the parsed FrontmatterResult is identical across calls. This function caches the first parse result in builtin

(path string, content []byte)

Source from the content-addressed store, hash-verified

227//
228// path must start with BuiltinPathPrefix ("@builtin:"); an error is returned otherwise.
229func ExtractFrontmatterFromBuiltinFile(path string, content []byte) (*FrontmatterResult, error) {
230 if !strings.HasPrefix(path, BuiltinPathPrefix) {
231 return nil, fmt.Errorf("ExtractFrontmatterFromBuiltinFile: path %q does not start with %q", path, BuiltinPathPrefix)
232 }
233 if cached, ok := GetBuiltinFrontmatterCache(path); ok {
234 return cached, nil
235 }
236 result, err := ExtractFrontmatterFromContent(string(content))
237 if err != nil {
238 return nil, err
239 }
240 // SetBuiltinFrontmatterCache uses LoadOrStore so concurrent races are safe.
241 return SetBuiltinFrontmatterCache(path, result), nil
242}
243
244// ExtractMarkdownSection extracts a specific section from markdown content
245// Supports H1-H3 headers and proper nesting (matches bash implementation)

Calls 4

ErrorfMethod · 0.45