ImageJ markdown error while imagej macro run perfectly for the same code

Hi @haesleinhuepf

I’m testing a script to generate macro headers from a dialog box.

When I run it in IJ1 Macro language it does what it is supposed to do (generate a html-based message and a log window with a header to put in my scripts). The problem is that when I run it with IJ1 Macro Markdown it generates an error that I can’t debug (error message is not very informative).
I thought that IJM and IJMMD would run equally well or throw the same errors if it was the case. Never saw a code that runs in one language but not on the other.

You can find the code at my github page. Please download it and run it with IJM language activated and then with IJMMD activated to see the error.

Do you know what’s happening?

Thanks

1 Like

Hi Eduardo @econdesousa ,

I just quickly checked your code. It is a macro that generates an html page which is put in a macro that generates a markdown file. It is a script that puts itself into a script, right? I’m afraid I never thought of such Matroschka code and that’s why IJMMD might be confused here. Is there a particular reason why you need to execute this using ImageJ Macro Markdown?

Best,
Robert

Hi Robert @haesleinhuepf

No, it Isn’t. It generates the html from the strings the user types in the dialog box. It also generates the header of a new script from the same info (its actual header was a manual copy-paste of the output of one run of it).
This was just a small toy project. I usually add a pre-defined header to all my scripts and inspired by https://twitter.com/DrNickCondon/status/1250310396642078720 I decided to somehow automate the header copy-paste process.

I use the IJMMD often, but this time it was not a goal at all. I just change the language out of curiosity and in the first few draft versions of the code (already with the large part of the html and print statements in it) it ran. Then I added some extra fields to the dialog box and at some point (sorry, but I lost track of when) the behavior started being far from the expected (to me at least) and decided to share this with you. I don’t know if this is a bug or simply something the IJMMD is not meant to do (I understand that html is not common but as I said, the main problem is not the html per se, because the first attempts worked - it broke somewhere after the first few steps).

Mainly, this post had tow purposes:

  1. (the most important) let you know, in case this is a bug that you may be interested in addressing,
  2. out of pure academic curiosity

So, if you find out the reason, please let me know.

Best,
Eduardo

1 Like

Alright, thanks for reporting this! It’s appreciated. I think, I won’t dig deeper here because it’s not really needed.

Just some background: IJMMD modifies the given macro by entering additional lines in the code. These lines write the markdown file in the background. You can see the mechanism here. No magic :wink:

Best,
Robert

I checked your source code… Not that I’m an expert… far from it. I never coded anything serious on java.
Nevertheless one line caught my attention (line 66):

builder.append("call(\"net.haesleinhuepf.imagej.markdown.ImagejMacroMarkdownRuntime.println\", \"" + line.replace("\"", "\\\"") + "\");\n");

I think the problem is not on the html at all. It was just coincidence.
The problem is with the \" that is replaced in that line. To be honest I don’t understand the goal of that replacement and why it crashes the code but I’m pretty sure the proble is with the sequence \"

Please, try the same thing with this dummy example:

str="dummy text with \" ... ";
print(str);

If you run it in IJM it prints

dummy text with " …

If you run it with IJMMD it will export the same error.

If the problem is this one maybe it will need some fix or at least a note to users since the combination \" is somehow common…

Best
Eduardo

1 Like

I’m actually replacing a " with a \", I’m replaceing it by its escape sequence. Otherwise, I can’t print the command to the markdown file.

If I also replace \ by \\, the error goes away :slight_smile: This code works then:

str="dummy text with \" ... ";
print(str);

Not sure if this is also true for your long code example. The result looks a bit weird and fixing this might be a deep dive down the rabbit hole.

I’ve updated the IJMMD update site. Let me know what you think.

Thanks again!

Best,
Robert

Hi Robert @haesleinhuepf

I tested it today with its defaults in IJMMD and it worked perfectly.
Thanks!

One thing that I notice and it was awesome: Although IJMMD didn’t print the showMessage output, the resulting window content was there because I printed the command to the Log Window and IJMMD parsed the html code inside that line:

Best,
Eduardo

1 Like