ozntel / oz-image-in-editor-obsidian

This Obsidian plugin to view Images, Transclusions, iFrames and PDF Files within the Editor without a necessity to switch to Preview.
339 stars 13 forks source link

Excalidraw 1.2 compatibility #36

Closed zsviczian closed 3 years ago

zsviczian commented 3 years ago

Hi Ozan,

I am releasing Excalidraw 1.2 for alpha testing today. In this new version, I am moving away from the .excalidraw filetype. Drawings are stored in .md file. This opens up the opportunity to fully native integration into Obsidian.

I've created an ExcalidrawAutomate function to help identify if a file is an Excalidraw file. ExcalidrawAutomate.isExcalidrawFile(file:TFile):boolean

Here's how I think your script needs to be modified to be compatible with both Exalidraw 1.1.x and 1.2.x.

// @ts-ignore
if (app.plugins.getPlugin('obsidian-excalidraw-plugin') 
    && imageFile 
       && (filename.endsWith('excalidraw') 
           || (ExcalidrawAutomate.isExcalidrawFile 
               && ExcalidrawAutomate.isExcalidrawFile(imageFile)))) {
    // The file is an excalidraw drawing
    if (plugin.imagePromiseList.contains(imageFile.path)) return;
    plugin.addToImagePromiseList(imageFile.path);

    // @ts-ignore
    ExcalidrawAutomate.reset();

    // @ts-ignore
    image = await ExcalidrawAutomate.createPNG(imageFile.path);
...      
ozntel commented 3 years ago

Hi Zsolt,

I will try to do my best to integrate the new version but it might require a little bit more work since the files are going to have .md extension and they won't even enter into check_line function due to the image file extension regex versus the line text.

Are the drawings going to have format ![[drawing.md]] or ![[drawing]]?

I can handle with .md extension, but it might be hard to implement in the plugin without an extension.

zsviczian commented 3 years ago

Hi Ozan,

So your plugin currently displays the *.excalidraw.md files that are created by the migration script. The new Excalidraw files are simply markdown files with the .md extension.

Thanks, Zsolt

On Sat, Jul 3, 2021, 20:14 Ozan Tellioglu @.***> wrote:

Hi Zsolt,

I will try to do my best to integrate the new version but it might require a little bit more work since the files are going to have .md extension and they won't even enter into check_line function due to the image file extension regex versus the line text.

Are the drawings going to have format ![[drawing.md]] or ![[drawing]]?

I can handle with .md extension, but it might be hard to implement in the plugin without an extension.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ozntel/oz-image-in-editor-obsidian/issues/36#issuecomment-873448118, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADNRO6RKRFPO2Z2FW6MYXFTTV5HRHANCNFSM47YC2J3A .

ozntel commented 3 years ago

Hi Zsolt,

I understand that you want to keep the naming convention as .excalidraw.md

The problem will happen when the users remove the .excalidraw from the name and leave only as drawing.md. The drawings are still going to work within your plugin, however, they won't be rendered in Editor since I don't have an additional check for md files. Maybe you can mention that they should keep the naming convention, which is created after your migration script, to ensure that the files are supported in my plugin, too?

I will release the new version in a moment. I tried with the testing version and it works with .excalidraw.md for the moment.

Thanks, Ozan

zsviczian commented 3 years ago

Hi Ozan,

I do not wish to keep the naming convention as .excalidraw.md, this is simply a migration thing. I felt safest renaming files to .excalidraw.md to avoid file conflicts.

If you add .md to the RegExp in ImageHandler, and use the proposed logic in the original issue, does that not provide a universal solution... one that does not depend on file naming conventions?

Thanks for spending your time on this! Zsolt

zsviczian commented 3 years ago

Just as a further thought... based on your recommendation I have now modified my plugin to generate files following the .excalidraw.md naming convention... however, I don't want to enforce the file naming convention. I still think it would be best if Image in Editor could use isExcalidrawFile to check for Excalidraw files.

For now, however, since not everyone will upgrade to 1.2.x it is probably best to keep both in your logic, ie. in the ImageHandler RegExp filter for md|excalidraw and use the above proposed if logic to decide if a file is an excalidraw file.

Thanks!

ozntel commented 3 years ago

Since it includes md file check within the plugin, I added an option within the settings for Excalidraw drawings if the user wants them to be rendered in Editor or not.

The implementation I just added will work with markdown link format since it will include .md extension, however, wikilinks won't work since wikilinks doesn't require an extension to be provided for the links.

I will release it later today.

zsviczian commented 3 years ago

Thanks!

On Sun, Jul 4, 2021, 15:52 Ozan Tellioglu @.***> wrote:

Since it includes md file check within the plugin, I added an option within the settings for Excalidraw drawings if the user wants them to be rendered in Editor or not.

The implementation I just added will work with markdown link format since it will include .md extension, however, wikilinks won't work since wikilinks doesn't require an extension to be provided for the links.

I will release it later today.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ozntel/oz-image-in-editor-obsidian/issues/36#issuecomment-873595243, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADNRO6UJ3UFNKUS2ZJWGDCTTWBRQFANCNFSM47YC2J3A .

ozntel commented 3 years ago

Hi Zsolt,

I just released the version, which also renders .md files in case they are Excalidraw drawings.

I added a brief description here to ensure that the users are going to keep .md extension within the Wikilinks format. Then it should work properly.

https://github.com/ozntel/oz-image-in-editor-obsidian#excalidraw-view

Please let me know if you encounter any problems.

Thanks Ozan