I have a bit of logic around this in my Advanced Doc Connections (aka Cross-doc Plus) pack. Happy to share privately if you aren’t building a competing pack.
In general I think the logic is that you should consider the value plain text if it both starts and ends with triple ticks. I thought that this could be an issue with text values which contain only a code block, but in those cases we appear to drop the closing triple ticks:
^ I think that would only remove the first triple ticks, and you’d want to remove the ending one as well.
As for the ending triple tick being needed for code blocks, it seems to depend on the destination for that markdown and what their parser accepts. In a brief survey some seem to support unclosed triple ticks and others don’t. Notably the parser used by the Pack value hint Markdowndoes seem to require it.
It probably does make sense to close the triple ticks, but you’ll probably need to count how many there are in the doc, and if there are an odd number then to add a closing one at the end.
function recoverText(text) {
// converts ```\`\`\`test\`\`\```` to test
if (text.match(/^```.*```$/)) {
text = text.replace(/^```/, "").replace(/```$/, "");
}
text = text.replace(/\\`/g, "`");
return text;
}
Never noticed any slowness there tbh. Or at least I wouldn’t think this could be the slowest part.
P.S. I’m supplying the result into a coda.ValueHintType.Markdown column in a sync table, so I actually want to preserve markdown if it’s proper markdown, and only unwrap the plain text from those backticks, and escape all markdown-like characters in the plain text value.
It’s a steep learning curve, the symbols are really arcane, and they change depending on the context [^abc].* means “nothing that matches a, b, or c” whereas ^abc.* means “nothing that begins with ‘abc’”
In my opinion, yes 100%. Outside of programming it’s supported by many applications in the find and replace dialog, and can save you a ton of time if you need to filter or manipulate lists of data. There are Coda formulas that uses them as well!
Yeesh - I never knew regex was that beloved. @Paul_Danyliuk I’ll check out your lesson - The amount of coda I have learned from your posts are insane… Side note: I really appreciate that you always make your stuff copyable. You could totally make your examples read only and bait people into some sort of payment for the doc (I’m not saying that having people pay for a service (doc) is wrong) - I just personally appreciate it.
Btw, I don’t mean to diminish your contributions @Connor_McCormick1 . I have seen a ton of stuff from you recently that Is really interesting…I’m more of the “Can i cheat on you for the test” type of coda community goer haha…
Haha thanks for your nice note, I’m so with you, @Paul_Danyliuk’s contributions have been enormously helpful to me, too. Imo the Coda community is what it is today only because of Paul’s consistent and brilliant contributions.