b2a8a2f99e
This PR fixes two bugs causing HTML validators to complain. - Error: Bad value data:image/svg+xml;charset=utf-8, for attribute src on element img: Illegal character in scheme data: < is not allowed. - Fixed by using base64 for svg during `layout=intrinsic` to avoid angle brackets - Error: Element img is missing required attribute src. - Fixed by using base64 transparent gif for `loading=lazy` placeholder Fixes #18850
10 lines
236 B
TypeScript
10 lines
236 B
TypeScript
/**
|
|
* Isomorphic base64 that works on the server and client
|
|
*/
|
|
export function toBase64(str: string) {
|
|
if (typeof window === 'undefined') {
|
|
return Buffer.from(str).toString('base64')
|
|
} else {
|
|
return window.btoa(str)
|
|
}
|
|
}
|