Reference · Draw a bracket, a table or a road to the final
cleanSvgfunction
Takes inline SVG markup from a caller and makes it safe to put inside a drawing: the outer <svg>'s viewBox is kept,
and scripts, event handlers, <style>, <foreignObject>, comments and javascript: addresses are removed. Returns the
viewBox and the inner markup, or null when it is not an <svg>.
Import it
import { cleanSvg } from "@johnmorrisdotca/taisen-brackets";
Definition
function cleanSvg(markup: string): { viewBox: string; inner: string; } | null
Parameters
| Name | Type | Description |
|---|---|---|
markup | string | The SVG text of a team's mark. |
Returns
{ viewBox: string; inner: string; } | null
The view box and the inner markup with scripts, events and external references removed; null when the text is not an <svg>.
Examples
import { cleanSvg } from "@johnmorrisdotca/taisen-brackets";
console.log(cleanSvg('<svg viewBox="0 0 10 10" onload="alert(1)"><script>alert(1)</script><circle cx="5" cy="5" r="4"/></svg>'), cleanSvg("not svg"));{ viewBox: '0 0 10 10', inner: '<circle cx="5" cy="5" r="4"/>' } nullWhat it prints (run when this page was built)