[TW5] How to combine/transclude codeblock tiddlers?

324 views
Skip to first unread message

Branimir Braykov

unread,
Aug 27, 2014, 12:11:11 PM8/27/14
to tiddl...@googlegroups.com
I have several tiddlers that only contain single codeblocks.
Like, these are two tiddlers:
Tiddler1
```
line 1
line 2
line 3
```
Tiddler2
```
text 1
text 2
text 3
```

I would like to use Transclude widget to combine them as a single block.
I tried this:
<$transclude tiddler="Tiddler 1" mode=block/>
<$transclude tiddler="Tiddler 2" mode=block/>
But I still get two separate codeblocks.
Surrounding these two widget calls with ``` also doesn't work as it does not get wikified.
So how do I do that?

Jeremy Ruston

unread,
Aug 27, 2014, 3:15:40 PM8/27/14
to TiddlyWiki
Hi Branimir

I would like to use Transclude widget to combine them as a single block.

Yes, that makes sense.
 
I tried this:
<$transclude tiddler="Tiddler 1" mode=block/>
<$transclude tiddler="Tiddler 2" mode=block/>
But I still get two separate codeblocks.

TiddlyWiki doesn't merge consecutive code blocks. I'm not sure that it should, though, what do others think?

Surrounding these two widget calls with ``` also doesn't work as it does not get wikified.
 
So how do I do that?

There are two parts to the answer:

* Use an explicit <code> tag inside a <pre> tag instead of the triple backticks syntax
* Rather than transcluding the target tiddlers (which causes them to be wikified), use the view widget to render them in plain text

The end result would be something like this:

<pre><code>
<$view tiddler="text1"/>
<$view tiddler="text2"/>
</code></pre>

Would that work for you?

Best wishes

Jeremy

 

--
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 http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

Branimir Braykov

unread,
Aug 27, 2014, 4:00:42 PM8/27/14
to tiddl...@googlegroups.com
Hi, Jeremy,
10x for your quick answer.
I tried the proposed way, but the resulting block includes a lot of ``` as they become part of the text.
My actual tiddlers only include something like:
```
text
more text
```

I was originaly trying to follow the logic as explained in TranscludeWidget.
Actually this should work if I have tiddlers that only contain, e.g. unordered list.
But after combining such tiddlers I do get a small whitespace, separating the lists from the two tiddlers.
The same behavior is observed when I try to combine codeblocks.
From what is given in the example in TranscludeWidget, which is actually more complex, transcluding tiddlers in block mode means that the tiddlers are combined as a single "block"-ed content but wikified as within the separate tiddlers.
I too would like to hear other opinions on the matter.

Either way I think it should be possible to transclude tiddlers both like it works now, in separate blocks and as a single block, list, etc.
If that sounds complicated I can provide examples.

Jeremy Ruston

unread,
Aug 27, 2014, 5:59:07 PM8/27/14
to TiddlyWiki
Hi Branimir

Apologies, I missed out a couple of points: you'll need to remove the triple backticks from your code tiddlers. If you still want those tiddlers to display as fixed width text then you can give them the type text/plain.

In terms of transclusion, there's basically two ways of doing it:

* To replace any transclusions with the target text (if necessary repeatedly), and then parse and render the result. The downside of this approach is that if one of the transcluded tiddlers changes then we need to refresh the entire tiddler
* To treat transclusions more like an HTML iframe, where the transcluded text is parsed separately and then spliced into the output tree. The upside of this approach is that we can then selectively refresh individual transclusions, making the process much more efficient

TiddlyWiki supports both approaches. Textual transclusion is accomplished via macro parameters and variable substitutions. Structured transclusion is accomplished via the transclude widget.

There's much more flexibility baked into the transclude widget, simply because it's almost always the most efficient. But there are many tasks that require the textual transclusion capability of macros.

The particular use case here would require a form of filtered textual transclusion that isn't possible right now. But we might imagine something like this:

\define my-concatenated-tiddlers(filter)
```
$$( $filter$ || mytemplate )$$
```
\end

Best wishes

Jeremy


--
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 http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.

Branimir Braykov

unread,
Aug 28, 2014, 4:48:44 AM8/28/14
to tiddl...@googlegroups.com
Thank you for this info.
I didn't know that setting a tiddler as text/plain displays it like a codeblock. This is the thing that suits me most.
So here's what I did: converted my tiddler types to text/plain and used this:
<pre><code><$view tiddler="text1"/>
<$view tiddler="text2"/>
</code></pre>

It is perfect, because I can also adjust the space between these tiddlers, so if I decide I need a blank line I could just do this:
<pre><code><$view tiddler="text1"/>
 
<$view tiddler="text2"/>
</code></pre>

There is one unexpected glitch, however. After converting my tiddlers, for some unknown reason they look like parsed with the "highlight" plugin that I have.
I don't know if this is a bug or it's intentional, but I will ignore this for now.

Jeremy Ruston

unread,
Aug 28, 2014, 7:26:27 AM8/28/14
to TiddlyWiki
Hi Branimir


There is one unexpected glitch, however. After converting my tiddlers, for some unknown reason they look like parsed with the "highlight" plugin that I have.
I don't know if this is a bug or it's intentional, but I will ignore this for now.

The highlight plugin currently applies to all instances of the codeblock widget, including those generated automatically by the core when transcluding non-wikitext tiddlers.

Best wishes

Jeremy
 

--
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 http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.

Branimir Braykov

unread,
Aug 28, 2014, 8:25:34 AM8/28/14
to tiddl...@googlegroups.com, jeremy...@gmail.com


On Thursday, August 28, 2014 2:26:27 PM UTC+3, Jeremy Ruston wrote:

The highlight plugin currently applies to all instances of the codeblock widget, including those generated automatically by the core when transcluding non-wikitext tiddlers.


Strange. I wonder what language it is trying to recognize.
I usually use it like this to specify:
```bash
myVar=value
``` 

But as I said, that is not important for me now :-) 
Reply all
Reply to author
Forward
0 new messages