A Filter Question: Split Text

I have a tiddler like this

This is first part

! Heading 1
This is the upper middle part

!! Heading 2
This is the lower middle part

! Heading 3
This is the last part

and look for a filter to split it to:

This is first part

! Heading 1
This is the upper middle part

!! Heading 2
This is the lower middle part

! Heading 3
This is the last part

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).

e.g.
before node split:

Splitting node alt+enter:

after node split :

(with Streams default configuration

)

2 Likes

Hi Frederic

The main question

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!

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!

looks nice! I see you can manually split a tiddler! but check if you can split as I explained in previous post e.g based on headings!

Would just a split by newline followed by exclamation point do that? I would think that would get your split.

The harder part would be the editor part because you’d need some kind of unique id so you could do a replace section after editing.

1 Like

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.

Mohammad,

I believe the best approach to this, starts like this below;
I have not worked through the total solution yet.

I may also point out there are some solutions similar to what you ask already out there. I will share if I find them.

<$wikify name=TestHeadings text={{TestHeadings}} output=html>
<$text text=<<TestHeadings>>/>
</$wikify>

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

<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="excise"
	title={{$config-title$/new-title}}
	type={{$config-title$/type}}
	macro={{$config-title$/macro-title}}
	tagnew={{$config-title$/tagnew}}
/>

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.

snapshot.json (6.2 KB)

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.

@sull-vitsy - thank you! your method works! I will go through it to see how can I use it
in the section editor!

I let you know the feedback!

@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.

Or do I misunderstand something?

3 Likes

:wink: :sweat_smile: getting old makes doing things difficult if not impossible!

Thank you Mat!

Your solution is correct! The find macro which is belong to ancient time, do a similar task, except it needs a start/stop delimiter!

It should be manageable to treat the first/last part of a tiddler text where there may not available the start or stop delimiter!

@twMat thanks so much for that comment. I new there was a way and using the first and rest operators allow on to process a list.