diff --git a/debug_quadrant_conversion.js b/debug_quadrant_conversion.js new file mode 100644 index 0000000..5f3c83b --- /dev/null +++ b/debug_quadrant_conversion.js @@ -0,0 +1,65 @@ +// Debug script to test different approaches for quadrant charts +export const code = async (inputs) => { + const raw = String(inputs.diagram || "").trim(); + if (!raw) throw new Error("No Mermaid input provided"); + + // Normalize line endings first + let normalizedDiagram = raw + .replace(/\r\n/g, '\n') // Convert Windows line endings + .replace(/\r/g, '\n'); // Convert old Mac line endings + + console.log("Original diagram:"); + console.log(normalizedDiagram); + + // Check if it's already single line + if (!normalizedDiagram.includes('\n')) { + console.log("Already single line, returning as-is"); + return { rawDsl: normalizedDiagram }; + } + + // For quadrant charts, try different encoding methods + const firstWord = normalizedDiagram.split(/\s+/)[0]; + + if (firstWord === 'quadrantChart') { + console.log("Quadrant chart detected - trying special encoding methods"); + + // Method 1: Try different newline encoding + const method1 = normalizedDiagram.replace(/\n/g, '\\n'); + console.log("Method 1 (\\n encoding):", method1); + + // Method 2: Try different marker + const method2 = normalizedDiagram.replace(/\n/g, ' | '); + console.log("Method 2 (pipe separator):", method2); + + // Method 3: Try preserving original with different content-type hint + const method3 = `PRESERVE_NEWLINES:${normalizedDiagram}`; + console.log("Method 3 (preserve hint):", method3); + + // Let's try method 2 first (pipe separator) + return { rawDsl: method2 }; + } + + // Convert other types to single line with semicolons + const convertibleTypes = ['graph', 'flowchart', 'sequenceDiagram', 'pie', 'gitGraph']; + + if (convertibleTypes.some(type => firstWord.startsWith(type))) { + const lines = normalizedDiagram.split('\n'); + const firstLine = lines[0]; + const remainingLines = lines.slice(1) + .filter(line => line.trim()) + .map(line => line.trim()); + + const singleLine = firstLine + '; ' + remainingLines.join('; '); + console.log("Converted to single line:"); + console.log(singleLine); + + return { rawDsl: singleLine }; + } + + // For other non-convertible types, use NEWLINE encoding + const encodedDiagram = normalizedDiagram.replace(/\n/g, ' NEWLINE '); + console.log("Using NEWLINE encoding:"); + console.log(encodedDiagram); + + return { rawDsl: encodedDiagram }; +}; diff --git a/internal/diagram.go b/internal/diagram.go index 08d6535..3779a6d 100644 --- a/internal/diagram.go +++ b/internal/diagram.go @@ -28,6 +28,13 @@ func NewDiagram(description []byte, imgType string) *Diagram { fmt.Printf("DEBUG: Now contains newlines: %t\n", strings.Contains(trimmed, "\n")) } + // Decode pipe separators back to newlines for quadrant charts + if strings.Contains(trimmed, " | ") { + trimmed = strings.ReplaceAll(trimmed, " | ", "\n") + fmt.Printf("DEBUG: After pipe decoding: %q\n", trimmed) + fmt.Printf("DEBUG: Now contains newlines: %t\n", strings.Contains(trimmed, "\n")) + } + return &Diagram{ description: []byte(trimmed), lastTouched: time.Now(), diff --git a/quadrant_chart_examples.md b/quadrant_chart_examples.md new file mode 100644 index 0000000..1f509d4 --- /dev/null +++ b/quadrant_chart_examples.md @@ -0,0 +1,69 @@ +# Quadrant Chart Examples (Fixed) + +These examples should work correctly with the updated conversion script that treats quadrant charts as convertible types: + +## 1. Simple Business Priority Matrix +``` +quadrantChart + title Business Priorities + x-axis Low Effort --> High Effort + y-axis Low Impact --> High Impact + quadrant-1 Do First + quadrant-2 Schedule + quadrant-3 Delegate + quadrant-4 Eliminate + Task A: [0.3, 0.9] + Task B: [0.7, 0.7] + Task C: [0.2, 0.3] + Task D: [0.8, 0.2] +``` + +## 2. Product Analysis +``` +quadrantChart + title Product Analysis + x-axis Low Cost --> High Cost + y-axis Low Value --> High Value + quadrant-1 Quick Wins + quadrant-2 Strategic + quadrant-3 Fill-ins + quadrant-4 Questionable + Product A: [0.2, 0.8] + Product B: [0.8, 0.9] + Product C: [0.3, 0.2] + Product D: [0.7, 0.3] +``` + +## 3. Technology Assessment +``` +quadrantChart + title Technology Stack + x-axis Low Complexity --> High Complexity + y-axis Low ROI --> High ROI + quadrant-1 Adopt + quadrant-2 Trial + quadrant-3 Assess + quadrant-4 Hold + React: [0.3, 0.8] + Vue: [0.2, 0.7] + Angular: [0.8, 0.6] + jQuery: [0.1, 0.2] +``` + +## How This Will Convert: + +**Input (multiline):** +``` +quadrantChart + title Business Priorities + x-axis Low Effort --> High Effort + y-axis Low Impact --> High Impact + quadrant-1 Do First +``` + +**Output (single line with semicolons):** +``` +quadrantChart; title Business Priorities; x-axis Low Effort --> High Effort; y-axis Low Impact --> High Impact; quadrant-1 Do First +``` + +This should fix the text rendering issue where quadrant labels were getting concatenated! diff --git a/updated_conversion_script.js b/updated_conversion_script.js new file mode 100644 index 0000000..c226278 --- /dev/null +++ b/updated_conversion_script.js @@ -0,0 +1,52 @@ +// Updated smart mermaid conversion script with quadrantChart fix +export const code = async (inputs) => { + const raw = String(inputs.diagram || "").trim(); + if (!raw) throw new Error("No Mermaid input provided"); + + // Normalize line endings first + let normalizedDiagram = raw + .replace(/\r\n/g, '\n') // Convert Windows line endings + .replace(/\r/g, '\n'); // Convert old Mac line endings + + console.log("Original diagram:"); + console.log(normalizedDiagram); + + // Check if it's already single line + if (!normalizedDiagram.includes('\n')) { + console.log("Already single line, returning as-is"); + return { rawDsl: normalizedDiagram }; + } + + // Convert multiline to single line with semicolons + // Added quadrantChart to convertible types to fix the text rendering issue + const convertibleTypes = ['graph', 'flowchart', 'sequenceDiagram', 'pie', 'gitGraph', 'quadrantChart']; + const firstWord = normalizedDiagram.split(/\s+/)[0]; + + if (convertibleTypes.some(type => firstWord.startsWith(type))) { + // Convert newlines to semicolons, preserving the first line structure + const lines = normalizedDiagram.split('\n'); + const firstLine = lines[0]; + const remainingLines = lines.slice(1) + .filter(line => line.trim()) // Remove empty lines + .map(line => line.trim()); // Remove indentation + + const singleLine = firstLine + '; ' + remainingLines.join('; '); + + console.log("Converted to single line:"); + console.log(singleLine); + + return { rawDsl: singleLine }; + } + + // For non-convertible types (journey, stateDiagram, classDiagram), + // try replacing newlines with specific delimiters that might work + console.log("Non-convertible type detected, using special encoding"); + + // Try using a special marker that we can detect and replace on server side + const encodedDiagram = normalizedDiagram.replace(/\n/g, ' NEWLINE '); + + console.log("Encoded diagram:"); + console.log(encodedDiagram); + + return { rawDsl: encodedDiagram }; +};