transform.Remarshal for SVG generation?


I would like to expand small SVG icons into slightly larger SVGs with the help of Hugo’s methods. I can see two general ways to go about this:

  1. Use string manipulation methods on the SVG string to decompose it and add my stuff also with string methods. Take care of the appropriate SVG structure myself.

  2. Use transform.Unmarshal to parse the SVG as XML into a data structure and add my stuff there. Use transform.Remarshal to assemble the new SVG from the altered data structure.

The second way should be the more flexible and elegant one, but I’m worried about the warning which comes with transform.Remarshal. It is not intended as a general transformation tool and may be unreliable, says the documentation.

Until now, I’ve been using transform.Remarshal only to show debugging information and never had any problems. But I wonder, should I better stick to the first way and avoid transform.Remarshal for production template code?

Many thanks,

Please let me know if/where the word “unreliable” is used. The documented caveat is:

This function is primarily a helper for Hugo’s documentation, used to convert configuration and front matter examples to JSON, TOML, and YAML.

This is not a general purpose converter, and may change without notice if required for Hugo’s documentation site.

This template function has not changed in a very long time. I guess it’s a bit of a gamble to use it, but based on history it seems safe-ish.

“Unreliable” was only my sloppy interpretation of this paragraph.

Thanks a lot!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.