Fixes chatbot does not display code blocks correctly (#3816)

* fix

* changelog

* Update CHANGELOG.md

* style code blocks

* next beta version for release

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
Dawood Khan 2023-04-12 14:04:47 -07:00 committed by GitHub
parent 9f4f851d68
commit c772c6ae57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 4 deletions

View File

@ -14,8 +14,8 @@ with gr.Blocks() as demo:
```
## Bug Fixes:
- Fix code markdown support in `gr.Chatbot()` component by [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3816](https://github.com/gradio-app/gradio/pull/3816)
No changes to highlight.
## Documentation Changes:

View File

@ -4364,8 +4364,12 @@ class Chatbot(Changeable, Selectable, IOComponent, JSONSerializable):
"is_file": True,
}
elif isinstance(chat_message, str):
chat_message = chat_message.replace("\n", "<br>")
return self.md.renderInline(chat_message)
children = self.md.parseInline(chat_message)[0].children
if children and any("code" in child.tag for child in children):
return self.md.render(chat_message)
else:
chat_message = chat_message.replace("\n", "<br>")
return self.md.renderInline(chat_message)
else:
raise ValueError(f"Invalid message for Chatbot component: {chat_message}")

View File

@ -1 +1 @@
3.25.1b1
3.25.1b2

View File

@ -252,4 +252,8 @@
.hide {
display: none;
}
.message-wrap :global(pre) {
padding: var(--spacing-xl) 0px;
}
</style>