MCPcopy Create free account
hub / github.com/danielpetho/fancy / convertComponentSourceToMarkdown

Function convertComponentSourceToMarkdown

src/scripts/build-docs-markdown.ts:220–247  ·  view source on GitHub ↗
(content: string, includeSourceCode: boolean)

Source from the content-addressed store, hash-verified

218}
219
220function convertComponentSourceToMarkdown(content: string, includeSourceCode: boolean): string {
221 if (!includeSourceCode) {
222 return content.replace(/<ComponentSource[^>]*\/>/g, "")
223 }
224
225 return content.replace(
226 /<ComponentSource\s+name="([^"]+)"[^>]*\/>/g,
227 (match, name) => {
228 try {
229 // Try to load the source code from the registry
230 const registryPath = path.join(baseDir, "public", "r", `${name}.json`)
231 if (fs.existsSync(registryPath)) {
232 const registry = JSON.parse(fs.readFileSync(registryPath, "utf8"))
233 const mainFile = registry.files.find(
234 (file: any) => file.path.split("/").pop().replace(/\.(tsx|ts)$/, "") === name
235 )
236
237 if (mainFile) {
238 return `#### ${name}\n\n\`\`\`tsx\n${mainFile.content}\n\`\`\`\n\n`
239 }
240 }
241 return `#### ${name}\n\nSource code for \`${name}\` component.\n\n`
242 } catch (error) {
243 return `#### ${name}\n\nSource code for \`${name}\` component.\n\n`
244 }
245 }
246 )
247}
248
249function convertInstallTabsToMarkdown(content: string, includeInstructions: boolean): string {
250 if (!includeInstructions) {

Callers 1

convertMdxToMarkdownFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected