obsidian-execute-code icon indicating copy to clipboard operation
obsidian-execute-code copied to clipboard

@show / Python - invalid syntax (<code block>)

Open luckman212 opened this issue 1 year ago • 5 comments

macOS 15.3.1 + Obsidian 1.8.9

I am trying a simple @show example, not sure if this is a regression since 2.1.0 since I am pretty sure it worked before!

import os
catimg = '/'.join([@vault_path,'attach',@title,'cat.png'])
print(f'path:{catimg}\nexists:{os.path.exists(catimg)}')

result:

path:/Users/luke/Sync/Obsidian/Main/attach/Obsidian Execute Code plugin/cat.png
exists:True
import os
catimg = '/'.join([@vault_path,'attach',@title,'cat.png'])
print(f'path:{catimg}\nexists:{os.path.exists(catimg)}')
@show(catimg, 25%, 25%, left)

result:

invalid syntax (<code block>, line 10)
Image

luckman212 avatar Feb 25 '25 14:02 luckman212

Hi, I think the problem was the extra "/" that was introduced by concatenating the app line ("app://..../") and the image link ("/some/path/..."). I don't have a mac and can't test this. Can you please update the plugin (v 2.1.2) and tell me if it worked?

Also: Can you try creating a plot to see if it shows up correctly? e.g., like this:

import matplotlib.pyplot as plt
import numpy

x = numpy.array(list(range(10)))  
y = numpy.sin( x ) 

plt.plot( x , y )
plt.show()

This is related to #405

twibiral avatar Mar 01 '25 16:03 twibiral

Thanks for looking 🙏 - I will test 2.1.2 as soon as I get home.

luckman212 avatar Mar 01 '25 18:03 luckman212

matplotlib test was a success...

Image

but cat img test is still saying invalid syntax (<code block>, line 7)

Image

luckman212 avatar Mar 01 '25 22:03 luckman212

@luckman212 Okay, I have no clue why it doesn't work.... can you go to the developer view (ctrl+i for windows) and select the code block output. There should be some html code that isn't rendered correctly. Maybe this can help me understand the problem better.

It's working perfectly on my machine, so unfortunately I cannot check it myself...

twibiral avatar Mar 02 '25 14:03 twibiral

I tried a small variation as well, it still gives me invalid syntax (<code block>, line 7) error:

import os
a = "{}/attach/{}".format(@vault_path,@title)
catimg = os.path.join(a,'cat.png')
@show(catimg, 25%, 25%, left)

I don't see any code (invalid or otherwise) in the Dev Tools console... is there a setting I need to enable to show the generated code that the plugin is trying to execute?

luckman212 avatar Mar 02 '25 15:03 luckman212