Deleting or Changing the output format of the tags field

Hello! I am trying to figure out how to either delete the tags field altogether and then re-create it as a new field or change the output format when I export the tiddler.

The output that I am looking for is ['tag1', 'tag2', 'tag3']

Again it can either be in the tiddler itself or in the output of a custom exporter - the goal is to have that format when exported.

I can see how to generate the output you want then we need to modify the exporter. Which exporter do you use? Tid jsonā€¦

Its also an unusual request I cant imagin why you would do this? I assume you do not plan to reimport them?

Also is this from a single file wiki, node wiki or both as it may alter your options.

Thank you so much for working with this! What I have already done is create an exporter that exports to a markdown file. What I have done is create a way to create and edit blog posts in tiddlywiki and then export them for use in the nodejs static site generator eleventy. The tags are used as front matter and need to be in the format described. Originally I was using ā€˜postTagā€™ to generate my tags but I have found that most if not all pre made templates use ā€˜tagsā€™ and it would probably be easier to change things on the tiddlywiki side.

Here is the exporter code:

\define renderContent()
{{{ $(exportFilter)$ ||$:/core/templates/eleventyexport}}}
\end
<<renderContent>>

and here is the template:

`---`
<$fields exclude='text bag created modified modifier revision type published' template='$name$: $value$
'></$fields>`
---

`<$view field="text" format="text" />
```

as you can see I have kept the tags field in the exporter because right now I just use the one tag ā€˜postā€™ and that works fine but I need the desired output for multiple tags.

The wiki I have created for this purpose is at My 11ty Blog ā€” drafts and notes for my 11ty blog

Here is what the exported final product looks like.

One idea I had which I will look into when I get up is excluding the default tags field and creating a custom field tagsFoo and finding a way to drop the Foo on export.

Thank you again for your consideration!!

edit: oh and it is a single file wiki but Iā€™m just as comfortable transitioning to a node wiki I already have a couple of those as well.

1 Like

Perhaps have a look to see if this Markdown exporter meets your needs:

1 Like

@digitalap3 it seems to me as @saqimtiaz has realised the title of this post and its whole question could be replaced with a markdown exporter.

If this is not true let us know.

I looked inside the javascript and it appears its converting the tags field as you desire at export time.

How did I miss this plugin??? I have been looking for something like this for years! IMO Tiddlywikiā€™s adoption will increase through itā€™s use as a tool for outputting or connecting to other applications/platforms like this. After playing around with MySQL a couple years ago I had an epiphany and started looking at TW like a database instead of a wiki and it completely transformed how I used it.

Iā€™ll play with the plugin tonight but yes it looks like the answer. I am a bit hesitant to rely too much on plugins since they might stop working with updates and a ā€˜nativeā€™ answer would be educational but at this point probably not necessary.

Thank you both!!

edit: Iā€™ll play around with it tonight and if it works Iā€™ll mark it as the solution

1 Like

Sadly this isnā€™t it. The output for the tag field is tags: ['post,Musings,Test'] and I need tags: ['post', 'Musings', 'Test']. Also, I donā€™t see any way to include the custom fields that I added in the export with this plugin. Iā€™m sure it is possible with a much higher level of JS than I have but I am not even close to that yet. Hopefully there is a more ā€œnativeā€ way to accomplish this. Any help is appreciated. Thanks!!

edit: Even just pointing me in a direction you think might help I am not looking for or expecting someone to solve the problem for me. I have played around with trying to delete and modify shadow tag tiddlers without any success.

@digitalap3 Yes it is unfortunate the markdown exporter is built in javascript when it could be in wikitext, but exporters are fairly easy to build.

Notes;

  • Yes TiddlyWiki is many things database, website, app, smart document, notepad, software development kit, ā€¦ never under estimate its possibilities.
  • Donā€™t be shy of relying on plugins, they often work after upgrades because of a commitment to backwards compatibility
  • Perhaps @saqimtiaz or another developer can help you customise the existing markdown plugin

