Comments (7)
do you have a suggested fix?
What Go version did you build the library with?
What version of Chrome are you seeing the error?
from svgo.
As a quick fix I just added a space before each attribute, but looking at the code, you'd likely want to do a somewhat more elegant refactor.
I'm on the latest versions of everything: Go 1.9; Chrome 61.0.3163.91 (64-bit) -- but also on Chrome 60.0.3112.113 I get the same issues.
My system is Mac OS X 10.11.6.
from svgo.
As additional info: FireFox 55.0.3 has the same behaviour, as does Safari 11.0 (11604.1.38.1.7)
from svgo.
Note that the variadic arguments were designed to be the name="value" type. The use case is to use the variadic type if the style= type is not sufficient. (this is what you get if you simply use a single argument.
Try this:
package main
import (
"os"
"github.com/ajstarks/svgo"
)
func main() {
canvas := svg.New(os.Stdout)
width, height := 600, 600
canvas.Start(width, height)
canvas.Rect(0, 0, width, height, "fill:red")
canvas.Text(200, 150, "Some Text", `font-size="48px"`, `fill="#ababab"`)
canvas.Text(200, 100, "More Text", `font-size="48px"`, `fill="white"`)
canvas.End()
}
from svgo.
Sure, I understand the issue doesn't show up if you supply just regular attributes, but this is not enforced in any way. I guess the main problem is that you automatically create a style
attribute, so if something like font-size:48px
is given, this will produce: style="font-size:48px"
.
Perhaps a better approach would be not to do that auto convert, and if a user wishes to use the style
attribute they would have to specify it directly like so:
canvas.Text(200, 150, "Some Text", `style="font-size:48px;fill:blue;"`)
from svgo.
...although maybe a better approach would be to accept a map
instead of just a plain old string
:
map[string]string{
"font-size": "48px",
"fill": "#ababab",
}
This would make it very obvious what was expected.
Just some thoughts.
from svgo.
Not doing the auto convert would break a lot of code. In fact the auto style= was meant as a shorthand because most of the time it was sufficient, and the variadic case was for when you needed complete control.
There may be better ways, but I'm afraid I'm stuck with it now. Perhaps as you suggest better error handing of the variadic case would help.
from svgo.
Related Issues (20)
- Including units and floating point values HOT 2
- Just Want to Say Thank You HOT 1
- Pdf to SVG HOT 1
- Pdf to SVG HOT 1
- Add <title> to individual element? HOT 2
- Defining marker orientation HOT 4
- Potential code quality issues found
- Getting the getComputedTextLength() HOT 2
- Please add module support! HOT 2
- Requesting support for tspan HOT 4
- rotate(deg, cx, cy) HOT 1
- Support importing a svg into the SVG object HOT 4
- add method
- html to svg HOT 1
- Dead link to SVGo Paper HOT 1
- Add method for rotation around the center
- Please add LICENSE HOT 3
- Textlength attribute on Text HOT 1
- Help drawing a vertical text? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svgo.