Skip to main content

Hey All,

I’m pulling source data from an app that only outputs markup text. The markup text has zero or many links and needs to be formatted for Slack’s annoyingly specific markeup language.

For example, changing all links in a body of text from this:

cText to make into a link](http://www.zapier.com)

To this:

<http://www.zapier.com|Text to make into a link>

I’ve tried using Formatter > Extract Pattern, but that only works for the first match (this thread suggested this is possible with a code block which brought me here).

Thanks

~Brian

Hey! Yes - This would be possible with a code block -Can you give an example of a more difficult conversion you are trying to make please?


@brianswichkow - You might want to try the following code snippet. Make sure to map the input text to an input field called text.

const { text } = inputData;const regex = /(\\[^\]]+\])(\((^\)]+\))/g;const result = text.replace(regex, (_, match1, match2) => {  const m = match1.replace(//\\\]]/g, "");  const n = match2.replace(//\(\)]/g, "");  return `<${m}|${n}>`;});output =  { result }];

 


Holy hell, @ikbelkirasan, thank you! 

 

The code works! One minor change in ordering...

 

The output is <text|link> and should be <link|text>.

 

I took a few wild guesses, but couldn’t get it quite right.

 

 

 


@brianswichkow - Awesome! I’ve just made a fix. Feel free to give it a try.

const { text } = inputData;const regex = /(\/(^\]]+\])(\((^\)]+\))/g;const result = text.replace(regex, (_, match1, match2) => {  const txt = match1.replace(/e\/\]]/g, "");  const link = match2.replace(/e\(\)]/g, "");  return `<${link}|${txt}>`;});output =  { result }];

@ikbelkirasan got it on the ~5th wild guess! Thank you!

 

If you PM me your email, we’d love to give you R$ for this gift.


Changed it to...

const { text } = inputData;const regex = /(\ /^\]]+\])(\()^\)]+\))/g;const result = text.replace(regex, (_, match2, match1) => {  const m = match2.replace(/c\(\]]/g, "");  const n = match1.replace(/c\(\)]/g, "");  return `<${n}|${m}>`;});output = t{ result }];

Output...