CodeblockCustomizer icon indicating copy to clipboard operation
CodeblockCustomizer copied to clipboard

Feature Request: Compatibility with execute code plugin

Open aelmoghit opened this issue 4 months ago • 11 comments

Hello, Thanks for this amazing plugin, it’s really great!

But there’s a compatibility problem with the Execute Code plugin — they don’t work together. Execute Code plugin works perfectly with default Obsidian code blocks, and I’ve tried Code Styler, which supports Execute Code, so I think it might be possible to add support.

Thanks!

aelmoghit avatar Aug 26 '25 01:08 aelmoghit

I can take a look, but please be more specific. What exactly do you mean by "they don't work together"? And what is the "compatibility problem"? Do you want the output of execute code plugin to be styled?

mugiwara85 avatar Aug 26 '25 02:08 mugiwara85

Errors I'm encountering:

  • The Run button doesn't appear most of the time.
  • When it does appear, I get an error message in the console.

Codeblock Customizer: Image

Compared to

Default Obsidian codeblock : Image

Code Styler plugin: Image

aelmoghit avatar Aug 26 '25 03:08 aelmoghit

Ok, I'll check it out, but it may take some time. I try to be as fast as possible though. I'll get back to you when you can "beta-test" something.

mugiwara85 avatar Aug 26 '25 11:08 mugiwara85

@aelmoghit just a quick update. Reading mode is almost done.

https://github.com/user-attachments/assets/f585a713-ae22-4d84-a7d8-3252f9066f94

mugiwara85 avatar Aug 31 '25 23:08 mugiwara85

@aelmoghit I added execute code plugin compatibility. Please test is as soon as possible, because I am preparing for the next release. There is a new settings page "Plugin Compatibility" where I added 1-2 settings. You can highlight lines and text in the output as well with "o" suffix.

  • hl:5 -> highlights line 5 in code
  • hlt:test -> highlights the word text in the code
  • hlo:5 -> highlights line 5 in the code output
  • hlto:test -> highlights the word text in the code output

Basically you can use all your normal and alternative highlights colors for line and text highlight, just need to add that "o" to specify that it should be highlighted in the output. Every feedback appreaciated!

mugiwara85 avatar Sep 15 '25 19:09 mugiwara85

First, thank you for all your hard work on this plugin.

I was testing the latest beta version 3aca1fe and encountered the following errors:

  1. Missing Execution Button: If I close Obsidian while in Reading view and later reopen it, the execution button (▶️) for code blocks is often missing. To restore it, I have to switch to Source view and then restart Obsidian.
  2. Execution Failure with hlo: When I use the hlo command to highlight output in a code block, the execution sometimes fails silently (no output is produced). When I remove the hlo command and run the exact same code, the output is displayed correctly and reveals the actual errors from the code itself, although the code is valid and runs fine without hlo.

Image

aelmoghit avatar Sep 16 '25 19:09 aelmoghit

Thanks for testing! I think I can explain both of these.

  • Exception failure: Yes, you are right that this happens. This is a bit complex, but the problem is when you change the hlo (or any other) parameter, then you basically trigger a rerender in reading view. This is how in case of normal code blocks, when you change a parameter and then switch to readingview, the parameter change is immediately shown, because the code block was triggered to redraw. The problem is that the execute code plugin adds an event listener for their run and clear buttons, and when you change a parameter you trigger a rerender, and this results that the clickhandler for the original run button is lost. Well, to be precise, it is not lost, but it is not attached to the newly rerendered code block. Thats why it fails. Unfortunately, I couldn't find a way to "reattach" it. So you have two choices here: 1. When you change a parameter, change something on the code as well (add a space, or remove one. anything). This would trigger Obsidians rerender which would then correctly have the event listener. 2. You have to switch documents to make it fresh. I know about this, but as I said, I couldnt find a solution for now. If I don't find one, this might be a limitation, and remain as it is.
  • Missing button: The execute button is only added when the original run button from execute code is present. This is actually a bug from Execute Code (which has a few as I noticed), which has an effect on my plugin. I also noticed this behavior, but actually the same happens when you disable my plugin. You can simply verify it, be opening a document in reading mode, then closing and reopening Obsidian, and you'll see, that the original run button is missing. If you inspect the html of that code block you will see that a run-button is not present:
Image

This I cannot fix, as the original run button is required to make everything work. If it is not present, but I would still show my button, you'll get an error.

Please verify the run button behavior, not that I missed something, but in my case the behavior was as written above. The parameter change I will investigate later once more, but I am not sure, if there is a solution, so as I said, it might remain a limitation. Aside from these two things, did you find anything else? Were there maybe any errors in the console? Or generally did everything work?

mugiwara85 avatar Sep 16 '25 19:09 mugiwara85

Thank you for looking into this so quickly.

  1. When you change a parameter, change something on the code as well (add a space, or remove one. anything). This would trigger Obsidians rerender which would then correctly have the event listener.

When I tried this solution everything worked fine.

This is actually a bug from Execute Code (which has a few as I noticed), which has an effect on my plugin. I also noticed this behavior, but actually the same happens when you disable my plugin.

I didn't encounter the same problem you did when Codeblock Customizer is disabled, the execution button behaves correctly after a restart Obsidian. The issue only occurs when the plugin is enabled.

Image

aelmoghit avatar Sep 16 '25 20:09 aelmoghit

Thanks, for testing. I will look into the missing button again. BTW, did you notice that when you create a "run-" codeblock in editing mode, you have syntaxhighlighting? :)

mugiwara85 avatar Sep 16 '25 20:09 mugiwara85

Yes I noticed that it's awesome.

aelmoghit avatar Sep 16 '25 21:09 aelmoghit

@aelmoghit Sorry for the late reply, but I could fix both problems. Could you please retest again, if you encounter the previous or any other problems? Please give a feedback if it works or not!

mugiwara85 avatar Oct 28 '25 21:10 mugiwara85