On Tuesday, January 15, 2019 at 11:41:16 AM UTC-8, AdamS wrote: > > Yeah, that's kind of my point. I understand why standard inline javascript > is not something that can be part of the core, or anything so fundamental > to the way tiddlywiki works. That's why I'm wondering if it would be > possible to sanitize it, removing any DOM related stuff or anything that > might pose a security problem, but allow things like string and array > manipulation and basic logic. I've found the wikitext and widget syntax > within TW5 to be a lot more difficult to learn than Javascript. If I'm not > alone in that, being able to do some of the lifting with a skill that is > more widely applicable might help with uptake with new users. >
There are two separate issues here: 1) Being able to use custom javascript code to do calculations and other logic 2) Loading the code "on-the-fly" As has been noted, (2) is problematic from a security standpoint... so let's just ignore that and focus on (1)... Fortunately, the solution is *already provided* by the TWCore. You can use https://tiddlywiki.com/dev/#JavaScript%20Macros to define custom javascript functions that are loaded during startup processing (just like plugins). Then, after startup, these javascript functions can be invoked from within tiddler content using the standard macro syntax (e.g., <<myMacro arg1:"foo" arg2:"bar">> or <$macrocall $name="myMacro" ... />. In addition, just like the definition of regular in-line macros (created using "\define foo(...)"), a javascript macro's "job" is simply to generate and return content for further rendering by the TWCore engine. A good example of a simple javascript macro can be found here: https://tiddlywiki.com/#%24%3A%2Fcore%2Fmodules%2Fmacros%2Fnow.js This code shows the definition of the TWCore's <<now>> macro, which accepts one optional parameter -- a datetime format -- and returns the corresponding datetime text as it's result. In addition to the <<now>> macro, there are several other javascript macros of varying complexity that are part of the TWCore. Use $:/AdvancedSearch to search the *shadow* tiddlers for "core/modules/macros" and you will see about a dozen results for you to study. Hopefully, this is enough to get you started. Let me know how it goes. enjoy, -e Eric Shulman TiddlyTools.com: "Small Tools for Big Ideas!" (tm) InsideTiddlyWiki: The Missing Manuals -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/ec41b892-e219-4767-b52c-a35076574d87%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

