Compare commits

..

5 Commits

Author SHA1 Message Date
zsviczian
0c5ceaa3f7 fixed unescape, decodeURIComponent issue with non-latin characters.
exitFullscreen when closing the view.
2024-12-18 10:22:27 +00:00
zsviczian
2e602d49a2 Merge pull request #2163 from hackerESQ/master
Allow poorly formated .excalidraw files to render
2024-12-18 10:10:08 +01:00
hackerESQ
84bcdf8bee Merge pull request #1 from hackerESQ/enable-poorly-formatted-json-legacy-mode
Allow poorly formated .excalidraw files to render
2024-12-17 22:07:26 -06:00
hackerESQ
6d60bcf6eb Allow poorly formated .excalidraw files to render
There are several excalidraw implementations which fail to follow the defined excalidraw JSON schema. This allows those poorly formatted files to render in legacy mode in Obsidian.
2024-12-17 22:06:54 -06:00
zsviczian
b832a51a5b Merge pull request #2160 from zsviczian/2.7.0-bugs
Fix ROOTELEMENTSIZE calc, view switch timestamp logic, update global app refs, minify packages, fix FileManager init, add 2.7.0 notes
2024-12-17 18:01:02 +01:00
6 changed files with 27 additions and 12 deletions

View File

@@ -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 }> {

View File

@@ -518,7 +518,7 @@ export class ExcalidrawData {
return;
}
const saveVersion = this.scene.source.split("https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/")[1]??"1.8.16";
const saveVersion = this.scene.source?.split("https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/")[1]??"1.8.16";
const elements = this.scene.elements;
for (const el of elements) {

View File

@@ -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();

View File

@@ -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);
});
}

View File

@@ -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(

View File

@@ -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("&nbsp;", " "))),
)}`;
};
export function svgToBase64(svg: string): string {
const cleanSvg = svg.replaceAll("&nbsp;", " ");
// 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) {