added fallback

This commit is contained in:
2026-01-06 20:08:53 +11:00
parent 00936f74ce
commit c7098d51d8

View File

@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"html" "html"
"math" "math"
"os"
"regexp" "regexp"
"sort" "sort"
"strconv" "strconv"
@@ -27,6 +28,7 @@ type GliffyDiagramConverter struct {
} }
func NewGliffyDiagramConverter(gliffyDiagramString string) (*GliffyDiagramConverter, error) { func NewGliffyDiagramConverter(gliffyDiagramString string) (*GliffyDiagramConverter, error) {
customTrans := os.Getenv("GLIFFY_TRANSLATIONS_JSON")
c := &GliffyDiagramConverter{ c := &GliffyDiagramConverter{
diagramString: gliffyDiagramString, diagramString: gliffyDiagramString,
drawioDiagram: NewMxGraph(), drawioDiagram: NewMxGraph(),
@@ -35,7 +37,7 @@ func NewGliffyDiagramConverter(gliffyDiagramString string) (*GliffyDiagramConver
rotationPattern: regexp.MustCompile(`rotation=(\-?\w+)`), rotationPattern: regexp.MustCompile(`rotation=(\-?\w+)`),
pageIDPattern: regexp.MustCompile(`pageId=([^&]+)`), pageIDPattern: regexp.MustCompile(`pageId=([^&]+)`),
namePattern: regexp.MustCompile(`name=([^&]+)`), namePattern: regexp.MustCompile(`name=([^&]+)`),
translator: NewStencilTranslator(""), translator: NewStencilTranslator("").WithCustomMapping(customTrans),
} }
if err := c.start(); err != nil { if err := c.start(); err != nil {
return nil, err return nil, err
@@ -331,6 +333,9 @@ func (c *GliffyDiagramConverter) convertGliffyObject(obj *GliffyObject, parent *
isChevron := strings.Contains(obj.UID, "chevron") isChevron := strings.Contains(obj.UID, "chevron")
if translatedStyle != "" { if translatedStyle != "" {
style.WriteString("shape=" + translatedStyle + ";") style.WriteString("shape=" + translatedStyle + ";")
} else {
// Fallback if stencil translation is missing: render as a basic rect so the shape is visible.
style.WriteString("shape=rect;")
} }
if !strings.Contains(style.String(), "shadow=") { if !strings.Contains(style.String(), "shadow=") {
style.WriteString("shadow=" + intToString(boolToInt(shape.DropShadow)) + ";") style.WriteString("shadow=" + intToString(boolToInt(shape.DropShadow)) + ";")