-
I’ve made a macro which converts a wikitext table into a multiline sparkline-like graph. Currently the macro takes the wikitext as a parameter and parses it, but I would like it to parse the current tiddler text directly. This feels like it is an extremely dumb question but I have searched here and in the Google group yet still cannot figure out how to access the text of the current tiddler from a JS macro.
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
Can you tell what a "multiline sparkline-like graph" is? ... A link would be nice.
I think it's not the best approach to use a macro for this uscase. Macros per definition are "text substitutions". So they take some input and return some text output. ... They don't have a mechanism to participate in the global "refresh" mechanism. My gut feeling tells my, you may be better of with a widget, that takes a "tiddler title" as an input and renders some HTML output. |
Beta Was this translation helpful? Give feedback.
-
Thanks @pmario. This is my graph for tracking typing speed & accuracy, as an example 😄
The macro creates an SVG image of the results and returns it, along with the wikitext input, so the result in the tiddler is an SVG graph with the table of data beneath. I update the tiddlers regularly with new results added to the top of the wikitext table but what I’d prefer is for the macro to parse the text of the tiddler it’s used within and add a sparkline to any wikitext tables. You may be right that a widget is a better solution! I just discovered this tutorial which may help. I might also just stick with my existing solution which, although not the most elegant, works for my purposes! |
Beta Was this translation helpful? Give feedback.
-
It is possible to read the tiddler content by name. eg: If you write this to the F12 console in the dev tools
See the screenshot for a way to debug and get all the info you probably want ;) I'm using FireFox for debugging, since it displays a nice structure similar to the repo. Chrome is possible too, but it doesn't show the nice directory like structure If you need a second run. Just click the Run Button and add a "space" char to the text. Hope that helps Have fun! |
Beta Was this translation helpful? Give feedback.
-
Hi @danfarrow as @pmario notes, macros are simple functions with string parameters and no side effects, and have no intrinsic ability to interact with the refresh mechanism. They are intended to be the simplest possible interface for simple textual manipulation; in practice developers bend them to do more than that, but there are always problems as a result. The easiest way to approach your application would be to make a custom parser for a mime type like The railroad plugin is a good example of this approach: https://github.com/Jermolene/TiddlyWiki5/tree/master/plugins/tiddlywiki/railroad |
Beta Was this translation helpful? Give feedback.
-
I have now got this working, building on the previous answers - thanks again! Inside the macro, this gets the text of the current tiddler:
I extract the table wikitext using a regular expression (only supports a single table currently):
|
Beta Was this translation helpful? Give feedback.
I have now got this working, building on the previous answers - thanks again!
Inside the macro, this gets the text of the current tiddler:
I extract the table wikitext using a regular expression (only supports a single table currently):