reflex-dev / reflex

🕸️ Web apps in pure Python 🐍
https://reflex.dev
Apache License 2.0
19.1k stars 1.08k forks source link

The code block doesn't display the code as is or appears broken. #3889

Closed RektPunk closed 1 week ago

RektPunk commented 1 week ago

Describe the bug The code block doesn't display the code as is or appears broken. I know this is due to the "\" character, but I would appreciate it if you could show me how to fix it or how to properly use it.

To Reproduce Steps to reproduce the behavior:

  1. Example that code not displayed as is:
    
    import reflex as rx

code = """ def parse_sections_regex(text): pattern = r'<(.?)>(.?)</\1>' matches = re.findall(pattern, text, re.DOTALL) return matches """

def index() -> rx.Component: return rx.container( rx.vstack( rx.code_block(code, language="python", can_copy=True), spacing="5", justify="center", min_height="85vh", ) ) app = rx.App() app.add_page(index)

2. Example that broken
```python
import reflex as rx

code = """
def parse_sections_regex(text):
    pattern = r'<(.*?)>(.*?)</\\1>'
    matches = re.findall(pattern, text, re.DOTALL)
    return matches
"""

def index() -> rx.Component:
    return rx.container(
        rx.vstack(
            rx.code_block(code, language="python", can_copy=True),
            spacing="5",
            justify="center",
            min_height="85vh",
        )
    )
app = rx.App()
app.add_page(index)

Expected behavior Show code as is.

Screenshots

  1. First case

    image
  2. Second case

    image

Specifics (please complete the following information):

wassafshahzad commented 1 week ago

I ran the code on the development version and it appears to be fixed I am running the following code

import reflex as rx

code = """
def parse_sections_regex(text):
    pattern = r'<(.*?)>(.*?)</\\1>'
    matches = re.findall(pattern, text, re.DOTALL)
    return matches
"""

def index() -> rx.Component:
    return rx.container(
        rx.vstack(
            rx.code_block(code, language="python", can_copy=True),
            spacing="5",
            justify="center",
            min_height="85vh",
        )
    )
app = rx.App()
app.add_page(index)

Screenshot 2024-09-08 035408

RektPunk commented 1 week ago

That sounds great @wassafshahzad . Can you run the first example too, please?

wassafshahzad commented 1 week ago

First

The first one gives the following issue

RektPunk commented 1 week ago

TYSM, @wassafshahzad . Maybe, I can do what I want to do after version update.

wassafshahzad commented 1 week ago

@RektPunk That sounds good