Some coding fun: dump a tiddler line-by-line into a data tiddler

219 views
Skip to first unread message

Charlie Veniot

unread,
May 10, 2021, 11:31:59 PM5/10/21
to TiddlyWiki
Just scratching a coding itch.

Modify the code in the button, changing the "Some Tiddler" instances to an existing tiddler in your TiddlyWiki.  (I've been playing with TiddlyWiki.com for the giggles.)

Put this code in some tiddler and save the tiddler.  Then, press the button, and take a look at the new tiddler named the same as this one, but with the added suffix " Data".

<$button>
<$vars newLine="
" >
<$vars nCount={{{ [[Some Tiddler]get[text]split<newLine>count[]] }}}
            thisTiddler=<<currentTiddler>>>
<$list variable="line-num" filter="[range<nCount>]">
<$action-setfield $tiddler={{{ [<thisTiddler>addsuffix[ Data]] }}} $index={{{ [<line-num>addprefix[line]] }}}, $value={{{ [[Some Tiddler]get[text]split<newLine>nth<line-num>] }}}/>
</$list>
</$vars>
</$vars>
Click me!
</$button>

Why code that?  I'm just got this festering thought: how would I go about creating an alternative tiddler editor with "code folding", using only TiddlyWiki?

Well, I think it starts with first finding a way to split a tiddler into its individual lines.

Just an exercise for the $hit$ and the giggle$, possibly coming to a fiery end  when I hit the wall ...

TW Tones

unread,
May 10, 2021, 11:55:33 PM5/10/21
to TiddlyWiki
Cj

Remember its possible to do this [[some tiddler]get[text]splitregexp[\n]] to separate the lines.

Rather than split<newLine>

Tones

Charlie Veniot

unread,
May 11, 2021, 8:58:16 AM5/11/21
to TiddlyWiki
I couldn't get \n working, so I gave up.  Thanks!

TW Tones

unread,
May 11, 2021, 8:06:40 PM5/11/21
to TiddlyWiki
Charlie,

Try this on tiddlywiki.com in a new tiddler. It extracts lines from HelloThere and seperates them with a line.

<$list filter="[[HelloThere]get[text]splitregexp[\n]]" variable=line-content >
<<line-content>><hr>
</$list>

Tones

Charlie Veniot

unread,
May 11, 2021, 8:20:50 PM5/11/21
to TiddlyWiki
Yeah, but it isn't just about seeing the lines.  It is about being, eventually, able to edit/delete/add/move lines.

Charlie Veniot

unread,
May 11, 2021, 8:22:56 PM5/11/21
to TiddlyWiki
Okay, inching closer to something.

For anybody interested in tracking the evolution of this coding project, import the attached into TiddlyWiki.com for some safe experimenting:
Tiddler Viewer Package.json

TW Tones

unread,
May 11, 2021, 8:30:51 PM5/11/21
to TiddlyWiki
Got it,

Codemirror is able to seperate lines, perhaps have a look there to see if there are some solutions.

Best of luck
Tones

Charlie Veniot

unread,
May 11, 2021, 8:49:09 PM5/11/21
to TiddlyWiki
Well, current plugin is meh.  I'm not particularly impressed.  

Being no fan of javascript, I am very interested in the question:  how would I construct a Tiddler Editor in TiddlyWiki with nothing but native TiddlyWiki code + HTML + CSS ?

Whatever it is, it must have code folding.  I haven't put much other thought regarding requirements.

Charlie Veniot

unread,
May 11, 2021, 9:00:14 PM5/11/21
to TiddlyWiki
Well, when I get to the point of trying to duplicate anything that Codemirror plugin does, I may quickly find myself very impressed by the plugin.

Like I often say lately, as it quickly becomes a favourite in various forms:  the opportunity to eat crow can open up for dining pleasure around any corner.

Mat

unread,
May 12, 2021, 6:19:55 AM5/12/21
to TiddlyWiki
I would also like a native solution for code folding in the editor.

It may be too complicated but rather than line folding, it would make more sense with "widget folding" by using the opening and closing tags of widgets, macro defs and html tags.

Second best would be to use indentation level.

<:-)

Charlie Veniot

unread,
May 12, 2021, 8:53:37 AM5/12/21
to TiddlyWiki
Folding the lines is usually based on keywords, whatever between the starting keyword and ending keyword getting folded.

I don't know of any other way to have code folding.

So yes, things like widget tags, macro defs, html tags, comment tags.

Although the philosophy of tiddlers is to keep the small, they can get easily get pretty big when delving into more than wikitext (i.e. programming with widgets and macros, and formatting with html elements.)

TW Tones

unread,
May 12, 2021, 7:29:38 PM5/12/21
to TiddlyWiki
I have some faded memories of seeing some code folding. However the code highlighting features get you part of the way functionally.

