Markdown Bold to HTML (regexreplace)

Hello Coda Family :slight_smile:

I’ve been trying to replace markdown imported in Coda as: *text* or **text**

and then convert it to HTML for italic or bold only.

I worked my way around the italic: text.RegexReplace('\*([^*]+)\*','<i>$1</i>')

"Why is business an infinite game? (4) " → “Why is business an infinite game? <i>(4)</i>

However, I can’t wrap my head around replacing the bold and doing it without having an overlap of the bold and italic condition since they both contain the * character :sweat_smile:

Anyone can help a regex noob?

Thank you :pray:

UPDATE: I found @Paul_Danyliuk 's regex video which was quite helpful, so now I only have to figure out the bold part. Here’s the link for those interested: Regular Expressions - YouTube

1 Like

Hi @Jay_Lefebvre,
I might look a bit more into it, but I’m afraid the only way is to chain two patterns here:

text
     .RegexReplace('\*\*([^*]+)\*\*','<b>$1</b>') // first passage to capture bold
     .RegexReplace('\*([^*]+)\*','<i>$1</i>') // second for italic

Let me know if it works (havent tested yet…).
Cheers!

1 Like

Hey Jay! I’d definitely give Federico’s suggestion a try, but I’d also like to hear more about your workflow. We convert text automatically through the API, so I’m wondering if you are copy/pasting the actual markdown code? If so, where are you copying from? We can pass this feedback along to our product team :smile:

Work’s perfectly, thank you!!! :pray:

1 Like

I’m copying from Obsidian, this is how the “raw” markdown looks like:

I don’t think there’s any bug here, if I copy bold text from the internet it will usually be pasted as bold in Coda. My “importer” wouldn’t work if the content was automatically converted to markdown since I need the characters to be able to replace them :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.