24 lines
1021 B
JavaScript
24 lines
1021 B
JavaScript
// Enhanced mermaid conversion script that preserves newlines for all chart types
|
|
export const code = async (inputs) => {
|
|
const raw = String(inputs.diagram || "").trim();
|
|
if (!raw) throw new Error("No Mermaid input provided");
|
|
|
|
// Normalize line endings first
|
|
const normalizedDiagram = raw
|
|
.replace(/\r\n/g, '\n') // Convert Windows line endings
|
|
.replace(/\r/g, '\n'); // Convert old Mac line endings
|
|
|
|
// Base64 encode to preserve exact content including newlines
|
|
const base64Encoded = Buffer.from(normalizedDiagram, 'utf8').toString('base64');
|
|
|
|
// Create a wrapper that tells the server this is base64 encoded
|
|
const wrappedDiagram = `%%{init: {"base64": true}}%%\n${base64Encoded}`;
|
|
|
|
console.log("Original diagram length:", normalizedDiagram.length);
|
|
console.log("Original has newlines:", normalizedDiagram.includes('\n'));
|
|
console.log("Base64 encoded length:", base64Encoded.length);
|
|
console.log("Wrapped diagram:", wrappedDiagram);
|
|
|
|
return { rawDsl: wrappedDiagram };
|
|
};
|