Learn R Programming

cardargus (version 0.2.2)

sanitize_svg_for_raster: Sanitize SVG for rasterization engines (librsvg / ImageMagick)

Description

SVGs exported by editors such as Inkscape may contain sodipodi:* and/or inkscape:* nodes/attributes. If these namespace prefixes appear without the corresponding xmlns:* declarations, strict parsers (notably librsvg) can fail with errors like:

Namespace prefix sodipodi on namedview is not defined

This helper removes non-rendering metadata blocks and attributes commonly responsible for parse failures, producing a more interoperable SVG string. It also removes Google Fonts @import rules which are not supported by rasterization engines.

Usage

sanitize_svg_for_raster(svg_input)

Value

A character string containing a sanitized SVG.

Arguments

svg_input

An SVG string or an object coercible to character (e.g. htmltools::HTML).