Jul 25, 2022 10:03 AM
I’m trying to format markdown in a long text field to something I can use in Zapier. The input looks something like this:
# This is a heading 1
This is a paragraph
- bulleted item 1
- bulleted item 2
- bulleted item 3
And here's a paragraph - with an embedded minus, and some more normal text
The output should look like this:
# This is a heading 1
This is a paragraph
- bulleted item 1
- bulleted item 2
- bulleted item 3
And here's a paragraph - with an embedded minus, and some more normal text
In essence, I need to replace the single newline after each paragraph with two newlines, except for the bulleted lists.
My first strategy is to use REGEX_REPLACE(source,“\n”,“\n\n”) which adds the 2 newlines everywhere. So far so good. But for the life of me I can’t find a way to remove the (now) extra newline between the bulleted items (lines starting with a “-”). It seems that the “^” (match at the beginning of a line) in Airtable’s REGEX doesn’t seem to work?
Any suggestions highly appreciated!
Jul 25, 2022 10:11 AM
I’ve also tried using
REGEX_REPLACE(source,“\n([^-])”,“\n\n$1”)
which gives me this output:
# Heading 1
And a normal paragraph after that.
And a normal paragraph after that.
- Bullet 1
- Bullet 2
- Bullet 3
And a normal paragraph after that.
And here's a paragraph - with an embedded minus
> And this is a block quote in the middle of it all.
And a paragraph following the blockquote.
## Heading 2
This is some text under the heading 2 - again with a minus embedded.
- And some more content in a bullet
- And another bullet
And some final text
So I’m close, but the first bullet in each case still needs an additional newline above it…
For what it’s worth, using the caret “^” to match a “-” at the start of a line doesn’t seem to work.
Jul 25, 2022 10:23 AM
I don’t personally know how to do this with REGEX or Zapier, but I personally use Make’s markdown to HTML converter to do this:
Jul 25, 2022 10:24 AM
Solution found - this consists of 2 formula fields:
step 1: REGEX_REPLACE(source,‘\n([^-])’,‘\n\n$1’) (let’s call this output1)
step 2: REGEX_REPLACE(output1,‘\n([^-])’,‘\n\n$1’)
that does the job. Will post here again if I find exceptions.