mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2026-02-06 09:55:47 +00:00
fix(preprocessMarkdown): handle autolink syntax for video URLs
Support markdown autolinks <https://youtube.com/...> in addition to standard markdown links [text](url) for YouTube and Rumble videos. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
5b446f933c
commit
393d882cfe
@ -61,10 +61,23 @@ export function preprocessMarkdown(text: string): string {
|
||||
|
||||
/**
|
||||
* Converts YouTube and Rumble markdown links to video-embed HTML tags.
|
||||
* Handles both standard markdown links [Text](url) and autolinks <url>
|
||||
*/
|
||||
export function preprocessVideoLinks(text: string): string {
|
||||
let result = text
|
||||
|
||||
// YouTube autolinks: <https://www.youtube.com/watch?v=VIDEO_ID>
|
||||
result = result.replace(
|
||||
/<https?:\/\/(?:www\.)?youtube\.com\/watch\?v=([^>&]+)[^>]*>/g,
|
||||
'<video-embed provider="youtube" video-id="$1"></video-embed>',
|
||||
)
|
||||
|
||||
// YouTube short autolinks: <https://youtu.be/VIDEO_ID>
|
||||
result = result.replace(
|
||||
/<https?:\/\/youtu\.be\/([^>?]+)[^>]*>/g,
|
||||
'<video-embed provider="youtube" video-id="$1"></video-embed>',
|
||||
)
|
||||
|
||||
// YouTube: [Text](https://www.youtube.com/watch?v=VIDEO_ID)
|
||||
result = result.replace(
|
||||
/\[([^\]]*)\]\(https?:\/\/(?:www\.)?youtube\.com\/watch\?v=([^)&]+)[^)]*\)/g,
|
||||
@ -77,6 +90,12 @@ export function preprocessVideoLinks(text: string): string {
|
||||
'<video-embed provider="youtube" video-id="$2"></video-embed>',
|
||||
)
|
||||
|
||||
// Rumble autolinks: <https://rumble.com/embed/VIDEO_ID>
|
||||
result = result.replace(
|
||||
/<https?:\/\/rumble\.com\/embed\/([^>]+)>/g,
|
||||
'<video-embed provider="rumble" video-id="$1"></video-embed>',
|
||||
)
|
||||
|
||||
// Rumble embed URLs: [Text](https://rumble.com/embed/VIDEO_ID)
|
||||
result = result.replace(
|
||||
/\[([^\]]*)\]\(https?:\/\/rumble\.com\/embed\/([^)]+)\)/g,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user