doJavaScript on a Markdown preview?

It’s it possible to have doJavaScript inject code in a MD preview? I’m not referring to a script element in the MD here.

At least theoretically but specifying a script in Settings > Files > Markdown via its item link is definitely the recommended way.

The difference being that is just JavaScript, equivalent to a script element in the MD. doJavaScript would be JXA-capable, i.e. it could work on records. script can’t.

It’s actually just running JavaScript in the web view (like <script>), it’s not JXA.

Yes, I know that. But I could do something like that

const app = Application("DEVONthink");
const r = app.getRecordWithUuid(...);
const tw = app.openWindowFor({record: r});
const result = app.doJavaScript(`do something here`, {in: tw});
r.plainText = r.plainText() + `\n` +  result.toString();

Or whatever JXA permits me to do: The script runs in the context of the preview (if that works), but the doJavaScript runs in the context of JXA.
Background: Interactive task-list checkboxes in the Markdown preview — now that the MultiMarkdown dependency is gone
It’s trivial to have a script make the checkboxes interaktive (ie turn disabled off), but then… As you said, script is just JS, not JXA. In order to change the MD file itself, one would need JXA (or AS, for that matter).
That’s why I was thinking of this slightly contrived approach…

I recognized right away what you’re planning :wink: Well, there will be some Markdown related improvements in the next release but one step after another…

1 Like