feat: support importing obsidian.md files

This commit is contained in:
dwelle 2024-07-19 10:33:53 +02:00
parent df8875a497
commit 93c33fef20
4 changed files with 26 additions and 4 deletions

View file

@ -123,10 +123,26 @@ export const loadSceneOrLibraryFromBlob = async (
fileHandle?: FileSystemHandle | null,
) => {
const contents = await parseFileContents(blob);
let data;
// assume Obsidian excalidraw plugin file
if (blob.name?.endsWith(".excalidraw.md")) {
if (contents.indexOf("```compressed-json") > -1) {
let str = contents.slice(
contents.indexOf("```compressed-json") + '"```compressed-json'.length,
);
str = str.slice(0, str.indexOf("```"));
str = str.replace(/\n/g, "").replace(/\r/g, "");
const LZString = await import("lz-string");
data = JSON.parse(LZString.decompressFromBase64(str));
}
}
try {
try {
data = JSON.parse(contents);
data = data || JSON.parse(contents);
} catch (error: any) {
if (isSupportedImageFile(blob)) {
throw new ImageSceneDataError(

View file

@ -72,6 +72,7 @@
"image-blob-reduce": "3.0.1",
"jotai": "1.13.1",
"lodash.throttle": "4.1.1",
"lz-string": "1.5.0",
"nanoid": "3.3.3",
"open-color": "1.9.1",
"pako": "1.0.11",