Formatting comments

  1. Tape accepts links in markdown, but not HTML
  2. Comments on external pages accepts links as HTML, but not markdown

What is the best way to work with this limitation.

Note: We are using jotform to receive and push external comments to an item. I don’t think that is relevant but I still figured I would mention it.


Note: Comments on the external page are displayed in reverse order in this screenshot.

Easy, but not free option would be to use an API such as: https://www.convertapi.com/htm-to-md (maybe you can find a free one out there but this is what I found in a quick search)

The developer option is to use regex to convert it yourself. I didn’t test this but here’s what ChatGPT spat out for me :slight_smile: You’ll need to reformat this a bit to get a proper return from a flow script but the logic itself looks like it should work as a starting point:

function htmlToMarkdown(html) {
  // Regular expression to match an HTML link
  var linkRegex = /<a href="([^"]+)">([^<]+)<\/a>/g;

  // Replace HTML links with Markdown links
  var markdownText = html.replace(linkRegex, "[$2]($1)");

  return markdownText;
}

// Example usage:
var htmlLink = '<a href="https://example.com">Example Website</a>';
var markdownLink = htmlToMarkdown(htmlLink);

console.log(markdownLink); // Output: [Example Website](https://example.com)

Hopefully that can help you build a solution!

2 Likes

Thanks a bunch!

So, this issue is that I need to push a markdown link to Tape for Tape comments to render the link. But then when calling the comments over to an external page the markdown link is stripped because html is needed to render the link.

Is it just the reverse of what I mentioned then - instead of converting Markdown to HTML, you want to convert HTML from Jotform to Markdown before putting it into your Tape comment? Not sure if I’m understanding correctly.

2 Likes

I’m pretty sure that the markdown link comes over as just the anchor text when you pull it over to the external page.

I’ll give it a go and then report back with my findings.