Reputation: 153
I'm trying to insert an SVG in my pug template but doesn't work properly. I'm using r6operators from marcopixel which offer a function operator.toSVG() which returns the XML string of an SVG.
When I do this :
p some text #{operator.name}
#{operator.toSVG()}
I get the image correctly but < and > staying around:
<p>some text Gridlock<<svg --- all the SVG content >
</p>
if I try to put it in an SVG line like :
p some text #{operator.name}
svg #{operator.toSVG()}
I get something like :
<p> some text</p>
<svg>"<svg ---all the content</svg>"</svg>
I checked for some mixin templates or the SVG use but they take a href and not a string
Upvotes: 0
Views: 598
Reputation: 8540
If operator.toSVG()
returns <svg>...</svg>
, you have a couple of options:
Use piped text and unescaped string interpolation:
- const operator = { name: 'Gridlock', toSVG: () => '<svg>...</svg>' }
p some text #{operator.name}
| !{operator.toSVG()}
- const operator = { name: 'Gridlock', toSVG: () => '<svg>...</svg>' }
p some text #{operator.name}
!= operator.toSVG()
Use a mix of options 1 and 2:
- const operator = { name: 'Gridlock', toSVG: () => '<svg>...</svg>' }
p
| some text #{operator.name}
!= operator.toSVG()
Result in all three cases:
<p>some text Gridlock<svg>...</svg></p>
Two variations:
- const operator = { name: 'Gridlock', toSVG: () => '<svg>...</svg>' }
p
| some text #{operator.name}
| !{operator.toSVG()}
- const operator = { name: 'Gridlock', toSVG: () => '<svg>...</svg>' }
p.
some text #{operator.name}
!{operator.toSVG()}
Result in both cases (notice the difference in whitespace):
<p>some text Gridlock
<svg>...</svg></p>
Upvotes: 2