counter command to filter operator "jsonstringify"

41 views
Skip to first unread message

Torax Malu

unread,
Jan 16, 2020, 12:42:36 PM1/16/20
to TiddlyWiki
Hi,

I try to append to the text of $:/DefaultTiddlers a new line. I get the content of this tiddler via following souce and add new text:

<!--
set in variable text a search pattern / adding-text
-->
<$set name="tag" value="[all[]has:field[atc.pinned]]">
    <!--
    Get $:/DefaultTiddlers!!text
split result at LF to breakup the resulting string into a list
search in resulting list for content of variable tag
count result
save result in variable existingEntry
   -->
    <$list variable="existingEntry" filter="[[$:/DefaultTiddlers]get[text]splitregexp:m[\n]search::literal<tag>count[]]">
        <!-- if variable existingEntry = 0 -->
        <$list filter="[<existingEntry>match[0]]">
<!--
get content of $:/DefaultTiddlers!!text
encode it into a JSON-String (in addition escaping LFs as "\n")
append "\n" (to get a new line / LF)
append variable tag
save result to variable "newDefaultTiddlers"
-->
            <$list
  variable="newDefaultTiddlers"
filter="[[$:/DefaultTiddlers]get[text]jsonstringify[]addsuffix[\n]addsuffix
<tag>]">
                <<newDefaultTiddlers>>
            </$list>
        </$list>
    </$list>
</$set>
 

So, I have now a JSON-encoded string. question is, how to get back a normal string with interpreted escape-sequences to replace the content of $:/DefaultTiddlers!!text with the new string.

Thanks for help

Cheers

ToraxMalu


Torax Malu

unread,
Jan 17, 2020, 3:24:41 PM1/17/20
to TiddlyWiki

Hi @all,

 

if someone tries to solve my problem, it is solved and thanks for the try. In short, I simply misunderstood the whole TW-concept with filters and how to store values in the tiddlers.

 

Here is my solution see below.

 

Only ugly side effect: possible used line feeds in $:/DefaultTiddlers are replaced by space.

 

Cheers.

 

Torax

 

\define pinfieldfilter()
[has:field[atc.pinned]]
\end

\define newDefaultTiddlers()
<$set name="defaultTiddlerTXT" filter="[[$:/DefaultTiddlers]!is[missing]get[text]split[ ]splitregexp[\n]]"><$list filter="[<defaultTiddlerTXT>search<pinfieldfilter>count[]match[0]]"><$set name="newDefaultTiddlersTXT" filter="[enlist<defaultTiddlerTXT>append<pinfieldfilter>]"><$text text=<<newDefaultTiddlersTXT>> /></$set></$list><$list filter="[<defaultTiddlerTXT>search<pinfieldfilter>count[]!match[0]]"><$text text=<<defaultTiddlerTXT>> /></$list></$set>
\end

\define addTiddllerControls()
<table><tr><td><$checkbox field="atc.pinned" checked="true" unchecked="false" default="false" checkactions="""<$wikify name="neuerText" text=<<newDefaultTiddlers>>><$action-setfield $tiddler="$:/DefaultTiddlers" $field="text" $value=<<neuerText>> /></$wikify>""" uncheckactions="""<$action-deletefield $field="atc.pinned" />""">&nbsp;&nbsp;📌</$checkbox></td></tr></table>
\end


Am Donnerstag, 16. Januar 2020 18:42:36 UTC+1 schrieb Torax Malu:
Hi,

I try to append to the text of $:/DefaultTiddlers a new line. I get the content of this tiddler via following souce and add new text:


Reply all
Reply to author
Forward
0 new messages