Macros in Tiddlywiki are stored in tiddlers tagged with
$:/tags/Macro
and their contents are hidden. For documentation purpose it is desired to show macros in separate blocks with macro name as heading and content wrapped into<pre>
tag.Using
find
with delimitersbegin="\define"
andend="\end"
can extract macros from any tiddler. When a macro is extracted a secondfind
run on the result withstart=" "
andend="("
can extract the macro name.
In any tiddler contains macros, put the below script
!! Macro <<< <<show-macro>> <<<
The
show-macro
works based on delimiters. If macro is defined as a single line (with no\end
delimiter) the macro may fail.
Drag and drop the below macros into your wiki
his example shows how the shod-macro
macro can be used to display macros inside a filtered list of tiddlers.
List all macros in first three tiddlers tagged with $:/tags/Macro
<$list filter="[tag[$:/tags/Macro]limit[3]]">
<li><$link to=<<currentTiddler>>> <$text text=<<currentTiddler>> /></$link></li>
<blockquote>
<<show-macro>>
</blockquote>
</$list>
That renders as:
DBADGE
\define dbadge(subject,status, type:"primary") <div class="dbadge"><span class="dbadge-subject">$subject$</span><span class="dbadge-status dbadge-$type$ ">$status$</span></div> \end
ALERT
\define alert(type:"primary" text:"", width:"100%", class:"") <div class="alert alert-$type$ $class$" style="width:$width$;"> $text$ </div> \endALERT-LEFTBAR
\define alert-leftbar(type:"primary" text:"", width:"100%") <div class="alert bg-transparent leftbar border-$type$" style="width:$width$;"> $text$ </div> \end
WIKITEXT-EXAMPLE
\define wikitext-example(src) <div class="doc-example"> <$macrocall $name="copy-to-clipboard-above-right" src=<<__src__>>/> ``` $src$ ``` That renders as: $src$ \endWIKITEXT-EXAMPLE-WITHOUT-HTML
\define wikitext-example-without-html(src) <div class="doc-example"> <$macrocall $name="copy-to-clipboard-above-right" src=<<__src__>>/> ``` $src$ ``` That renders as: $src$ </div> \end
Demo: file:///G:/TW/TW-Findmacro/Find%20macro.html#Example%2001%3A%20List%20Macros%20from%20TiddlersBestMohammad
nice example of using access to macros such that they are somewhat self documenting.
As suggested by me previously I think it would still be valuable to develop a convention to create a fied macro-macroname containing the syntax and descriptor of any macro in a given tiddler. We could then combine these to give a full description of any macro.
However rather than in line in wiki text an editor toolbar item with a dialogue that searches for macronames and displays the macro content with an option to past into wikitext or clipboard would realy help desiging.
I am happy to help build the editor toolbar item.
Regards
Tony
Many thanks for your feedback and your idea.
Best
Mohammad