(
code: string,
language: string = "javascript",
options: ConversionOptions,
currLineOffsetFromTop: number,
newDiffLines: DiffLine[],
newDiffChars: DiffChar[],
)
| 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, |
no test coverage detected