Ignoring formatting rules in $wikify widget

234 views
Skip to first unread message

Evan Balster

unread,
May 10, 2016, 2:39:26 AM5/10/16
to TiddlyWiki
I'm very enthusiastic about the new Wikify widget!  I was hurting for this feature ages ago when experimenting with generation of timeline SVGs and other visualizations in TiddlyWiki, and now that it's here I might revisit those utilities and kick them up a notch!

I have one minor gripe, for which I have already determined a workaround:  When rendering with text output, wiki markup is scrubbed from the input even when those rules are not applied.  This makes rendering non-formatted content, such as dynamically generated source code, somewhat more confusing than it should be.

Here's a bit of code demonstrating a place where the wikify widget's behavior is troublesome -- I attempt to render some SVG code, here sourced from a variable, and get nothing for reasons which might not be immediately clear.

!!Without Backtick 

<$vars radius=40 svg="<svg width=100 height=100><circle cx=50 cy=50 r=<<radius>>/></svg>">
<$wikify name=svg_code text=<<svg>> >
<<svg_code>>
<pre><code><$text text=<<svg_code>>/></code></pre>
</$wikify>
</$vars>

The work-around I discovered after some brief experimentation?  Enclose the text in `code snippet` or ```code block``` markup as below, so that all content is unformatted.  Unfortunately, this will prevent any enclosed transclusions, widgets or macros from expanding in the $wikify widget.

!!With Backtick (macro call is not expanded)

<$vars radius=40 svg="`<svg width=100 height=100><circle cx=50 cy=50 r=<<radius>>/></svg>`">
<$wikify name=svg_code text=<<svg>> >
<<svg_code>>
<pre><code><$text text=<<svg_code>>/></code></pre>
</$wikify>
</$vars>

This is far from a show-stopping problem, but it felt worth pointing out.  In the long run, I think that the nicest solution for wikifying with text output (especially code) would be a parsing mode which handles only variables, macros, widgets and transclusions.  (I would also suggest that this mode preserve whitespace.)

Anyway.  Keep up the great work, Jeremy, and don't burn yourself out trying to hurry it out the door!

-- Evan

Mat

unread,
May 10, 2016, 1:26:33 PM5/10/16
to TiddlyWiki
Evan, thanks for sharing your insights!


Unfortunately, this will prevent any enclosed transclusions, widgets or macros from expanding in the $wikify widget.


I have not tried out your code (and it's bordering on me understanding it at all), but wouldn't it be possible to simply concatenate like so:

svg="`code` {{transclusion and stuff}} `more code`"

<:-)

Jeremy Ruston

unread,
May 10, 2016, 2:06:44 PM5/10/16
to tiddl...@googlegroups.com
Hi Evan

Here's a bit of code demonstrating a place where the wikify widget's behavior is troublesome -- I attempt to render some SVG code, here sourced from a variable, and get nothing for reasons which might not be immediately clear.

The problem here is that the `output` attribute of the wikify widget defaults to “text”, giving you the text content of the wikified output (in this case, there is no text output, of course). The fix is to add `output=“html”` to the wikify widget.

Best wishes

Jeremy.



!!Without Backtick 

<$vars radius=40 svg="<svg width=100 height=100><circle cx=50 cy=50 r=<<radius>>/></svg>">
<$wikify name=svg_code text=<<svg>> >
<<svg_code>>
<pre><code><$text text=<<svg_code>>/></code></pre>
</$wikify>
</$vars>

The work-around I discovered after some brief experimentation?  Enclose the text in `code snippet` or ```code block``` markup as below, so that all content is unformatted.  Unfortunately, this will prevent any enclosed transclusions, widgets or macros from expanding in the $wikify widget.

!!With Backtick (macro call is not expanded)

<$vars radius=40 svg="`<svg width=100 height=100><circle cx=50 cy=50 r=<<radius>>/></svg>`">
<$wikify name=svg_code text=<<svg>> >
<<svg_code>>
<pre><code><$text text=<<svg_code>>/></code></pre>
</$wikify>
</$vars>

This is far from a show-stopping problem, but it felt worth pointing out.  In the long run, I think that the nicest solution for wikifying with text output (especially code) would be a parsing mode which handles only variables, macros, widgets and transclusions.  (I would also suggest that this mode preserve whitespace.)

Anyway.  Keep up the great work, Jeremy, and don't burn yourself out trying to hurry it out the door!

-- Evan

--
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 tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
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/30501eac-3d18-4f83-8cc0-a5cb15cce75a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Evan Balster

unread,
May 10, 2016, 2:33:56 PM5/10/16
to TiddlyWiki
Here's an alternate use case that isn't well-served by text or HTML output:  Say I want to use TiddlyWiki to generate some C++ source code which utilizes substitutions.  (I have actually done this insofar as generating pseudocode for filtering routines, so it isn't too far afield of practicality.)

Here's my source code template -- in this case,  

"SourceTemplate"  (plain text tiddler)
//Inherit from this class 
template<typename T_Traits> <<className>>
{
  typedef T_Traits Traits;
}

And here's a bit of code to display it:
<$vars className=MyClass>
<$wikify name=source text={{SourceTemplate}}>
<pre><code><$text text=<<source>>/></code></pre>
</$wikify>
</$vars>

When wikified to text, the //comment and <template parameter list> are both identified as formatting and removed:
Inherit from this class 
template MyClass
{
  typedef T_Traits Traits;
}

Wikifying to HTML instead interprets these as formatting.  (We can avoid the extraneous <p> tags by parsing in inline mode)
<em>Inherit from this class 
template<typename T_Traits="true"> <a class="tc-tiddlylink tc-tiddlylink-missing" href="#MyClass">MyClass</a>
{
  typedef T_Traits Traits;
}</typename></em>

How do you suggest approaching problems like this without adding undue complexity?


For a bit more perspective, attached is a tiddler I wrote last year to generate C++-like pseudocode for digital filter difference equations up to a certain level of complexity.  (It includes an example rendering.)  This was rather difficult to make, and it's something I'd love to be able to do more easily with the new wikify widget -- and ideally without having to worry about the gotchas mentioned above.
_FilterMacros.json

Jeremy Ruston

unread,
May 10, 2016, 2:42:28 PM5/10/16
to tiddl...@googlegroups.com
Hi Evan

Interesting idea.

When wikified to text, the //comment and <template parameter list> are both identified as formatting and removed:

That’s why I added the \rules except pragma to my example.

I think there’s a fundamental problem with incompatibilities between the default wikitext syntax and the structures typically found in code.

To explore this area properly, I’d be inclined to create a new parser for `text/code-sample` (or something) that has a very small set of parse rules chosen to avoid clashes.

Best wishes

Jeremy


For more options, visit https://groups.google.com/d/optout.
<_FilterMacros.json>

Evan Balster

unread,
May 10, 2016, 2:54:33 PM5/10/16
to tiddlywiki
I would agree with that reasoning, generally.  And yes, I'll certainly be out of luck if I have something that looks like a {{transclude}}, <<variable>> or <$widget> in my code.  For my uses I suspect all of these would be exceedingly unlikely.

Mainly, I just find the default behavior -- removing formatting -- to be very unintuitive.  That loss of information is only useful in certain situations where the user wants to strip formatting from a field.

Where's the example you mention?

– Evan

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/9cO-7C3LiLE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.

To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Matthew Lauber

unread,
May 10, 2016, 4:50:28 PM5/10/16
to TiddlyWiki
Reply all
Reply to author
Forward
0 new messages