Hi Mohammad, I find your problem intriguing.
Just to confirm, are you trying to split the single tiddler into 4 different tiddlers in this case?
Streams has a powerful text splitting function that will turn a single node into a number of nodes (configurable split sequence, such as \n\n which would probably work in your case).
The actual question is to split a tiddler into sections!
Each section is start by a heading (h1, h2 not h3 or more)
We may have a preface (some text before first section)
Ultimate purpose!
If so, then I can have a section editor in place or on the sidebar!
we can develop tools to click on a heading and see sidebar editor with just that section! of in place editor!
Note: I know I can do this using multiple tiddler and if you look in TW-Script, you will see we have developed such tool several years ago! look for Folding editor and inline editor!
The quickest way might involve structuring you document with custom HTML tags, so you can use those tags to identify logical sections of your document for section editing?
<part s="First">
This is first part
<part s="UpMid">
! Heading 1
This is the upper middle part
<part s="LowMid">
!! Heading 2
This is the lower middle part
<part s="Last">
! Heading 3
This is the last part
That makes for very explicit things you can use for filtering each section.
Where TestHeadings is your example tiddler. We get this result; <p>This is first part</p><h1 class="">Heading 1</h1><p>This is the upper middle part</p><h2 class="">Heading 2</h2><p>This is the lower middle part</p><h1 class="">Heading 3</h1><p>This is the last part</p>
I think TT and others have already published the regex to now parse this html result to divide the content as you would like. This approach has the advantage of allowing you to parse the result not only the text field (pre-render) even the output of list widgets and macros.
This should allow you to generate sub tiddlers, and perhaps an ultimate solution could be made by using concepts from the excise editor toolbar
$:/core/ui/EditorToolbar/excise
$:/core/ui/EditorToolbar/excise-dropdown
I think ultimately I am moving towards a set of solutions that operate on post rendered content to close what I see are substantial gaps . However don’t expect this soon, it is more part of a strategic direction for me.
My first related tool was to take a snapshot of a tiddler as HTML, then display that, so it need not be re-rendered, important for tiddlers with a lot of processing for which you do not need to see immediate updates.
Hi. I’m a google groups lurker (now talk tw) and I’ve been waiting my whole tiddlywiki life for tiddler text splitting to be brought up. I am hyped. Some time ago I tried to work on this problem myself in order to wrap my head around wikitext. I’ve dumped the results of my playing around here: https://sull-vitsy-sandbox.tiddlyhost.com/
It is a very crude attempt by a newbie tw user. It splits the text field directly without rendering to html first. It relies mostly on the splitregexp[] operator.
Some things work, some things don’t. I didn’t even know what regexp was before I tried this, but your regexp in tiddlywiki documentation helped a lot. Hoping that this discussion picks up more, because this would really improve my tiddlywiki use case.
PS: I was able to split a text field by h1s, but no success with multi-level headings yet.
@Mohammad - you’ve solved much more difficult problems!
But OK: It takes a recursive loop; use a regexp filter to split the text at the first desired place (i.e before the newline+!), display the first element and resend the rest to the macro again.