Image in Markdown

Hey! Used this to insert images modifying a lil bit of the function to add a personal touch and it worked perfectly, thanks a lot !

1 Like

That’s great, glad it’s working for you!

1 Like

Here’s the simplest most elegant solution I ended up using:

def st_markdown(markdown_string):
    parts = re.split(r"!\[(.*?)\]\((.*?)\)", markdown_string)
    for i, part in enumerate(parts):
        if i % 3 == 0:
            st.markdown(part)
        elif i % 3 == 1:
            title = part
        else:
            st.image(part)  # Add caption if you want -> , caption=title)

I let AI write that REGEX for me, because my brain doesn’t do REGEX, so please check that. :slight_smile:

1 Like

It works, Good idea!

works like a charm :slight_smile: