zsviczian / obsidian-excalidraw-plugin

A plugin to edit and view Excalidraw drawings in Obsidian
4.02k stars 217 forks source link

Script to parse and split text element by functions (not by lines) #717

Open 7flash opened 2 years ago

7flash commented 2 years ago

Is your feature request related to a problem? Please describe. My workflow to understand any codebase involves using Excalidraw. Basically, I do copy-paste all the code from repository into my canvas and then move parts around until it makes sense to me. Thinking about the ways to automatize this proces..

Describe the solution you'd like I would like to have a script that allows me to select a text element and then it will separate it into multiple text elements each containing single function. Similar how it's done by another script separating text into lines. Possible future enhancements..

Describe alternatives you've considered Extrenal tools to pre-process code and generate excalidraw documents

Additional context Context: https://github.com/excalidraw/excalidraw/issues/5299

7flash commented 2 years ago

Consider as example codebase of this repository itself.. This how I can see it now.. I wish it would be rather simplified and show me outline of each file linked to the actual file.. but that's for next step..

image

zsviczian commented 2 years ago

This sounds like a nice script challenge! Why don't you look at the split text by line script and see if you can write this script on your own?

7flash commented 7 months ago

Currently I am doing annotations of my code files into segments with special comments

For example given this file,

file.test.ts

import { assertEquals } from "https://deno.land/std@0.216.0/assert/mod.ts";

//.second
Deno.test("second", () => {
    const xit = '{"elements": [{ "text": "first" }]}';
    const ixit = new Function(`return ${JSON.stringify(xit)}`);
    const xixit = ixit.call(null);
    assertEquals(xixit, xit);
});

//.double-backslash
Deno.test("fifth", () => {
    const str = "it \\n";
    const text = str.replace(/\\n/g, '\\\\n');
    const ixit = new Function(`return {"elements": [{ "text": "${text}" }]}`);
    const xixit = ixit.call(null);
    assertEquals(xixit.elements[0].text, "it \\n");
});

I can reference particular section like

path = file://file.test.ts#double-backslash

Using following regexp pattern:

            _, selector = path.split('#')
            if file_extension == ".py":
                comment_symbol = "#"
            else:
                comment_symbol = "//"
            pattern = fr'({re.escape(comment_symbol)}\s?\.{re.escape(selector)}\n)(.*?(?={re.escape(comment_symbol)}\s?\.|Z))'