MCPcopy Create free account
hub / github.com/OnedocLabs/react-print-pdf / buildExample

Function buildExample

docgen/buildExample.tsx:6–56  ·  view source on GitHub ↗
(
  example: EnrichedExample,
  component: string,
  outputPath: string,
  compileOptions?: CompileOptions
)

Source from the content-addressed store, hash-verified

4import type { CompileOptions } from "../src/compile/compile";
5
6export const buildExample = async (
7 example: EnrichedExample,
8 component: string,
9 outputPath: string,
10 compileOptions?: CompileOptions
11) => {
12 let markdown = ``;
13
14 const snippet = await formatSnippet(example.templateString);
15
16 const paths = await renderPreview(
17 example.template,
18 component,
19 outputPath,
20 true,
21 compileOptions
22 );
23
24 if (example.description) {
25 markdown += `${example.description}\n\n`;
26 }
27
28 markdown += `<Frame background="subtle"><img src="${paths.imagePath}" style={{ width: '100%', height: 'auto', maxHeight: '500px', borderRadius: "0.25rem", overflow: "hidden", border: '1px solid #E5E4E2' }} /></Frame>\n\n`;
29
30 // Check if the folder docs/previews contain the image
31
32 markdown += `<div style={{paddingTop: "1rem", paddingBottom: "1rem"}}><CodeBlocks>
33<CodeBlock title="template.tsx">
34\`\`\`jsx
35import { ${component}${
36 example.imports ? `, ${example.imports.join(", ")}` : ""
37 } } from "@fileforge/react-print";${
38 example.externalImports ? `\n${example.externalImports.join("\n")}` : ""
39 }
40
41${snippet}
42\`\`\`
43</CodeBlock>
44<CodeBlock title="styles.css">
45\`\`\`css
46${baseCss}
47\`\`\`
48</CodeBlock>
49</CodeBlocks></div>\n\n`;
50
51 // markdown += `<a href="${pdfPath}">Download the PDF example ↓</a>\n\n`;
52
53 return {
54 markdown,
55 };
56};

Callers 1

buildFileMarkdownFunction · 0.90

Calls 2

formatSnippetFunction · 0.90
renderPreviewFunction · 0.90

Tested by

no test coverage detected