Search code examples
svgcommentsblock-comments

How do you make a block comment in SVG


I'm trying to learn SVG for the first time but the code seems to have an issue with my block comments. I'm using:

/* This is my
 * block comment
 */

And when I run my code, I get the following error:

'return' statement outside of function
line: 116, column: 4

That so happens to be immediately before my block comment.


Solution

  • As SVG is XML, you can use XML style comments:

    <!-- 
        comment 
    -->
    

    For example:

    <g onclick = "setScale(1)">
        <rect id = "scale1" x = "120" y = "10" width = "30" height = "30"
            fill = "#ffc" stroke = "black"/>
        <!-- 
            this text describes middle rectangle
        -->
        <text x = "135" y = "30" text-anchor = "middle">M</text>
    </g>
    

    Or you can exclude some part of code:

    <!--
         this group is disabled for testing    
    <g onclick = "setScale(1)">
        <rect id = "scale1" x = "120" y = "10" width = "30" height = "30"
            fill = "#ffc" stroke = "black"/>
        <text x = "135" y = "30" text-anchor = "middle">M</text>
    </g>
    -->