MCPcopy Create free account
hub / github.com/driangle/taskmd / findFrontmatterBounds

Function findFrontmatterBounds

apps/vscode/src/frontmatter.ts:38–61  ·  view source on GitHub ↗
(
  text: string
)

Source from the content-addressed store, hash-verified

36 * Returns the line numbers and the YAML text between them, or null if not found.
37 */
38export function findFrontmatterBounds(
39 text: string
40): { startLine: number; endLine: number; yamlText: string } | null {
41 const lines = text.split("\n");
42
43 // Opening delimiter must be at the very first line
44 if (lines.length === 0 || lines[0].trim() !== "---") {
45 return null;
46 }
47
48 // Find closing delimiter
49 for (let i = 1; i < lines.length; i++) {
50 if (lines[i].trim() === "---") {
51 const yamlLines = lines.slice(1, i);
52 return {
53 startLine: 0,
54 endLine: i,
55 yamlText: yamlLines.join("\n"),
56 };
57 }
58 }
59
60 return null; // Unclosed frontmatter
61}
62
63/**
64 * Parse frontmatter from a markdown document string.

Callers 4

getResultFunction · 0.90
parseFrontmatterFunction · 0.70

Calls

no outgoing calls

Tested by 1

getResultFunction · 0.72