Is there a way to run a python function from a html?

def convert_page_references_to_links(text):
    # Define the patterns to search for
    patterns = [r'\(p\.(\d+)\)', r'\(p\. (\d+)\)']
    # Replace each pattern with a link
    for pattern in patterns:
        text = re.sub(
            pattern,
            r'<button style="background-color: transparent; outline: none; border: none; text-align: center; text-decoration: none; display: inline-block; cursor: pointer; border-bottom: 1px solid #46acfa; color: #46acfa;" onclick="")">p.\1</button>',
            text,
        )

    return text

I have a code like this which replaces substrings which replaces patterns like (p.XX) and (p. XX) into HTML buttons. and I would like to run a python function when one of the buttons is clicked is there a way to implement this? or does anyone know any workarounds?

please feel free to suggest any ideas. the goal is to open a page in a pdf which is the source

If you want to render custom frontend elements that communicate with your Python backend, you’ll need to create a custom component.

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