diff --git a/MathjaxToSVG/index.ts b/MathjaxToSVG/index.ts index 726e926..f5777d9 100644 --- a/MathjaxToSVG/index.ts +++ b/MathjaxToSVG/index.ts @@ -15,9 +15,15 @@ let html: any; let preamble: string; function svgToBase64(svg: string): string { - return `data:image/svg+xml;base64,${btoa( - decodeURIComponent(encodeURIComponent(svg.replaceAll(" ", " "))), - )}`; + const cleanSvg = svg.replaceAll(" ", " "); + + // Convert the string to UTF-8 and handle non-Latin1 characters + const encodedData = encodeURIComponent(cleanSvg) + .replace(/%([0-9A-F]{2})/g, + (match, p1) => String.fromCharCode(parseInt(p1, 16)) + ); + + return `data:image/svg+xml;base64,${btoa(encodedData)}`; } async function getImageSize(src: string): Promise<{ height: number; width: number }> { diff --git a/src/ExcalidrawView.ts b/src/ExcalidrawView.ts index 05b7e43..c4081e3 100644 --- a/src/ExcalidrawView.ts +++ b/src/ExcalidrawView.ts @@ -1925,7 +1925,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ //onClose happens after onunload protected async onClose(): Promise { (process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.onClose,`ExcalidrawView.onClose, file:${this.file?.name}`); - + this.exitFullscreen(); await this.forceSaveIfRequired(); if (this.excalidrawRoot) { this.excalidrawRoot.unmount(); diff --git a/src/utils/CropImage.ts b/src/utils/CropImage.ts index d15f13f..24fbaa4 100644 --- a/src/utils/CropImage.ts +++ b/src/utils/CropImage.ts @@ -7,6 +7,7 @@ import { getEA } from "src"; import { ExcalidrawAutomate, cloneElement } from "src/ExcalidrawAutomate"; import { ExportSettings } from "src/ExcalidrawView"; import { nanoid } from "src/constants/constants"; +import { svgToBase64 } from "./Utils"; export class CropImage { private imageEA: ExcalidrawAutomate; @@ -170,7 +171,7 @@ export class CropImage { 1 // image quality (0 - 1) ); }; - image.src = `data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(svgData)))}`; + image.src = svgToBase64(svgData); }); } diff --git a/src/utils/FileUtils.ts b/src/utils/FileUtils.ts index 01b66e4..5f566a7 100644 --- a/src/utils/FileUtils.ts +++ b/src/utils/FileUtils.ts @@ -350,7 +350,9 @@ export const getInternalLinkOrFileURLLink = ( const vault = plugin.app.vault; const fileURLString = vault.adapter.url.pathToFileURL(path).toString(); if (fileURLString.startsWith(VAULT_BASE_URL())) { - const internalPath = normalizePath(unescape(fileURLString.substring(VAULT_BASE_URL().length))); + const internalPath = normalizePath( + decodeURIComponent(fileURLString.substring(VAULT_BASE_URL().length)) + ); const file = vault.getAbstractFileByPath(internalPath); if(file && file instanceof TFile) { const link = plugin.app.metadataCache.fileToLinktext( diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 1bd38a3..e9d3b68 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -230,11 +230,17 @@ export function base64StringToBlob (base64String: string, mimeType: string): Blo return new Blob([buffer], { type: mimeType }); }; -export function svgToBase64 (svg: string): string { - return `data:image/svg+xml;base64,${btoa( - unescape(encodeURIComponent(svg.replaceAll(" ", " "))), - )}`; -}; +export function svgToBase64(svg: string): string { + const cleanSvg = svg.replaceAll(" ", " "); + + // Convert the string to UTF-8 and handle non-Latin1 characters + const encodedData = encodeURIComponent(cleanSvg) + .replace(/%([0-9A-F]{2})/g, + (match, p1) => String.fromCharCode(parseInt(p1, 16)) + ); + + return `data:image/svg+xml;base64,${btoa(encodedData)}`; +} export async function getBinaryFileFromDataURL (dataURL: string): Promise { if (!dataURL) {