Commit aa2b791
feat: Add native video support in markdown rendering (#2704)
## Summary
Adds support for rendering video files directly in markdown when using
image syntax (``). The markdown parser now detects video
file extensions and renders a native HTML5 video element instead of
trying to display videos as images.
<img width="721" height="461" alt="image"
src="https://github.com/user-attachments/assets/7ba80009-2b80-482f-9de9-d3493b953eaf"
/>
## Changes
- Modified the `img` component handler in `Markdown.tsx` to detect video
file extensions
- Renders native HTML5 `<video>` element with controls for video URLs
- Supports common video formats: `.mp4`, `.webm`, `.mov`, `.avi`,
`.ogv`, `.m4v`
- Falls back to standard image rendering for non-video files
## Motivation
Previously, when users included video URLs in markdown syntax like
``, the frontend was replacing them
with `<img>` elements, which couldn't display the videos properly. This
fix enables proper video playback directly within markdown content.
## Example
```python
from chainlit import AskUserMessage, Message, on_chat_start
@on_chat_start
async def main():
res = await AskUserMessage(content="Please enter a video URL:", timeout=30).send()
if res:
video_url = res['output']
await Message(
content=f"Here's your video:\n\n",
).send()
```
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Add native video rendering in Markdown when users embed videos with
image syntax. The renderer detects video URLs and shows an HTML5 video
player with controls for inline playback.
- **New Features**
- Detects common video extensions in Markdown image nodes.
- Renders a responsive HTML5 video element with controls.
- Supports .mp4, .webm, .mov, .avi, .ogv, .m4v.
- Falls back to standard image rendering for non-video URLs.
<sup>Written for commit 83674db.
Summary will update automatically on new commits.</sup>
<!-- End of auto-generated description by cubic. -->
---------
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Co-authored-by: Josh Hayes <[email protected]>1 parent 08ea796 commit aa2b791
1 file changed
+26
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
161 | 186 | | |
162 | 187 | | |
163 | 188 | | |
164 | 189 | | |
165 | 190 | | |
166 | 191 | | |
167 | 192 | | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
| 193 | + | |
173 | 194 | | |
174 | 195 | | |
175 | 196 | | |
| |||
0 commit comments