MCPcopy Create free account
hub / github.com/antvis/AVA / wrapSyntaxInHTML

Function wrapSyntaxInHTML

src/visualization/generator.ts:17–54  ·  view source on GitHub ↗

* Wrap GPT-Vis syntax into a standalone HTML file that can be opened in any browser

(syntax: string)

Source from the content-addressed store, hash-verified

15 * Wrap GPT-Vis syntax into a standalone HTML file that can be opened in any browser
16 */
17function wrapSyntaxInHTML(syntax: string): string {
18 // Escape backticks, dollar signs, and backslashes for JS template literal
19 const escapedSyntax = syntax
20 .replace(/\\/g, '\\\\')
21 .replace(/`/g, '\\`')
22 .replace(/\$/g, '\\$')
23 .replace(/<\/script>/g, '<\\/script>');
24
25 return `<!DOCTYPE html>
26<html>
27 <head>
28 <meta charset="UTF-8">
29 <title>Data Visualization</title>
30 <script src="https://unpkg.com/@antv/gpt-vis/dist/umd/index.min.js"></script>
31 <style>
32 html, body, #container {
33 margin: 0;
34 padding: 0;
35 font-family: Arial, sans-serif;
36 width: 100%;
37 height: 100%;
38 }
39 </style>
40 </head>
41 <body>
42 <div id="container"></div>
43 <script>
44 const gptVis = new GPTVis.GPTVis({
45 container: '#container',
46 });
47
48 const visSyntax = \`${escapedSyntax}\`;
49
50 gptVis.render(visSyntax);
51 </script>
52 </body>
53</html>`;
54}
55
56/**
57 * Generate GPT-Vis syntax via LLM and wrap it into a standalone HTML file

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected