Unfortunately I have hit some barriers with approach for now, as reflected here Accessing ts-raw without the slot widget?
- It could be done with a procedure but providing the code snippet will be best by putting it in a procedure rather than inline and wrapping it the a custom widget would allow.
- I will comeback If I progress this.
Here is a quick example that can be customised further, but requires the code to exist within named variable/procedure;
- the advantage being it can be used many times or used to refer to other variables.
\procedure show.it(block n:"0" lines:"3" )
\procedure copy.button() <$button tooltip="copy to clipboard" message="tm-copy-to-clipboard" param=<<content>> class="tc-btn-invisible" >{{$:/core/images/copy-clipboard}}</$button>
<$let content={{{ [<block>getvariable[]] }}} show.it-state={{{ [<qualify $:/temp/show.it/>addsuffix<n>] }}} >
<$list filter="[<show.it-state>!has[title]]" variable=~>
<$button popup=<<show.it-state>> >{{$:/core/images/unfold-button}}</$button> <<copy.button>>
<pre><code><$list filter="[<content>splitregexp[\n]limit<lines>]" variable=line><$text text=<<line>>/><br></$list></code></pre>^^more ...^^
</$list>
<$list filter="[<show.it-state>has[title]]" variable=~>
<$button popup=<<show.it-state>> >{{$:/core/images/fold-button}}</$button> <<copy.button>>
<pre><code><<content>></code></pre>^^... less^^
</$list>
</$let>
\end show.it
\procedure myblock()
; my code block
: there
a
b
c
d
\end
<<show.it myblock>>
<<show.it myblock 1>>
<<show.it transclusion 2>>
- You could also have a button to render the code (if tiddlywiki script/markdown)
<div>
<<content>>
</div>
I would be easy to extend to
- detect existing tiddlers (rather than variables)
- Not show the expand button if less than or equal to n lines