Splitting and re-assembling a list with wikitext

I’m slowly going to try to take @saqimtiaz 's challenge to build a wikitext only version of a streams-like outliner. It’s funny though, I always get hung up on the parts that should be easy!

Say I have an existing outline that looks like:

* Point A
** Point A1
** Point A2
* Point B
** Point B1

I need to return a version of the rendered version of this but with say a button at the end of each of the lines… I’m getting hung up with joining it and having it render the same as it was… Logic would say it’s something like:

<$list filter="[<currentTiddler>get[text]splitregexp[\n]]">

<<currentTiddler>><$button>test</$button>
</$list>

Now if I don’t leave the line above <<currentTiddler>> then the *s don’t render as <li>'s but when the line is there, then the rendered list ADDS extra lines between the bullet points…

I remember threads around all the different ways of adding spacing etc but I’ve been trying things for an hour and unable to figure it out.

Here’s a before and after (top is input and bottom is output) without the extra line:

And then if I add the extra line:

1 Like

I am not entirely sure what your end goal is. However, do you need to split and re-assemble or do you just need to insert buttons?

Something like this might work to just insert buttons at the end of each line:


<$list filter="[[test]get[text]search-replace:mg:regexp[(.)$],[$1<$button>test</$button>]]">

<<currentTiddler>>
</$list>

You might need 5.2.0 for that.

If you want to insert a line break back into the line after using the splitregexp, without needing 5.2.0 I have seen @EricShulman creating a macro containing a line break but can’t find it in my notes.

You would then add it back eg addprefix<line-break>

I have looked through my notes but cant fine it, normally an “empty” macro definition throws an error.

eg this contains a line break but does not work.

\define line-break()

\end

Depending on the application you can use <br> have you tried;


<$list filter="[<currentTiddler>get[text]splitregexp[\n]]">

<<currentTiddler>><$button>test</$button><br>
</$list>

Also since you are using bullets, perhaps fall back to html and wrap the list in <ul><$list ...</ul> and the items in the list <li>item</li> rather than trying to make it need to render the wikitext “*”

@saqimtiaz thanks, that does work though does require 5.2 for the multiline flag usage. I was hoping to avoid that, but maybe it’s not possible.

@TW_Tones I tried that (the macro version) too, but thought it was odd that it didn’t work. What did work that was similar was to have a whole tiddler as line-break and then use {line-break} where you suggested <line-break> (aka use transclusion instead of macro). That part isn’t my problem though unfortunately.

I was trying to use an example to make the problem more clear, but I might’ve confused things. I believe the problem I was getting at is essentially having <$list> return the components of a wikitext list and have it wikify normally - mean show as a normal bullet list. I remember a post a while ago where one of the gurus here (maybe @EricShulman ?) said it was due to extra html tags or something getting in the way. I thought there was a way to kind of workaround or patch it via a parameter of list or something…

Here’s a more tailored example (in animated gif form) of just generating 10 lines starting with the * character. I go through the different obvious ways of trying to get to a normal bulleted list, but I either get a tight non-wikified list, or a loose (extra lines) wikified one.

listbuilding

Does this ring a bell to anyone? If I can solve this, then I can solve my real problem. Thanks in advance!

Sorry I forgot to address this. I’m hoping to avoid this, because in my real scenario, I have many levels in the outline, and reverse entering the user’s nested *#'s back into html would be a huge effort programmatically.

I will have a look tomorrow If possible. I am quite sure I solved this.

But of the top of my head, have you considered using the template parameter on the list widget? - much of the core does this for “listitems”

Thanks @TW_Tones , I did try it for this ( though I’d never used it before) and it didn’t seem to change much, though maybe I was doing it wrong.

To add a bit more of an explanation around why I need this solved, in my conversation with @saqimtiaz , we agreed that for a single tiddler outliner, a flow that made sense would be to parse/copy out the text to 1 tiddler per bullet. For the “editor view” then I have to show all of the broken out tiddlers as if they are 1 outline with the one being edited as an edit-text. So, I would use a list widget with a filter to gather the broken out tiddlers, and need them returned such that the ones starting at various levels of nesting display as expected. This is where I’m stuck, because something extra seems to be returned that interrupts the intended behavior.

I learned this from the streams plugin demo page. Is this helpful?

<$vars br="""
""">
<$list filter="[<textHere>addsuffix<br>addprefix[* ]]">
<<currentTiddler>>
</$list>
</$vars>

I use it all the time :smiley:

Thanks @sull-vitsy, that doesn’t seem to make the difference either.

Let me give a longer walkthrough with some testable code so it’s easier for others to see the real issue.

Say you start with a VERY simple outline like this:
image

For the outliner project, you’d click an “edit” button and it would parse the lines into other tiddlers say named things like line1, line2, line3

image

Okay, so now I have 3 separate tiddlers while I’m in edit mode. Now to build an edit view I need to present the 3 of them back together keeping their outline level. The equivalent to your code @sull-vitsy (I believe) would be this then:

image

As you can see on the right, it ignores the line break, and even if I use the transclusion method to put the newline in there, it’s not parsed correctly. (for this I have a tiddler named newline with a newline in there)

I know the answer is usually to add a blank line before the <<currentTiddler>> so that it happens in “block mode” rather than “inline mode” (I may just be confused here though). Anyways, with that it produces:

image

Kind of better? It at least shows the bullet points as actual bullet points, but you can see that aside from the extra row/vertical space, that anything non-top-level it doesn’t really work (see the 2 separated bullets on the second row).

Going into developer tools and looking at how TiddlyWiki is generating HTML:

