@@ -28,12 +28,15 @@ type textEdge struct {
2828}
2929
3030func parseNode (line string ) textNode {
31+ // Trim any whitespace from the line that might be left after comment removal
32+ trimmedLine := strings .TrimSpace (line )
33+
3134 nodeWithClass , _ := regexp .Compile (`^(.+):::(.+)$` )
3235
33- if match := nodeWithClass .FindStringSubmatch (line ); match != nil {
34- return textNode {match [1 ], match [2 ]}
36+ if match := nodeWithClass .FindStringSubmatch (trimmedLine ); match != nil {
37+ return textNode {strings . TrimSpace ( match [1 ]), strings . TrimSpace ( match [2 ]) }
3538 } else {
36- return textNode {line , "" }
39+ return textNode {trimmedLine , "" }
3740 }
3841}
3942
@@ -167,7 +170,32 @@ func (gp *graphProperties) parseString(line string) ([]textNode, error) {
167170func mermaidFileToMap (mermaid , styleType string ) (* graphProperties , error ) {
168171 // Allow split on both \n and the actual string "\n" for curl compatibility
169172 newlinePattern := regexp .MustCompile (`\n|\\n` )
170- lines := newlinePattern .Split (string (mermaid ), - 1 )
173+ rawLines := newlinePattern .Split (string (mermaid ), - 1 )
174+
175+ // Process lines to remove comments
176+ lines := []string {}
177+ for _ , line := range rawLines {
178+ // Stop processing at "---" separator (used in test files)
179+ if line == "---" {
180+ break
181+ }
182+
183+ // Skip lines that start with %% (comment lines)
184+ if strings .HasPrefix (strings .TrimSpace (line ), "%%" ) {
185+ continue
186+ }
187+
188+ // Remove inline comments (anything after %%) and trim resulting whitespace
189+ if idx := strings .Index (line , "%%" ); idx != - 1 {
190+ line = strings .TrimSpace (line [:idx ])
191+ }
192+
193+ // Skip empty lines after comment removal
194+ if len (strings .TrimSpace (line )) > 0 {
195+ lines = append (lines , line )
196+ }
197+ }
198+
171199 data := orderedmap .NewOrderedMap [string , []textEdge ]()
172200 styleClasses := make (map [string ]styleClass )
173201 properties := graphProperties {data , & styleClasses , "" , styleType }
0 commit comments