[DOC] WikifyWidget : examples, usecase

The wiki currently lack examples for the wikify widget, thus I suggest we all collaborate to fix that. This wiki will serve as a draft for a future PR to the doc. Please feel free to edit it!

Using the output of widgets in a filter expression

<$let
target="purple" 
colourA="white"
colourB="black"
>
<$wikify name="wikified-color" text="""
<$macrocall $name="contrastcolour" 
target=<<target>> 
fallbackTarget=<<fallbackTarget>>
colourA=<<colourA>> 
colourB=<<colourB>> 
/>""">
<span style={{{"color:"=[<wikified-color>]";background:"=[<target>]+[join[]] }}}>Text with good contrast</span>
</$wikify>
</$let>

Accurate word count calculation

If a tiddler transclude some content, or use widgets to generate content, filters that try to calculate the word count won’t be accurate - we need to analyses the text AFTER it’s wikified.

Example:

\define lorem() lorem ipsum dolor

<$list filter="[range[0],[10]]"><<lorem>></$list>

Rendered output:

lorem ipsum dolorlorem ipsum dolorlorem ipsum dolorlorem ipsum dolorlorem ipsum dolorlorem ipsum dolorlorem ipsum dolorlorem ipsum dolorlorem ipsum dolorlorem ipsum dolorlorem ipsum dolor
  • Word count without wikify = {{{ [<code>split[ ]count[]] }}} = 6
  • Word count with wikify = {{{ [<wikify-output>split[ ]count[]] }}} = 23

Exporting rendered html out of tiddlywiki

<$edit-text field="code" tag="textarea" class="tc-edit-texteditor" placeholder="Write some wikitext.."/>

Copy rendered html:

<$wikify name="code" text={{!!code}} output="html">

<$codeblock code=<<code>>/>

<$macrocall $name="copy-to-clipboard" src=<<code>>/>

</$wikify>

Since javascript macros can be called with arguments now (recent TW version added that feature), I would write your example more simply as

{{{ [<now dddd>multiply[2]] }}}

I think a different example which can’t be simplified would be better.

1 Like

One is supposed to use the wikifywidget sparingly because it is very resource intensive. I think it would be desirable if the docs also gives specific examples of such poor usage along with comments why it is poor and alternative, better, solutions.

1 Like

Yes. I think examples where it acceptable would also be helpfull

I know, this was not a very good example. I think the color contrast macro is a good use case. What do you all think ? Dont forget you can edit the post if you want!

Very true. Such a note definitely belongs into the doc.

Sometimes I wonder if such information is confusing for the beginning WikiText programmer. $wikify is any easy solution for some problems (see OP) and much simpler than some of the workarounds. Maybe we should have something like an Advanced Usage box in the respective tiddlers, in which some of these considerations for, well, advanced users are collected. A beginner should ignore this and only later read through the advanced stuff, once he finds his footing with WikiText programming.

Have a nice day
Yaisog

PS: I think the tag coloring still uses text substitution instead of wikification, which is equally haunted and should not be used as an example for a $wikify alternative.