Tinderbox Forum

Trying to pull a list with ^action()^ and it each item is quotes, how do I get rid of the quotes

I’m using the following to generate a list,

^action($MyList=collect(children("Appendix B: Summary of Relevant Theories"),$ShortTitle+" "+$Citation);)^ ^value($MyList.replace(";",", "))^.

The list is coming out with each item items quotes “Attitude Theory (Rosenberg, 1956)”, “Diffusion of Innovation Theory (Rogers, 1962)”, “Theory of Propositional Control (Dulany, 1967)”, “Theory of Reasoned Action (Fishbein & Ajzen, 1975)”, “Protective Motivation Theory (Core) (Rogers, 1975)”, “Self-efficacy Theory (Bandura, 1977)”, “Theory of Interpersonal Behavior (Triandis, 1977)”, “Use and Gratification Theory (Blumler, 1979)”, “Theory of Planned Behavior (Ajzen, 1985), (Blumler, 1979)”, “Social Cognitive Theory (Bandura, 1986)”, .

How do I get rid of the quotes?

Michael

Tinderbox implicitly removes quotes in many contexts. But those parens are (I think) frightening it.

This will be easier in Tinderbox 9.

1 Like

Isn’t this the problem that Mark A and I found with markdown clickable links yesterday? () in lists automatically triggers quotes around that string.

Briefly, Mark found an answer that worked: we had to substitute {} for () in the list and then .replace("\{","(").replace("\}",")") once the list had been built. (The {} has to be escaped because they are special characters in regex, of course.)

In our case we’d been adding the parentheses in the collect statement, while it looks like yours are already in $Citation, so you’ll have to do an initial transform (would $Citation.replace("\(","{").replace("\)","}") do it in the collect statement so that you’re not disturbing the real contents of $Citation?).

The thread is here for the background: Tinderbox Training Video 31 - Integrating Export Code & Action Code in Your Text

Does that help?

So the $ShortTitle+" "+$Citation is what is seems to be causing the issue here. To my recollection, collect was intended for fetching all the values of an attribute from the nominated group of notes. Witness the general syntax: collect(group,attribute). The attribute is singular!

One of its prime roles was later replaces by values(), and the arrival of find() use in a designator (IOW a custom query designator) also eroded the role of collect_if().

So the first point here is should we trying (even if we want to) to use collect for string concatenations? Anyway, as the attached TBX’s test confirms, it is the presence of parentheses () anywhere in the collected attribute(s) value(s) that generated the (unwanted) quotes. There is a fix though—read on.

Firstly, unless we really want to export the list as a list, rather than use .replace(";",", ") we should use `.format(", "). Now we have a single string with a comma+space between each list item. Now, we can use .replace to string the quotes with:

.replace('\"',"")

Note in this case we do need to escape the double quote to tell Tinderbox we are citing a literal character and not opening a doube-quote-enclosed sub-string in the input parameter. The latter code also shows two further syntax points. Firstly, you can enclose the input strings in either single or double quotes as long as properly paired. Secondly you don’t have to use the same enclosing quote type for each input.

The revised action is here (line breaks in code to better fit on screen):

^action(
$MyList=collect(children("Appendix B: Summary of Relevant Theories"),$ShortTitle+" "+Citation);
)^
^value($MyList.format(", ").replace('\"',""))^

See the detail in this demo file: collect-quotes-problem.tbx (119.3 KB)

@brookter’s suggestion is also correct, but since my solution given in the thread recommended, I’ve (above) now got a better appreciation of the source problem and a simpler problem in the form of fewer replace calls.

Interesting problem, happily now solved.

1 Like

Thanks. It is getting close, but I still have a few issues.

In a few of my collected notes now the ’ is showing up and in some of the me the $ShortTitle is not returning. Also, the sort order is not the same as that of the source.

OK, at this point a sample file would help. This sort of edge case it hard to diagnose textually. I don’t see any apostrohe’s in your original example so can’t test the issue. :slight_smile:

Sort. What order are you expecting? My presumption is collect would return children in outline order (i.e. sibling order).

There isn’t one, I think this is a byproduct of using the ’ in the action code.

I was expecting the sort order to be the same out the outline (sibling order), it is not.

I’ll work up a test file in a bit.

Nothing seen here:

Could you provide an example that generates the problem on demand?

We tracked it down. One of @satikusala’s source notes was showing in a list like above with straight single quotes. The source note’s $Citation looked like this:

"(Rodgers 2007; Smith 2009)"

Note the quotes in the value. Removing those, the above list code worked. The next problem is the code making the citation string is adding back the quotes is they are removed. Why? Likely it’s because this looks a lot like a list in parentheses, i.e.:

(item 1;item 2)

But Tinderbox knows it’s a string so puts double quotes around the literal string. Essentially, this:

"(Rodgers 2007; Smith 2009)"

Is Tinderbox telling itself the string value means this (or something like that)

\(Rodgers 2007\; Smith 2009\)

So the task is now to fix the code creating the en-quoted $Citation value string.

1 Like