[TW5] Render WikiText into attribute strings?

111 views
Skip to first unread message

Evan Balster

unread,
Sep 12, 2015, 12:52:24 PM9/12/15
to tiddl...@googlegroups.com
Use Case:

Suppose within my TiddlyWiki I'm rendering an infographic as SVG.  The SVG contains a path, which is defined by a string containing a list of vertices.  Suppose further I want to use an operation with at least one <$list> widget to populate this path, as below.  Because the path is an attribute string, any transclusion into it will not be wikified.  I can paste transclusions together using macros, but that isn't practical for lists.  So is there a way to force wikification?

Obviously any HTML would be undesirable in the output, so I would need to be able to use a render mode like the one which applies in this typed block:

$$$text/vnd.tiddlywiki>text/plain
<$list filter="[tag[Vertex]first[]]">M {{!!x}} {{!!y}}
</$list>
<$list filter="[tag[Vertex]rest[]]">L {{!!x}} {{!!y}}
</$list>
$$$

(I ran into this problem a few months ago while creating a graphical timeline generator and never managed to solve it.  I know this is possible, because TiddlyWiki does something very similar to support customized stylesheets with basic parsing rules -- but I've investigated how it's done, and the mechanism uses calls to the rendering engine in core code rather than any accessible macro.  The discussion I started at that time did not lead anywhere.)

As far as I can tell, all that would be necessary would be a macro to the effect of:

<<parse_and_render {{MySVGCode}} text/vnd.tiddlywiki>text/plain>>

Which makes the appropriate calls into core code.  Would this be reasonable to request as a core feature?  If not, is there a plug-in?


(I anticipate someone will mention that this is possible by way of storing data to a temporary tiddler and then transcluding it.  If so, I would love to know how -- but I also point out that such is a significant deviation from TiddlyWiki's "normal" way of rendering things and makes unnecessary use of long-term storage.  I'd also rather avoid "refresh" trigger buttons.)

Evan Balster

unread,
Sep 12, 2015, 1:21:33 PM9/12/15
to TiddlyWiki
I noticed another ongoing thread where the user in question was expecting to be able to render wikitext into an attribute:  Read here.

He is trying to generate a filter expression using <$list> widgets, presumably to cull duplicated items in a recursive search.  His calling code is thus:

<$set name="myList" value=<<listDescendants "NameOfConceptTiddler">> >
<$list filter=<<myList>> />
</$set>


(where <<myList>> is a recursive macro involving <$list>.)


I suspect this isn't an entirely uncommon sticking point.

Mark S.

unread,
Sep 15, 2015, 1:31:02 PM9/15/15
to TiddlyWiki
I'm not real up-to-date on SVG. Could you explain a little what you're trying to do in your example? I would think that you were trying to draw an SVG figure, except that it looks like you want to render it as text.  I think what's wanted is a way to accumulate the output of a <$list> widget so that it can then be subsequently used inside of something else (like SVG code). What is in X and Y that you want wikified? Wouldn't they just be numbers, or are X and Y wrapped in some type of SVG formatting?

Thanks,
Mark

Evan Balster

unread,
Sep 15, 2015, 4:02:51 PM9/15/15
to TiddlyWiki
I would want to render, at minimum, widgets, into a plaintext format for use in SVG tag attributes.  Specifically, the d (data) attribute of the <path> tag.

As far as I know, there is no direct means to achieve this.  Apparently the developers have discussed it extensively, but implementation is complicated by use-cases involving automatic refresh and use of this functionality to generate widget attributes.

BJ

unread,
Sep 15, 2015, 4:32:26 PM9/15/15
to TiddlyWiki
HI Evan,
it is possible to do this with one of my plugins
http://bjtools.tiddlyspot.com/#Flexitype Demo

However I think that using the $list widget it is going to be hard to give the correct order of your x,y coordinates (how to list the tiddlers in the correct order?)

cheers bj

Mark S.

unread,
Sep 15, 2015, 4:50:22 PM9/15/15
to TiddlyWiki
Just to be clear, you want text that you can cut and paste into your svg editor? Or are you hoping to render right there into SVG (in which case I don't understand why you want to see the plain text).

About BJ's comment ... you probably would need to add a field that orders the points. I imagine you left that out to keep things simple.

Mark

BJ

unread,
Sep 15, 2015, 5:19:40 PM9/15/15
to TiddlyWiki
This is one of the things that I need to do as well. I think that it would be better to put the data in to json tiddlers - they can contain ordered lists (arrays), and then have some widgets like the ractive.js templates (see http://mlarocca.github.io/01-22-2014/pathsjs_ractive.html for an example) that can handle json tiddlers.

Evan Balster

unread,
Sep 15, 2015, 5:34:29 PM9/15/15
to TiddlyWiki
My actual scheme for rendering the SVG path is a bit more complicated -- my example code is meant to be as simple as possible for purposes of explaining the problem.  (I'm making a timeline display system for a story wiki.)

I'll look into the FlexiType tool; it looks like it could be well-suited to this use-case.  (Re-parsing is an interesting way to solve the problem!  How well does it deal with automatic updates?)

Evan Balster

unread,
Sep 15, 2015, 5:41:34 PM9/15/15
to TiddlyWiki
BJ:  I should note that while FlexiType looks like what I need, your example shows a case where standard TiddlyWiki functionality actually works!  Try the code below in your wiki:


<svg width="100%" height="100%" viewBox="0 0 1000 300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="background:white;">
<defs>
<path id="MyPath" d={{AtrStr!!path}}/>
</defs>
<use xlink:href="#MyPath" fill="none" stroke="#ddd"/>plain
<text font-family="'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif" font-size="42.5">
<textPath xlink:href="#MyPath">
====To The  Top=====on the bottom=======================
</textPath>
</text>
</svg>


It's quite possible to transclude into attributes with TW5 -- it's just that such transclusions are never wikified.
Reply all
Reply to author
Forward
0 new messages