mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: support importing obsidian.md
files
This commit is contained in:
parent
df8875a497
commit
93c33fef20
4 changed files with 26 additions and 4 deletions
|
@ -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(
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue