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

Markdown pane does not render new lines as hard line breaks, configurable with hard_line_break #7582

Merged
merged 9 commits into from
Jan 20, 2025

Conversation

maximlt
Copy link
Member

@maximlt maximlt commented Jan 2, 2025

Sort of addresses #7535

This PR adds a new break_as_new parameter (better name welcome!) to the Markdown pane to make it easier for users to declare whether they want simple line breaks to be rendered with a new line or not. Unfortunately, I haven't been able to find a simple way to configure MyST-Parser to toggle this behavior.

Importantly, note that I am -1 on the current default in Panel which is break_as_new=True with markdown-it. Even if I understand the motivation to make it easier to render Markdown generated by LLMs, it makes it way more difficult to display in a nice way some Markdown formatted text (pn.Column(md_intro, <objs>) vs pn.Column(pn.pane.Markdown(md_intro, break_as_new=False), <objs>). @ahuang11 prefers the current default, @philippjfr I'll let you chime in with your opinion (and let's wait for Andrew to be back too).

Once this is settled for good, I'll add tests to this PR.

@maximlt maximlt marked this pull request as draft January 2, 2025 15:48
@ahuang11
Copy link
Contributor

ahuang11 commented Jan 3, 2025

I'm okay with having break_as_new=False. The only thing is setting it to True in ChatMessage.

Also, I don't think break_as_new is intuitive, maybe breaks_as_newline?

@MarcSkovMadsen
Copy link
Collaborator

I think the name line_breaks is easier to remember and understand.

I also think this is actually a regression. Originally coming from Streamlit this was a major issue when moving to Panel that new lines in multiline """ strings got broken into new lines. I do believe it was fixed in Panel but at some stage it reverted to breaking lines which is quite annoying.

@maximlt
Copy link
Member Author

maximlt commented Jan 13, 2025

Ok so I renamed it to hard_line_break that defaults to False, re-establishing the older behavior.

The only thing is setting it to True in ChatMessage.

@ahuang11 in 728b1fa I've made a change to enable it in ChatMessage. But I wanted to ask you, do you know if all strings passed to ChatMessage are turned into Markdown panes? If yes, it could skip calling panel(...) and directly call Markdown(..., hard_line_break) for values of str type, probably making things a bit faster.

@ahuang11
Copy link
Contributor

But I wanted to ask you, do you know if all strings passed to ChatMessage are turned into Markdown panes

If it's a string, it should be a Markdown, but only if isinstance(message, str).

@maximlt
Copy link
Member Author

maximlt commented Jan 14, 2025

But I wanted to ask you, do you know if all strings passed to ChatMessage are turned into Markdown panes

If it's a string, it should be a Markdown, but only if isinstance(message, str).

I shortly discussed this with Philipp this morning, who told me other components can be instantiated from a string (image pointing to a URL), and that one could see ChatMessage as a sort of opinionated repr for panel(). So always instantiating a Markdown pane for a string isn't appropriate in this case.

@maximlt maximlt marked this pull request as ready for review January 14, 2025 12:55
Copy link

codecov bot commented Jan 14, 2025

Codecov Report

Attention: Patch coverage is 88.46154% with 6 lines in your changes missing coverage. Please review.

Project coverage is 82.24%. Comparing base (d48c45f) to head (59ebb7b).
Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
panel/tests/pane/test_markup.py 86.36% 6 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #7582    +/-   ##
========================================
  Coverage   82.24%   82.24%            
========================================
  Files         339      341     +2     
  Lines       51476    51702   +226     
========================================
+ Hits        42334    42522   +188     
- Misses       9142     9180    +38     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@maximlt maximlt changed the title Add a parameter to the Markdown pane to configure how soft line breaks are rendered Markdown pane does not render new lines as hard line breaks, configurable with hard_line_break Jan 14, 2025
@maximlt maximlt requested a review from philippjfr January 20, 2025 20:34
@philippjfr philippjfr merged commit 4c9bc99 into main Jan 20, 2025
18 checks passed
@philippjfr philippjfr deleted the markdown_line_breaks branch January 20, 2025 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants