Lists of hyperlinks treated inconsistently, getting a grammatically correct linked list

I have found that lists of hyperlinks are treated in a variety of unpredictable ways by Coda, and none of these ways results in the arrangement I would like. Here’s the scenario…

  1. Create a /table with two columns, a text column called Name and a link column called “Link”. Populate the table with two rows: Eric, https://example.org and Mary, https://example.org.

  2. Create a /formula that is ForEach(Table,Hyperlink(CurrentValue.Link,CurrentValue.Name)). Note the result is “Eric, Mary” with both words blue and linked.

  3. Create a /formula that is Concatenate("Concatenate: ", ForEach(Table,Hyperlink(CurrentValue.Link,CurrentValue.Name))). Note that the result is “Concatenate: EricMary” still linked, but now missing the separating comma and space.

  4. Create a /formula that is "Plus: " + ForEach(Table,Hyperlink(CurrentValue.Link,CurrentValue.Name)). Note that the result is “Plus: [“Eric”, “Mary”]” without any links.

  5. Create a /formula that is Join(", ", ForEach(Table,Hyperlink(CurrentValue.Link,CurrentValue.Name))). Note that the result is “Eric, Mary” without any links.

So clearly Concatenate() and the + operator are doing very different things. Each of them interpret the list coming from ForEach() in a different way. And even stranger, Concatenate() and Join() also operate differently, one leaving links intact and the other removing the links. By the way, you get the exact same results if you use FormulaMap() instead of ForEach() in the formulas above.

I would like a result like 3 above, the Concatenate() example, but with the separators from the ForEach() or FormulaMap() intact. Is that possible? [UPDATE: see my solution below.]

I also think it is very confusing for Coda to be producing such different results. In particular, the discrepancy between Concatenate() and Join() is difficult to understand. [UPDATE: I now realize that Concatenate() is a list function that keeps elements intact while Join() is a string function that transforms all elements into strings.[

Can anyone explain why these results are so different? Whether Coda might be updated to be more consistent? And whether there is any formula I can use with today’s Coda that would produce the result I want (a prefix with a legible hyperlinked list following it)? [UPDATE: see solution below.]

You can copy and play with a sample doc that includes all of the above.

Well, after a much deeper dive I came up with my own solution, and a better understanding of what is going on here. See the same sample doc to see this in action.

This formula allows for a prefix and even the Oxford comma. In the case of the scenario above it will result in “We see Eric and Mary” with both names linked.

WithName(
  "We see ",
  prefix,
  WithName(
    ForEach(
      Table,
      if(
        IsBlank(CurrentValue.Link),
        CurrentValue.Name,
        Hyperlink(CurrentValue.Link, CurrentValue.Name)
      )
    ),
    linkList,
    WithName(
      CountAll(linkList),
      linkCount,
      Concatenate(
        List(prefix),
        ListCombine(
          ForEach(
            Sequence(1, linkCount),
            SwitchIf(
              CurrentValue < 2,
              linkList.Nth(CurrentValue),
              CurrentValue = linkCount && CurrentValue = 2,
              ListCombine(" and ", linkList.Nth(CurrentValue)),
              CurrentValue = linkCount,
              ListCombine(", and ", linkList.Nth(CurrentValue)),
              CurrentValue > 1,
              ListCombine(", ", linkList.Nth(CurrentValue))
            )
          )
        )
      )
    )
  )
)

I have also added to the sample doc the reasoning for the various results noted in my original query. I no longer consider this a bug, though it is still very confusing.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.