Markdown and return not reversible (with Concatenate)

Hi! I spend hours trying to make an integration on a canvas column without success, then debugging with many tests I discovered something I cannot really explain so I am asking for help here.

Simplifying the overall process is the following:

  1. A Text column input, where a multiline text in inserted.
  2. A Canvas column canvas, that takes Input.RenderMarkdown() using the “Rich Text Tool” pack.
  3. A Text column “markdown” that takes Canvas.ToMarkdown() using again the “Rich Text Tool” pack.
  4. A final text column “result” that just is Concatenate(markdown).

I expect that, as long there are supported markdown codes, the first and third and fourth columns have the same content. They don’t when they should or they do when they shouldn’t. For debugging I built a very simple pack that prints the (ASCII) code of each char of a string.

Let’s see the two cases:

1st case

Input columm is

a**\nb\n\nc\n\n**d

where I write “\n” where I type a new line with Shift-Enter, while typing normal Enter produces “\n\n” (I actually uses an external editor to type that and then I copy&paste into Coda input column).

Markdown column becomes

a \nb**\n\nc\n\n**c

so the conversion to markdown adds a double blank at the end the first line since the markdwon syntax prescribes to do that to create a new paragraph (the alternative is to type \n\n).

So far it seems ok.. but it’s not, since if I calculates sha(input) and sha(markdown) I get the same output while I expect different values since markdown column has 2 blanks more.

Why…?

2nd case

Input column is

a**\n\nb\n\n**c

Markdown column has exactly the same content, since Input was already markdown compliant.

Now I create a new column with just Concatenate(markdown) and… the result is

a**\nb\n**c

so… Concatenate() has halved the new lines! Same result using Join(““,…). Why??

And here if I calculate hash(input) and hash(concatenate(canvas)) I get of course 2 different values for the “\n\n” converted into “\n” (at least I think that is the reason)…

I am lost…

What’s happening in conversion to markdown and using concatenate?

thanks a lot for your help!

Giuse

PS also not using toMarkdown() formula by “Rich Text Tools” but with a simple acquisition of the Canvas rich field as a String in a pack, the result it’s same so I don’t see a problem of the RTT pack

2 Likes

I made additional tests for hours and the conclusion is that it seems unpredictable how Coda treats newlines and count of characters in a text when dealing with markdown.

I prepared a comparison table of how an initial text written in markdown (or plain text) is transformed into rich text, back to markdown, concatenated with an empty string… and weird things happen

If some Codan may shed some light…. Thanks!

Giuse

2 Likes