zsviczian / obsidian-excalidraw-plugin

A plugin to edit and view Excalidraw drawings in Obsidian
4.11k stars 226 forks source link

FR: Allow some customization of the excalidraw markdown before reading and before saving #1731

Closed ramarivera closed 5 months ago

ramarivera commented 6 months ago

Is your feature request related to a problem? Please describe. I saw Nicole's last video (https://www.youtube.com/watch?v=zmgqMZi6QL8&ab_channel=NicolevanderHoeven) and it made me want to create some visual note template. The problem I found with this approach is that I always end up with at least 2 heading 1 in my notes: Text Elements and Drawings. Ideally, I would love to be able to add a # Excalidraw section, and put those two elements as headings 2 inside of it, but this breaks excalidraw. I also tried putting all of excalidraw generated md content inside a code block with 4 backticks or tildes, but while it works for the most part, excalidraw always removes the last line (```` or \~\~\~\~) so it feels fragile. I also tried putting all of excalidraw generated markdown inside a callout (so, each line starts with >), while this works very nicely in the textual note, it expectedly breaks excalidraw drawing 😅

Describe the solution you'd like I would be happy with something as simple as being able to set, via setting, the excalidraw heading level used. I would be super happy, with a very advanced setting, that allows me to provide 2 JS functions, one that is executed when excalidraw tries to read my markdown content (so, I could remove my specific textual content, e.g. reduce the heading levels or remove the callout >), and an inverse one before it saves (so, I could add my specific textual content)

Describe alternatives you've considered Described before

I completely understand this is an absolutely niche request, but I would also be happy to implement it and raise a PR if you agree with the very niche request 😅

Thanks for the amazing work that goes into obsidian excalidraw!!

ramarivera commented 6 months ago

For reference, this is the closest I came to it with my current templater template

<%* 
  const noteName = await tp.system.prompt("Note name?");
_%>
---
title: <% noteName %>
excalidraw-open-md: true
excalidraw-plugin: parsed
tags:
  - excalidraw
---

# <% noteName %>

# Excalidraw

> [!note]+ Excalidraw section of the note
> Do not write anything past this point, as it is managed by Excalidraw

```` <-- this line prevents obsidian from processing the headers as headers, and since it doesn't insert anything before each line, then excalidraw is happy and ignores it
# Text Elements
%%
# Drawing
```json
{
    "type": "excalidraw",
    "version": 2,
    "source": "https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/2.1.4",
    "elements": [],
    "appState": {
        "theme": "dark",
        "viewBackgroundColor": "#fffce8",
        "currentItemStrokeColor": "#1e1e1e",
        "currentItemBackgroundColor": "transparent",
        "currentItemFillStyle": "solid",
        "currentItemStrokeWidth": 2,
        "currentItemStrokeStyle": "solid",
        "currentItemRoughness": 1,
        "currentItemOpacity": 100,
        "currentItemFontFamily": 1,
        "currentItemFontSize": 20,
        "currentItemTextAlign": "left",
        "currentItemStartArrowhead": null,
        "currentItemEndArrowhead": "arrow",
        "scrollX": 604.671875,
        "scrollY": 680.5390625,
        "zoom": {
            "value": 1
        },
        "currentItemRoundness": "round",
        "gridSize": null,
        "gridColor": {
            "Bold": "#FFEE7DFF",
            "Regular": "#FFF7C4FF"
        },
        "currentStrokeOptions": null,
        "previousGridSize": null,
        "frameRendering": {
            "enabled": true,
            "clip": true,
            "name": true,
            "outline": true
        }
    },
    "files": {}
}
```
%%
```` <-- this line will get removed by excalidraw every time I go into visual mode so to speak
zsviczian commented 5 months ago

sorry - I will not even consider changing the file format as it creates unpredictable backward compatibility issues.

As Nicole also shows you can place a markdown comment before text elements and select the fade out options from the Misc settings.

ramarivera commented 5 months ago

Thanks, that's a very valid rationale

zsviczian commented 5 months ago

It turns backwards compatibility is not such a huge issue... you can install 2.1.8.1-beta-1 using BRAT. Please join the visual thinking discord to discuss the beta.

https://discord.com/channels/1026825302900494357/1076960836901417092/1240019285808513034