Skip to content

Conversation

@cpsievert
Copy link
Collaborator

Follow up to #1868. That PR introduced a problem where HTML content included in a starting message no longer rendered as HTML since the HTML started getting escaped. For a reprex, this example:

from shiny.express import ui

welcome = """
**Hello!** How can I help you today?

Here are a couple suggestions:

* <span class="suggestion">Tell me a joke</span>
* <span class="suggestion submit">Tell me a story</span>
"""

chat = ui.Chat(id="chat")
chat.ui(messages=[welcome])


@chat.on_user_submit
async def _(user_input: str):
    await chat.append_message(f"You said: {user_input}")

Went from:

Screenshot 2025-03-24 at 12 07 06 PM

to:

Screenshot 2025-03-24 at 12 07 36 PM

Note that:

  1. This isn't a problem for append_message() et al. since we're already skipping the "tagify" step there for strings.
  2. We have the same problem in shinychat, so I'll be doing a follow up PR there.

@cpsievert cpsievert changed the title Fix(Chat, MarkdownStream): prevent escaping of HTML inside message content strings fix(Chat, MarkdownStream): prevent escaping of HTML inside message content strings Mar 24, 2025
@cpsievert cpsievert marked this pull request as draft March 24, 2025 18:38
@cpsievert cpsievert merged commit 0973b52 into main Mar 25, 2025
61 checks passed
@cpsievert cpsievert deleted the fix-chat-message-html-escape branch March 25, 2025 15:38
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.

3 participants