Below are two ā€œformat-tagsā€ macros, that generate a formatted tag list as you ask.

  • The second is divided into the components should you wish to reuse it.

Build an export

Composing tags output, but you need to do the other conversions to markdown.

\define open() [
\define close() ]
\define join() ,
\define format-tags()
<$set name=total-items filter="[list[!!tags]] +[count[]]">
<$list filter="[list[!!tags]]" counter=item variable=content>
   {{{ [<item>match[1]then<open>] [<content>addprefix[']addsuffix[']] [<item>!match<total-items>then[,]] [<item>match<total-items>then<close>] }}}
</$list>
</$set>
\end

\define format-tags1()
<$set name=total-items filter="[list[!!tags]] +[count[]]">
<$list filter="[list[!!tags]]" counter=item variable=content>
   {{{ [<item>match[1]then<open>] }}}
   {{{ [<content>addprefix[']addsuffix[']] }}}
   {{{ [<item>!match<total-items>then[,]] }}}
   {{{ [<item>match<total-items>then<close>] }}}
</$list>
</$set>
\end

<$wikify name=format-tags text="""<<format-tags>>""">
   <<format-tags>>
</$wikify>
  • Note how you use the wikify widget just in time, to remove unwanted wikification
  • I suggest you
    • use a -tags to not pass on the standard tags field during export
    • construct a "tags": <<format-tags>> in the correct format for your output, in the position your template would output the tags such as after the title.
  • But we will if you canā€™t proceed

I can help you more tomorrow (23hours from this reply) if necessary.

1 Like

Oh man canā€™t wait to dig into this thank you so much Iā€™ll play with it tonight and let you know!

1 Like

It took a lot of playing before I remembered that templates take returns literally when using the list widget (or any widget I guess bc I had to take out the return between the field widget and ā€œtag:ā€ as well). The output was adding a return after each tag in the exported file but not in the test wiki which was maddening! Final product for my export template:

\define open() [
\define close() ]
\define join() ,
\define format-tags()
<$set name=total-items filter="[list[!!tags]] +[count[]]"><$list filter="[list[!!tags]]" counter=item variable=content>{{{ [<item>match[1]then<open>] [<content>addprefix[']addsuffix[']] [<item>!match<total-items>then[,]] [<item>match<total-items>then<close>] }}}</$list></$set>
\end
`---`
<$fields exclude='text bag created modified modifier revision type published tags' template='$name$: $value$
'></$fields>tags: <<format-tags>>

`---`
<$view field="text" format="text" />

There is a lot to learn here as well and I donā€™t look to macros enough as a solution to more complex problems.

Thank you!!! I would have given up way before coming to that elegant solution.

edit: it looks like the pragma \whitespace trim would solve the problem of the template adding returns

1 Like

I use the official TW markdown plugin to edit the tiddler and then when it is exported with the view widget and format='text' the markdown is preserved. I pretty much do all my editing with markdown now since it is more portable and the plugin allows tiddlywikiā€™s macros to work.

Hey man thank you again. I figured for learning sake I would try a solution with my original idea of subtracting a prefix by taking taking apart what you did. After an embarrassingly long time I came up with

<$set name="damntags" filter="[list[!!thetags]] +[removeprefix[my]]">
<$text text=<<damntags>>/>
</$set>
:  {{ !!postTags }}

where thetags field has the value mytags and the postTags field has the value of the set of tags in the desired format. The output is then tags : ['Musings', 'Test', 'Boop'] as desired. Of course I had to take the returns out for the template - which has led me to looking into inline vs block mode.

I like your solution better because itā€™s nice to use the default tags behavior but itā€™s cool to come up with another way.

All this is a very long winded way of saying thank you for the help and even more the lesson!

1 Like

Oh. Thatā€™s a bug in my plugin that you wouldā€™ve been welcome to report. I havenā€™t seen this before, but I hope to fix it this weekend. (You probably have no need for it now, but others may.)

Adding custom fields to the YAML front matter is an interesting idea that I can probably add too.

Fixes announced here: Markdown Export 0.4.0