HTML [SugarCube2] Any way to call a macro with a closing tag through JS on an existing element?

Satori6

Game Developer
Aug 29, 2023
414
787
Macros that don't need a closing tag are pretty straight forward by using jQuery's wiki method.

However, when trying to call a macro that requires a closing tag through JS, I'm having the following issue:
Untitled.png

The problem is that the macro is being called twice: once to add the macro tag, and another one to close it.
I've tried using a mixture of append and prepend, but the issue remains since they are separate operations.

I've found two workarounds: the first is to obviously rewrite the macro as pure JS, which is not ideal; reinventing the wheel and all that.

The second is to call the macro and include the text within the same call, that way you can include both tags together:
Code:
$('#testfade').wiki('<<fadein 10s>>'+content+'<</fadein>>');
This works fine, but I'd still like to see if anybody knows a way to do it while the content is already present on the document.
 

guest1492

Member
Apr 28, 2018
316
265
The second way is pretty much how it's done... Each wiki call is a separate call to the parser. It's only natural you get broken code if you try to parse only half of it a time.

Side note:
If you are using Chapel's <<fadein>> macro, it utilizes jQuery's . Since you are already using jQuery, why not just use that instead of going through a macro? I wouldn't call that rewriting it in JS but more like stripping it down.
 
  • Like
Reactions: Satori6

Satori6

Game Developer
Aug 29, 2023
414
787
The second way is pretty much how it's done... Each wiki call is a separate call to the parser. It's only natural you get broken code if you try to parse only half of it a time.

Side note:
If you are using Chapel's <<fadein>> macro, it utilizes jQuery's . Since you are already using jQuery, why not just use that instead of going through a macro? I wouldn't call that rewriting it in JS but more like stripping it down.

Thank you! I'll look into that for future use.

I ended up abandoning the JS idea for this part because due to the way that part was implemented, I ended up having to make a dirty "hack" with a finally block and a timer to get the desired result, and it was only going to get nastier from there.