mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
Merge pull request #2165 from zsviczian/2.7.1-beta-1
fixed unescape, decodeURIComponent issue with non-latin characters.
This commit is contained in:
@@ -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 }> {
|
||||
|
||||
@@ -1925,7 +1925,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
//onClose happens after onunload
|
||||
protected async onClose(): Promise<void> {
|
||||
(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();
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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<ArrayBuffer> {
|
||||
if (!dataURL) {
|
||||
|
||||
Reference in New Issue
Block a user