mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 03:26:22 +00:00
feat: support youtube playlist iframe (#968)
* feat: support youtube playlist iframe * chore: updated Youtube embed documentation to include playlists
This commit is contained in:
parent
0ca8a2ac7c
commit
e13cafe070
2 changed files with 18 additions and 2 deletions
|
@ -20,7 +20,7 @@ This plugin accepts the following configuration options:
|
||||||
- `parseArrows`: If `true` (default), transforms arrow symbols into their HTML character equivalents.
|
- `parseArrows`: If `true` (default), transforms arrow symbols into their HTML character equivalents.
|
||||||
- `parseBlockReferences`: If `true` (default), handles block references, linking to specific content blocks.
|
- `parseBlockReferences`: If `true` (default), handles block references, linking to specific content blocks.
|
||||||
- `enableInHtmlEmbed`: If `true`, allows embedding of content directly within HTML. Defaults to `false`.
|
- `enableInHtmlEmbed`: If `true`, allows embedding of content directly within HTML. Defaults to `false`.
|
||||||
- `enableYouTubeEmbed`: If `true` (default), enables the embedding of YouTube videos using external image Markdown syntax.
|
- `enableYouTubeEmbed`: If `true` (default), enables the embedding of YouTube videos and playlists using external image Markdown syntax.
|
||||||
- `enableVideoEmbed`: If `true` (default), enables the embedding of video files.
|
- `enableVideoEmbed`: If `true` (default), enables the embedding of video files.
|
||||||
- `enableCheckbox`: If `true`, adds support for interactive checkboxes in content. Defaults to `false`.
|
- `enableCheckbox`: If `true`, adds support for interactive checkboxes in content. Defaults to `false`.
|
||||||
|
|
||||||
|
|
|
@ -123,6 +123,7 @@ const tagRegex = new RegExp(
|
||||||
)
|
)
|
||||||
const blockReferenceRegex = new RegExp(/\^([-_A-Za-z0-9]+)$/, "g")
|
const blockReferenceRegex = new RegExp(/\^([-_A-Za-z0-9]+)$/, "g")
|
||||||
const ytLinkRegex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/
|
const ytLinkRegex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/
|
||||||
|
const ytPlaylistLinkRegex = /[?&]list=([^#?&]*)/
|
||||||
const videoExtensionRegex = new RegExp(/\.(mp4|webm|ogg|avi|mov|flv|wmv|mkv|mpg|mpeg|3gp|m4v)$/)
|
const videoExtensionRegex = new RegExp(/\.(mp4|webm|ogg|avi|mov|flv|wmv|mkv|mpg|mpeg|3gp|m4v)$/)
|
||||||
const wikilinkImageEmbedRegex = new RegExp(
|
const wikilinkImageEmbedRegex = new RegExp(
|
||||||
/^(?<alt>(?!^\d*x?\d*$).*?)?(\|?\s*?(?<width>\d+)(x(?<height>\d+))?)?$/,
|
/^(?<alt>(?!^\d*x?\d*$).*?)?(\|?\s*?(?<width>\d+)(x(?<height>\d+))?)?$/,
|
||||||
|
@ -574,7 +575,9 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>
|
||||||
if (node.tagName === "img" && typeof node.properties.src === "string") {
|
if (node.tagName === "img" && typeof node.properties.src === "string") {
|
||||||
const match = node.properties.src.match(ytLinkRegex)
|
const match = node.properties.src.match(ytLinkRegex)
|
||||||
const videoId = match && match[2].length == 11 ? match[2] : null
|
const videoId = match && match[2].length == 11 ? match[2] : null
|
||||||
|
const playlistId = node.properties.src.match(ytPlaylistLinkRegex)?.[1]
|
||||||
if (videoId) {
|
if (videoId) {
|
||||||
|
// YouTube video (with optional playlist)
|
||||||
node.tagName = "iframe"
|
node.tagName = "iframe"
|
||||||
node.properties = {
|
node.properties = {
|
||||||
class: "external-embed",
|
class: "external-embed",
|
||||||
|
@ -582,7 +585,20 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>
|
||||||
frameborder: 0,
|
frameborder: 0,
|
||||||
width: "600px",
|
width: "600px",
|
||||||
height: "350px",
|
height: "350px",
|
||||||
src: `https://www.youtube.com/embed/${videoId}`,
|
src: playlistId
|
||||||
|
? `https://www.youtube.com/embed/${videoId}?list=${playlistId}`
|
||||||
|
: `https://www.youtube.com/embed/${videoId}`,
|
||||||
|
}
|
||||||
|
} else if (playlistId) {
|
||||||
|
// YouTube playlist only.
|
||||||
|
node.tagName = "iframe"
|
||||||
|
node.properties = {
|
||||||
|
class: "external-embed",
|
||||||
|
allow: "fullscreen",
|
||||||
|
frameborder: 0,
|
||||||
|
width: "600px",
|
||||||
|
height: "350px",
|
||||||
|
src: `https://www.youtube.com/embed/videoseries?list=${playlistId}`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue