MCPcopy Index your code
hub / github.com/github/copilot-sdk / parseMarkdownCodeBlocks

Function parseMarkdownCodeBlocks

scripts/docs-validation/extract.ts:50–130  ·  view source on GitHub ↗
(
  content: string,
  filePath: string
)

Source from the content-addressed store, hash-verified

48}
49
50function parseMarkdownCodeBlocks(
51 content: string,
52 filePath: string
53): CodeBlock[] {
54 const blocks: CodeBlock[] = [];
55 const lines = content.split("\n");
56
57 let inCodeBlock = false;
58 let currentLang = "";
59 let currentCode: string[] = [];
60 let blockStartLine = 0;
61 let skipNext = false;
62 let wrapAsync = false;
63 let inHiddenBlock = false;
64
65 for (let i = 0; i < lines.length; i++) {
66 const line = lines[i];
67
68 // Check for validation directives
69 if (line.includes("<!-- docs-validate: skip -->")) {
70 skipNext = true;
71 continue;
72 }
73 if (line.includes("<!-- docs-validate: wrap-async -->")) {
74 wrapAsync = true;
75 continue;
76 }
77 if (line.includes("<!-- docs-validate: hidden -->")) {
78 inHiddenBlock = true;
79 continue;
80 }
81 if (line.includes("<!-- /docs-validate: hidden -->")) {
82 inHiddenBlock = false;
83 // Skip the next visible code block since the hidden one replaces it
84 skipNext = true;
85 continue;
86 }
87
88 // Start of code block
89 if (!inCodeBlock && line.startsWith("```")) {
90 const lang = line.slice(3).trim().toLowerCase();
91 if (lang && LANGUAGE_MAP[lang]) {
92 inCodeBlock = true;
93 currentLang = LANGUAGE_MAP[lang];
94 currentCode = [];
95 blockStartLine = i + 1; // 1-indexed line number
96 }
97 continue;
98 }
99
100 // End of code block
101 if (inCodeBlock && line.startsWith("```")) {
102 blocks.push({
103 language: currentLang,
104 code: currentCode.join("\n"),
105 file: filePath,
106 line: blockStartLine,
107 skip: skipNext,

Callers 1

mainFunction · 0.85

Calls 2

joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…