cleanSvg関数
リファレンスの説明と例は英語です。見出しと目次は日本語です。
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 { cleanSvg } from "@johnmorrisdotca/taisen-brackets";
定義
function cleanSvg(markup: string): { viewBox: string; inner: string; } | null
引数
| 名前 | 型 | 説明 |
|---|---|---|
markup | string | The SVG text of a team's mark. |
戻り値
{ 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>.
例
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"/>' } null出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。