This is the original input look (what it should end up being)
image
Here you can see it’s properly nested

Your code (the code without the line before <<currentTiddler>> as you posted @sull-vitsy) generates:
image
So I can tell it’s not being “wikified” as it’s just a paragraph with the *s as just text

And finally the last example goes too far by starting each line as it’s own <ul>
image
Here you can it’s gone too far and started each line with it’s own <ul> which is what’s causing them not to be part of the same outline, but rather 3 totally separate ones.

Now @saqimtiaz gave me a filter code using the m regex parameter within the filter for something simple like adding something to each line which avoids the whole "inside of the <$list>" issue I’m having, but once I solve this, rather than all of these lines just having <<currentTiddler>> some will actually be <$edit-text> widgets with it’s own code, actions, keyboard shortcuts assigned etc. so it wont’ be simple enough to bake all into the filter as an addsuffix.

In case anyone has a minute to test another idea, I’ve attached the tiddlers here that you can drag into a fresh TiddlyWiki.com instance to see what I mean. The challenge is to rewrite the view tiddler so that it renders like input.

tiddlers.json (737 Bytes)

Sorry, I’m probably not understanding the issue… but are you trying to get this?

<ul><$list filter="..."><li><<currentTiddler>></li></$list></ul>

Ah, I did miss this…

but you can do filter="[...addsuffix<heavy-duty-macro-stuff> ...]", right?

1 Like

@CodaCoder - I think if I was just appending some static values that makes sense, but I’m struggling with putting a bunch of ‘code’ in there. For instance, some of the lines I actually want to return the value of the text within those tiddlers, but in others I want to return an input field (edit-text widget).

For one I’m not sure how I can “pass” the tiddler name into the macro for testing without the title always coming through in the results. Addsuffix means the additional logic is only after the text is returned. Even aside from that, the macro stuff doesn’t get wikified at all and is returned from the addsuffix as the text of the code. I’m not sure how to sneak a wikify widget betwen the filter operator and the subsequent filter operator.

For example I think this is more or less what you’re suggesting? Assuming what I want to do is return the outline most of the time, but for one of the lines show it in edit mode (via widget):

\define code() 
<$list filter="[<currentTiddler>match[line3]]"><$edit-tiddler tiddler="line3" tag="input"/></$list>
<$list filter="[<currentTiddler>!match[line3]]">{{!!text}}</$list>
\end

<$vars br="""

""">
<$list filter="[prefix[line]sort[]addsuffix<code>join<br>]"></$list>

</$vars>

That outputs this:

line1<$list filter="[match[line3]]"><$edit-tiddler tiddler=“line3” tag=“input”/></$list> <$list filter="[!match[line3]]">{{!!text}}</$list> line2<$list filter="[match[line3]]"><$edit-tiddler tiddler=“line3” tag=“input”/></$list> <$list filter="[!match[line3]]">{{!!text}}</$list> line3<$list filter="[match[line3]]"><$edit-tiddler tiddler=“line3” tag=“input”/></$list> <$list filter="[!match[line3]]">{{!!text}}</$list>

The whole line3 would actually be more complicated as that wouldn’t be hard-coded but as a result of other test and variables stored for which line the user wants to edit.

@stobot there has being some activity in this thread over night for us Australian’s

One thing I noticed in your inspect shapshot is the <ul></ul> is reoccurring or nested, when in fact unless there are more than one list you only need this once outside the first list. If tiddlywiki is doing this, and possibly erroneously, instead use the html tags yourself .

However I also note normally to represent a bullet indented under another eg line2 requires A <li>inside another li tag</li>

I may be wrong but I think the solution may be the use of a recursive macro one that calls itself, to drill down into each bullet point. That macro needs to handle;

  • Identifying the content within that bullet
  • Any bullets within/below it (call self for each)
  • Supporting edit and save back

As far as I can see if you extract each bullet point to a line each, I can’t see the hierarchy any more except for the “*” or “**” and the order, that is you are relying on the wiki-text to indicate the depth of each line. In effect you are flattening the data and relying on the wiki-text to reconstitute the hierarchy.

I will think about this further but I think the problem is you are coming up hard against some of the assumption’s in the tiddlywiki parser, for example we need only provide “*” for a bullet point, but HTML needs to wrap this list with “<ul>” so the parser “guesses” where to place it.

So as I suggested perhaps de-emphasising the reliance on the parser by using html tags, would make sense.

  • However to do this you need an alternate way to handle the “hierarchy” than the “*”.

I hope this can help.

Thanks @TW_Tones but honestly if I have to essentially recreate the whole logic that the parser already does to handle both numbered and bulleted lists, combinations of them, and handling lines with neither all inter-mixed, then the scope of the project is at least double or triple what I intended when I started. In that case I’m probably going to abandon the project and just continue to use Saq’s editor-autolist instead. I’m disappointed, but appreciate everyone’s thoughtful suggestions.

Hello all, well I apparently couldn’t give up on the idea, so went back to the drawing board and am taking a different approach that is working so far. Just in case there are others interested in seeing this concept finished (lightweight outliner editing experience of existing wikitext bulleted list), I thought I’d post a little gif of progress so far:

bullets

Still lots to get done and figure out, but happy with recent progress. It’s wikitext only (no javascript) and just a lot of regex, search-replace, and action-tiddlers. I intend to make it a different edit button to launch the mode on any existing tiddler, regardless of the content (support tiddler bodies that contain non-outline stuff) and make it compatible with the edit-comptext plugin.

4 Likes

Excellent. Very pleased to see you making progress with this. Kudos for taking this on.

2 Likes