Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new lines in gr.Markdown #5356

Closed
1 task done
hysts opened this issue Aug 27, 2023 · 5 comments · Fixed by #5368
Closed
1 task done

new lines in gr.Markdown #5356

hysts opened this issue Aug 27, 2023 · 5 comments · Fixed by #5368
Assignees
Labels
bug Something isn't working

Comments

@hysts
Copy link
Collaborator

hysts commented Aug 27, 2023

Describe the bug

Not sure if this is a bug or just a breaking change, but the way gr.Markdown handles line breaks seems to have been changed in gradio==3.41.x.

Consecutive lines in markdown are often rendered as one long line unless there is blank line in it. GitHub renders markdown that way, and also it was the way gr.Markdown rendered markdown with gradio==3.40.1.
But now with gradio==3.41.2, consecutive lines are rendered as separate lines. Is this an intentional change or a bug?

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

import gradio as gr

markdown = """
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
the lazy dog.

The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog. The quick brown fox jumps over\
the lazy dog.
"""

with gr.Blocks() as demo:
    gr.Markdown(markdown)
demo.queue().launch()

https://huggingface.co/spaces/hysts-debug/markdown-new-line-gradio-3-40-1
https://huggingface.co/spaces/hysts-debug/markdown-new-line

Screenshot

gradio==3.40.1

gradio==3.41.2

Logs

No response

System Info

Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 3.41.2
gradio_client version: 0.5.0

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
altair: 5.0.1
fastapi: 0.103.0
ffmpy: 0.3.1
gradio-client==0.5.0 is not installed.
httpx: 0.24.1
huggingface-hub: 0.16.4
importlib-resources: 6.0.1
jinja2: 3.1.2
markupsafe: 2.1.3
matplotlib: 3.7.2
numpy: 1.25.2
orjson: 3.9.5
packaging: 23.1
pandas: 2.0.3
pillow: 10.0.0
pydantic: 1.10.12
pydub: 0.25.1
python-multipart: 0.0.6
pyyaml: 6.0.1
requests: 2.31.0
semantic-version: 2.10.0
typing-extensions: 4.7.1
uvicorn: 0.23.2
websockets: 11.0.3
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2023.6.0
httpx: 0.24.1
huggingface-hub: 0.16.4
packaging: 23.1
requests: 2.31.0
typing-extensions: 4.7.1
websockets: 11.0.3

Severity

I can work around it

@hysts hysts added the bug Something isn't working label Aug 27, 2023
@pngwn
Copy link
Member

pngwn commented Aug 27, 2023

This was intentional in order to make it consistent with our other uses of markdown in gradio.

This consistent with how markdown behaves in GitHub comments but not in rendered files.

If we change this settings we'll need to change it for everything.

@hysts
Copy link
Collaborator Author

hysts commented Aug 27, 2023

Thanks. I see. Yeah, GitHub renders lines in comments in separate lines, but GitHub renders consecutive lines in README.md etc. in one line, and VS Code also renders markdown in the same way.

I feel like there are pros and cons to both, so maybe it would be nice to have an optional argument in gr.Markdown to switch how to render lines.

@abidlabs
Copy link
Member

I think its better not too add too many parameters to gr.Markdown(). Since there's a very easy workaround, I'd prefer marking this as a breaking change and moving on.

@abidlabs abidlabs added this to the Component Cleanup milestone Aug 28, 2023
@hysts
Copy link
Collaborator Author

hysts commented Aug 28, 2023

By a very easy workaround, do you mean adding \ everywhere? I was aware of this workaround, but the reason I opened this issue was actually because I found it cumbersome and didn't want to do it. People need to add and delete \ every time they edit markdown string.

I got interested in what other libraries were doing. Looks like Python's markdown library has an extension to render new line as <br>, and markdown-it also has an option break: true to do so. Looking at these, I feel like there's a need for both options.
Also, I wonder if it is really better to render new line as <br> by default. Just out of curiosity, what is the reason for this change in behavior? Changing the other uses of markdown in gradio to not render newline as <br> was also an option, no?

@abidlabs
Copy link
Member

Oh sorry I misunderstood. I thought the change went the other way around -- we no longer respected single line breaks, so my suggestion would have been to just add a line break. This is a bit more annoying to deal with and I agree not the typical way I've seen Markdown rendered. I think its reasonable to add a flag to control this behavior, particularly for gr.Markdown() since its a component dedicated to rendering Markdown (whereas for gr.Chatbot for example we can be more opinionated with how we deal with Markdown)

Thanks for clarifying @hysts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants