Skip to content

Commit

Permalink
Merge pull request #44 from dnnrly/bugfix/reverse-css
Browse files Browse the repository at this point in the history
Fix parsing css from SVG
  • Loading branch information
dnnrly committed Mar 5, 2024
2 parents 22dfd76 + bd4a5e6 commit 4aa40e9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions layli.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ func AbsoluteFromSVG(svg string, output OutputFunc) error {
continue
}

key, style, found := strings.Cut(strings.Trim(line, ""), " {")
key, style, found := strings.Cut(strings.Trim(line, " }"), " { ")
if !found {
return fmt.Errorf("cannot parse style line: %s", line)
}
config.Styles[key] = "{" + style
config.Styles[key] = style
}
}

Expand Down
6 changes: 3 additions & 3 deletions layli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestAbsoluteFromSvg(t *testing.T) {
<style type="text/css">
<![CDATA[
.class-1 { stroke-width:3; }
.class-2 { stroke:green; }
.class-2 { stroke:green; stroke-width:5; }
]]>
</style>
<g style="text-anchor:middle;font-family:sans;fill:none;stroke:black">
Expand Down Expand Up @@ -254,8 +254,8 @@ func TestAbsoluteFromSvg(t *testing.T) {
ConfigEdge{From: "c", To: "d"},
},
Styles: ConfigStyles{
".class-1": "{ stroke-width:3; }",
".class-2": "{ stroke:green; }",
".class-1": "stroke-width:3;",
".class-2": "stroke:green; stroke-width:5;",
},
})
})
Expand Down
8 changes: 8 additions & 0 deletions test/features/reverse.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ Feature: Image reveral
| id | x | y |
| node1 | 3 | 3 |
| node2 | 7 | 3 |

@Acceptance
Scenario: Can consume to-absolute converted layli file
When the app runs with parameters "tmp/fixtures/inputs/styles.layli"
Then the app exits without error
And the app runs with parameters "to-absolute tmp/fixtures/inputs/styles.svg -o tmp/styles-absolute.layli"
And the app runs with parameters "tmp/styles-absolute.layli"
Then the app exits without error

0 comments on commit 4aa40e9

Please sign in to comment.