Tree macro - fix for double quotes (and other special characters) (#3552)

* Added fixes for special characters (e.g. double quotes) (including @BurningTreeC and @Jermolene suggestions)
* Removed a lot of redundant code
* Set a default value for "tree" macro prefix parameter ($:/)
This commit is contained in:
Adrian Morosanu
2018-11-19 10:50:09 +00:00
committed by Jeremy Ruston
parent 4f78d3d81b
commit f373d8f2bf
+31 -27
View File
@@ -1,53 +1,57 @@
title: $:/core/macros/tree title: $:/core/macros/tree
tags: $:/tags/Macro tags: $:/tags/Macro
\define leaf-node(prefix) \define leaf-link(full-title, chunk)
<$link to=<<__full-title__>>><$text text=<<__chunk__>>/></$link>
\end
\define leaf-node(prefix, chunk)
<li> <li>
<$list filter="""[[$prefix$$(chunk)$]is[shadow]] [[$prefix$$(chunk)$]is[tiddler]] +[removeprefix[$prefix$]] +[limit[1]]""" <$list filter="[<__prefix__>addsuffix<__chunk__>is[shadow]] [<__prefix__>addsuffix<__chunk__>is[tiddler]]" variable="full-title">
emptyMessage="""<$text text="$prefix$$(chunk)$"/>"""> <$list filter="[<full-title>removeprefix<__prefix__>]" variable="chunk">
<span>{{$:/core/images/file}}</span> <$link to="""$prefix$$(chunk)$"""> <span>{{$:/core/images/file}}</span> <$macrocall $name="leaf-link" full-title=<<full-title>> chunk=<<chunk>>/>
<$view field="title"/> </$list>
</$link>
</$list> </$list>
</li> </li>
\end \end
\define branch-node(prefix) \define branch-node(prefix, chunk)
<$reveal type="nomatch" text="" default="""$(chunk)$"""> <li>
<li> <$set name="reveal-state" value={{{ [[$:/state/tree/]addsuffix<__prefix__>addsuffix<__chunk__>] }}}>
<$list filter="""[all[shadows+tiddlers]prefix[$prefix$$(chunk)$]] -[[$prefix$$(chunk)$]] +[limit[1]]"""> <$reveal type="nomatch" stateTitle=<<reveal-state>> text="show">
<$reveal type="nomatch" stateTitle="""$:/state/tree/$prefix$$(chunk)$""" text="show"> <$button setTitle=<<reveal-state>> setTo="show" class="tc-btn-invisible">
<$button setTitle="""$:/state/tree/$prefix$$(chunk)$""" setTo="show" class="tc-btn-invisible">{{$:/core/images/folder}} <$text text="""$(chunk)$"""/></$button> {{$:/core/images/folder}} <$text text=<<__chunk__>>/>
</$button>
</$reveal> </$reveal>
<$reveal type="match" stateTitle="""$:/state/tree/$prefix$$(chunk)$""" text="show"> <$reveal type="match" stateTitle=<<reveal-state>> text="show">
<$button setTitle="""$:/state/tree/$prefix$$(chunk)$""" setTo="hide" class="tc-btn-invisible">{{$:/core/images/folder}} <$text text="""$(chunk)$"""/></$button> <$button setTitle=<<reveal-state>> setTo="hide" class="tc-btn-invisible">
{{$:/core/images/folder}} <$text text=<<__chunk__>>/>
</$button>
</$reveal> </$reveal>
</$list> <span>(<$count filter="[all[shadows+tiddlers]removeprefix<__prefix__>removeprefix<__chunk__>] -[<__prefix__>addsuffix<__chunk__>]"/>)</span>
<$list filter="""[all[shadows+tiddlers]prefix[$prefix$$(chunk)$]] -[[$prefix$$(chunk)$]] +[limit[1]]"""><span>(<$count filter="""[all[shadows+tiddlers]prefix[$prefix$$(chunk)$]] -[[$prefix$$(chunk)$]]"""/>)</span> <$reveal type="match" stateTitle=<<reveal-state>> text="show">
<$reveal type="match" stateTitle="""$:/state/tree/$prefix$$(chunk)$""" text="show"> <$macrocall $name="tree-node" prefix={{{ [<__prefix__>addsuffix<__chunk__>] }}}/>
<$macrocall $name="tree-node" prefix="""$prefix$$(chunk)$"""/>
</$reveal> </$reveal>
</$list> </$set>
</li> </li>
</$reveal>
\end \end
\define tree-node(prefix) \define tree-node(prefix)
<ol> <ol>
<$list filter="[all[shadows+tiddlers]removeprefix[$prefix$]splitbefore[/]sort[title]] +[!suffix[/]]" variable="chunk"> <$list filter="[all[shadows+tiddlers]removeprefix<__prefix__>splitbefore[/]sort[]!suffix[/]]" variable="chunk">
<<leaf-node """$prefix$""">> <$macrocall $name="leaf-node" prefix=<<__prefix__>> chunk=<<chunk>>/>
</$list> </$list>
<$list filter="[all[shadows+tiddlers]removeprefix[$prefix$]splitbefore[/]sort[title]] +[suffix[/]]" variable="chunk"> <$list filter="[all[shadows+tiddlers]removeprefix<__prefix__>splitbefore[/]sort[]suffix[/]]" variable="chunk">
<<branch-node """$prefix$""">> <$macrocall $name="branch-node" prefix=<<__prefix__>> chunk=<<chunk>>/>
</$list> </$list>
</ol> </ol>
\end \end
\define tree(prefix) \define tree(prefix: "$:/")
<div class="tc-tree"> <div class="tc-tree">
<span><$text text="""$prefix$"""/></span> <span><$text text=<<__prefix__>>/></span>
<div> <div>
<$macrocall $name="tree-node" prefix="""$prefix$"""/> <$macrocall $name="tree-node" prefix=<<__prefix__>>/>
</div> </div>
</div> </div>
\end \end