My guess it beyond building a code folding viewer (which may be moderately easy), an extension to the CodeMirror plugin may be the quickest route to this feature in an edit mode. CodeMirror has a life of its own outside tiddlywiki, it may have a folding feature that could be incorporated. 

Tones


Mohammad Rahmani

unread,
May 13, 2021, 12:12:17 AM5/13/21
to tiddl...@googlegroups.com
Charlie,

Why does this JSON need two steps for import?
- drag and drop you attached JSON to Tiddlywiki, imports Tiddler Viewer Package
- clicking on Tiddler Viewer Package opens the $:/Import again for the second time? 
It asks for another import as below. Is this intentional?

 
image.png


Best wishes
Mohammad


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/ff637e22-050e-4787-9537-b0323ff604e9n%40googlegroups.com.

Charlie Veniot

unread,
May 13, 2021, 7:37:17 AM5/13/21
to TiddlyWiki
Because somebody somewhere suggested I do the JSON thing for packaging tiddlers instead of putting them in a ZIP file, and this is the result of my understanding of what I was suggested to do.

Maybe I missed something. 

Mohammad Rahmani

unread,
May 13, 2021, 1:27:30 PM5/13/21
to tiddl...@googlegroups.com
Charlie,

On Thu, May 13, 2021 at 4:07 PM Charlie Veniot <cj.v...@gmail.com> wrote:
Because somebody somewhere suggested I do the JSON thing for packaging tiddlers instead of putting them in a ZIP file, and this is the result of my understanding of what I was suggested to do.

lol ! Somebody (he is not me!)

 

Maybe I missed something. 

Of course you did something interesting!


You can export in JSON using many tools including the advanced search page!
I have recorded a  screencast for you!

1. Open riddles you like to export in the story river
2. Open the $:/AdvancedSearch
3. Go to Filter tab
4. Select the Filter: Tiddlers in story river
5. Export as JSON

img_155_%pn.gif


 

Mohammad Rahmani

unread,
May 13, 2021, 1:43:13 PM5/13/21
to tiddl...@googlegroups.com
On Thu, May 13, 2021 at 4:07 PM Charlie Veniot <cj.v...@gmail.com> wrote:
Because somebody somewhere suggested I do the JSON thing for packaging tiddlers instead of putting them in a ZIP file, and this is the result of my understanding of what I was suggested to do.

Maybe I missed something. 

Confidential:
I do not know how you created the JSON in your previous post, but let's do something NOT allowed legally by Tiddlywiki!
  1. Open your JSON (Tiddler Viewer Package.json you posted above) in a text editor , no matter what it is!
  2. Find "plugin-type":"import" at the end of file
  3. Change it to "plugin-type":"plugin"
  4. Save and drag and drop into https://tiddlywiki.com/prerelease/  (or your own Tiddlywiki)
  5. What you see?!!! 
  6. You made a plugin illegally ;-)
  7. This way you can make a plugin in Browser (the KISS way)!
  8. Let's keep this secret ;-)
This is what you see then!
image.png

So you made a plugin by accident!



Cheers
Mohammad

Charlie Veniot

unread,
May 13, 2021, 1:44:43 PM5/13/21
to TiddlyWiki
Ahhhhhhhhhhh.  Now I get it.  Thanks!

TW Tones

unread,
May 13, 2021, 7:22:17 PM5/13/21
to TiddlyWiki
Mohammad et al

Nothing is illegal, may be unwise but this a is useful, especially for data tiddlers (Ie a package of tiddlers containing data to be processed by the wiki) . Later I plan to make an easy to use plugin update process.

I am possible the someone mentioned here " Why does this JSON need two steps for import?"

If you use the import mechanism to generate a JSON and don't remove the plugin-type import status pending, you basically capture the import in progress.
Export or drag this tiddler to another wiki and the import process occurs "again". The value in this is such packages Allow the user to select or review the tiddlers imported. This is useful if you are using this to import data and want to give an intermediate step to the user.

Regards
Tones

Charlie Veniot

unread,
May 13, 2021, 7:41:53 PM5/13/21
to TiddlyWiki
On Thursday, May 13, 2021 at 8:22:17 PM UTC-3 TW Tones wrote:


If you use the import mechanism to generate a JSON and don't remove the plugin-type import status pending, you basically capture the import in progress.
Export or drag this tiddler to another wiki and the import process occurs "again". The value in this is such packages Allow the user to select or review the tiddlers imported. This is useful if you are using this to import data and want to give an intermediate step to the user.

Regards
Tones

Damn it, again.  Something I was thinking without knowing I was thinking it, and somebody expressing it better than I could have.

I knew there was something about the approach I liked.  

Bravo!  Sure, I may have a few non-complimentary-names-out-of-envy floating about in my cranium, but BRAVO!
 
Reply all
Reply to author
Forward
0 new messages