Reverse Parsing: Parsing a list of items with the preferred format in reverse order

Ok, I have a parsing question problem, I have a file with a list of items in the reverse order than what I want.

The list is exported as:

URL | Name 

(weird I know!) What I want is reversed and in Markdown format

 [Name](URL)

Here is a sample of the list of URL addresses:

https://forum.eastgate.com/t/literature-review-with-tinderbox/5721/33 | Literature Review with Tinderbox - Tutorials and Examples - Tinderbox Forum

https://forum.eastgate.com/t/using-tinderbox-for-talking-points/7376/11 | Using Tinderbox for Talking Points - Tutorials and Examples - Tinderbox Forum

https://forum.eastgate.com/t/sense-making-of-academic-literature-using-tinderbox/389/64 | Sense-making of Academic Literature Using Tinderbox - Tutorials and Examples - Tinderbox Forum

https://forum.eastgate.com/t/struggling-with-tinderbox-and-a-suggestion/668/144 | Struggling with Tinderbox and a suggestion - Q & A - getting started with Tinderbox - Tinderbox Forum

The format I want is…


[Name](URL)


Here is a sample of the output I want


[Struggling with Tinderbox and a suggestion - Q & A - getting started with Tinderbox - Tinderbox Forum](https://forum.eastgate.com/t/struggling-with-tinderbox-and-a-suggestion/668/144)

How do I do this?

Thinking out loud: Pseudocode: What I THINK I know:

  1. I can probably use the streaming operators or regex to extract the parts of the line I need
  2. I probably need 2 lists
  3. I probably need to use eachLine to loop through each line.

Stuck
No clue on how I can recreate each line in reverse. Any ideas?
5. Recreate the format I want using $MyString: “[” + $MyList + “]” + “(” + $MyList1 + “)”;

Here is a sample file
ReverseOrderParser.tbx (165.6 KB)

Thanks in advance
Tom

ps… those are nice articles on Tinderbox to re-read as a bonus

Late here, but as 2 stamps. First, reverse paragraph order:

$Text = $Text.paragraphList.reverse.format("\n");

The process each paragraph to Markdown:

var:list vNewLink =;
$Text.paragraphList.each(aPara){
   var:list vLink = aPara.split(" \| ");
   vNewLink += "["+vLink.at(1)+"]("+vLink.at(0)+")";
};
$Text = vNewLink.format("\n");

How’s that?

Happy New Year!

1 Like

Checking the last (written after getting in late) we can condense to one action like so:

var:list vNewLink =;
$Text.paragraphList.reverse.each(aPara){
   var:list vLink = aPara.split(" \| ");
   vNewLink += "["+vLink[1]+"]("+vLink[0]+")";
};
$Text = vNewLink.format("\n");

The above is stamp “Process links v2” in this TBX: ReverseOrderParser-v2.tbx (236.8 KB)

3 Likes

Wow… MarkA, you are a genius! Works Perfectly!

Many Thanks and Happy New Year to you and All!

BTW… the source is the export of a useful (for me) chrome extension that will combine all your lists of open tabs to OneTab. Hence the extension is called OneTab. Super useful, I use it like a read it later tabs I am working on but for whatever reason I did not get around to it. In the past, I would leave the tabs open for days. Not anymore

Tom

Hi MarkA

I am trying to understand the use case between paragraphList that you used above and the eachLine operator that I would have chosen.

What would be a good use case ratioinale for using one over the other? IOW, why did you choose to use paragraphList vs eachLine?

Thanks in advance
Tom

ps… you are certainly magical in your skill … kudos!

In my aTbRef notes for .paragraphList:

If wanting to iterate and test paragraphs, rather than chain $Text.paragraphList.each(){}, use the newer stream parsing method $Text.eachLine(){}. In both instance a line—or paragraph—is a substring—delimited by one of more successive line breaks.

But also note, under .eachLine():

When parsing text paragraphs, this operator can substitute for the older method of chaining .paragraphList.each(){}.

Oh! But the last example above, if using .eachLine we’d have to recompile the reverse-ordered $Text back into a single string to use .eachLine(). So (not tested):

var:list vNewLink =;
var:string vReverseText =; 
vReverseText = $Text.paragraphList.reverse.format("\n");
vReverseText.eachLine(aPara){
   var:list vLink = aPara.split(" \| ");
   vNewLink += "["+vLink[1]+"]("+vLink[0]+")";
};
$Text = vNewLink.format("\n");

I guess you could shorten to (again not tested):

var:list vNewLink =;
$Text.paragraphList.reverse.format("\n").eachLine(aPara){
   var:list vLink = aPara.split(" \| ");
   vNewLink += "["+vLink[1]+"]("+vLink[0]+")";
};
$Text = vNewLink.format("\n");

But does this brevity help?

Recall there is often more than one way to do things and here we need to recall we were doing a paragraph-based transform on $Text. Thus the qualification ‘can substitute’ in the aTbRef quotes above. Often there is more than one right way. There is no hidden process here as regards the loop, the only reason you might explicitly want/need .eachLine() instead of .each() is if you wanted its extra affordance of its in-loop condition feature.

See:

1 Like
  • This is the part I do not understand: why?

Broadly speaking… to summarize, in my own words , eachLine() for most use can be used instead of the older paragraphList.each() Would that be fair to say?

I will need to drill down on your above explanation and example (which is excellent) and aTBRef for my better understanding. Definitely a gap in my Tinderbox knowledge.

Cheers
Tom

Yes, these are functionally the same:

$Text.paragraphList.each(){...
// vs.
$Text.eachLine(){...

I’ve used $Text above but the source string can be any String-type attribute, variable or even a literal string: "Hello world.\nGoodbye world.".eachLine(){....

But, I don’t intend to make my docs over-prescriptive. Either works, neither is wrong nor indeed (noticeably) less efficient. Part of the point is to avoid people needlessly re-writing code when not necessary.

1 Like