【问题标题】:How to make a TiddlyWiki table of contents (toc) with differnt colors如何制作不同颜色的 TiddlyWiki 目录 (toc)
【发布时间】:2022-11-18 07:58:14
【问题描述】:

我用

<div class="tc-table-of-contents">
<<toc "Inhalt">>
</div>

每个提琴手都标有吸入列在目录中。这很好用。

但我还有一个名为法尔特.是否可以更改此条目目录中的颜色?结果应如下所示:

Only tag Inhalt        --> normal blue color 
tag Inhalt + tag Fahrt --> perhaps a lighter blue oder different color

【问题讨论】:

    标签: colors tableofcontents tiddlywiki


    【解决方案1】:

    这对于默认的toc宏是不可能的,但是我们可以基于内置的toc宏编写一个新的宏来做到这一点,而不会有太多麻烦。我们将制作宏的一个版本,template-toc,它使用 template 来显示目录中的每个元素——这样,我们将能够重用我们的工作,以完全任意的方式格式化 TOC 元素方法。 (Fuller explanation of templates. 注意:这是我写的。)

    我们首先从 $:/core/macros/toc 复制宏 toctoc-body 并将它们粘贴到一个新的 tiddler $:/template-toc-macros(你可以随意调用这个 tiddler),标签为 $:/tags/Macro(这将导致宏在 wiki 中的任何 tiddler 中都可用)。

    然后我们将toc-body和所有对template-toc-body的引用重命名,同样将toc重命名为template-toc。我们添加一个参数 template 作为这两个宏的第二个参数,并调整两者的主体,以便它们将 &lt;&lt;__template__&gt;&gt; 参数作为 tiddler 而不是查看 captiontitle 字段以获得标题并以此作为文本创建链接。这使得这个 tiddler 的主体看起来像这样:

    define template-toc-body(tag,template,sort:"",itemClassFilter,exclude,path)
    whitespace trim
    <ol class="tc-toc">
      <$list filter="""[all[shadows+tiddlers]tag<__tag__>!has[draft.of]$sort$] -[<__tag__>] -[enlist<__exclude__>]""">
        <$let item=<<currentTiddler>> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}}>
          <$set name="excluded" filter="""[enlist<__exclude__>] [<__tag__>]""">
            <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item-selected" value="toc-item">
              <li class=<<toc-item-class>>>
                <$transclude tiddler=<<__template__>>/>
                <$macrocall $name="template-toc-body" tag=<<item>> template=<<__template__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> exclude=<<excluded>> path=<<path>>/>
              </li>
            </$set>
          </$set>
        </$let>
      </$list>
    </ol>
    end
    
    define template-toc(tag,template,sort:"",itemClassFilter:"")
    <$macrocall $name="template-toc-body"  tag=<<__tag__>> template=<<__template__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> />
    end
    

    下面是我们如何使用它:我们创建一个模板 tiddler,假设变量 &lt;&lt;currentTiddler&gt;&gt; 被设置为我们想要包含在 TOC 中的特定 tiddler,呈现我们想要包含在目录中的 HTML/wikitext。在此示例中,我们将此 tiddler 称为 MyTemplate,但您可能希望使用更具描述性的名称。在您的情况下,文本将类似于:

    <$link to=<<currentTiddler>>>
    <$list filter="[all[current]tag[Fahrt]]" emptyMessage="""<$view field='caption'><$view field='title' /></$view>""">
      <span style="color: red;"><$view field='caption'><$view field='title' /></$view></span>
    </$list>
    </$link>
    

    也就是说,如果过滤器 [all[current]tag[Fahrt]] 有任何输出,即 currentTiddler 被标记为 Fahrt,则填写 $list 小部件的主体(使用 color: red; CSS 属性创建一个跨度),包含caption 字段(如果它存在于 tiddler 上),否则为 title 字段。如果它没有被标记为Fahrt,则填写emptyMessage的内容,它做同样的事情但没有颜色。在任何一种情况下,创建一个指向包含该内容的currentTiddler 的链接。

    最后,无论你想在哪里显示目录,调用 template-toc 宏而不是 toc 宏,并将你刚刚创建的模板作为第二个参数传递给它:

    <div class="tc-table-of-contents">
      <<template-toc "Inhalt" MyTemplate>>
    </div>
    

    结果:

    【讨论】:

      猜你喜欢
      • 2018-02-05
      • 2017-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多