MCPcopy Index your code
hub / github.com/continuedev/continue / convertToSVG

Method convertToSVG

core/codeRenderer/CodeRenderer.ts:225–268  ·  view source on GitHub ↗
(
    code: string,
    language: string = "javascript",
    options: ConversionOptions,
    currLineOffsetFromTop: number,
    newDiffLines: DiffLine[],
    newDiffChars: DiffChar[],
  )

Source from the content-addressed store, hash-verified

223 }
224
225 async convertToSVG(
226 code: string,
227 language: string = "javascript",
228 options: ConversionOptions,
229 currLineOffsetFromTop: number,
230 newDiffLines: DiffLine[],
231 newDiffChars: DiffChar[],
232 ): Promise<Buffer> {
233 const strokeWidth = 1;
234 const highlightedCodeHtml = await this.highlightCode(
235 code,
236 language,
237 currLineOffsetFromTop,
238 newDiffLines,
239 );
240
241 const { guts, lineBackgrounds } = this.convertShikiHtmlToSvgGut(
242 highlightedCodeHtml,
243 options,
244 newDiffChars,
245 );
246 const backgroundColor = this.getBackgroundColor(highlightedCodeHtml);
247 const borderColor = "#6b6b6b";
248
249 const lines = code.split("\n");
250 const actualHeight = lines.length * options.lineHeight;
251
252 const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${options.dimensions.width}" height="${actualHeight}" shape-rendering="crispEdges">
253 <style>
254 :root {
255 --purple: rgb(112, 114, 209);
256 --green: rgb(136, 194, 163);
257 --blue: rgb(107, 166, 205);
258 }
259 </style>
260 <g>
261 <rect x="0" y="0" rx="2" ry="2" width="${options.dimensions.width}" height="${actualHeight}" fill="${backgroundColor}" stroke="${borderColor}" stroke-width="${strokeWidth}" shape-rendering="crispEdges" />
262 ${lineBackgrounds}
263 ${guts}
264 </g>
265 </svg>`;
266
267 return Buffer.from(svg, "utf8");
268 }
269
270 convertShikiHtmlToSvgGut(
271 shikiHtml: string,

Callers 1

getDataUriMethod · 0.95

Calls 4

highlightCodeMethod · 0.95
getBackgroundColorMethod · 0.95
fromMethod · 0.80

Tested by

no test coverage detected