@@ -20,19 +20,25 @@ export const htmlToElement = (html: string) => {
2020 */
2121const strip = ( text : string ) => text . replace ( / { % .* ?% } / gm, "" ) ;
2222
23- export const YT_EMBEDDING_SELECTION_REGEX = / { % e m b e d u r l = " < a h r e f = " h t t p s : \/ \/ w w w .y o u t u b e .c o m \/ w a t c h \? v = ( .* ?) \& .* ? % } / m;
23+ export const YT_EMBEDDING_SELECTION_REGEX = [
24+ / { % e m b e d u r l = " < a h r e f = " h t t p s : \/ \/ w w w .y o u t u b e .c o m \/ w a t c h \? v = ( .* ?) \& .* ? % } / m,
25+ / { % e m b e d u r l = " < a h r e f = " h t t p s : \/ \/ y o u t u .b e .* ?> h t t p s : \/ \/ y o u t u .b e \/ ( .* ?) " .* ? % } / m,
26+ ] ;
2427
25- const updateYoutubeEmbedingsWithIframe = ( text : string ) => {
28+ const getYtIframe = ( videoId : string ) => {
29+ return `<iframe width="100%" height="280" src="https://www.youtube.com/embed/${ videoId } " title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>` ;
30+ } ;
31+ const updateYoutubeEmbeddingsWithIframe = ( text : string ) => {
2632 let docString = text ;
2733 let match ;
28- while ( ( match = YT_EMBEDDING_SELECTION_REGEX . exec ( docString ) ) !== null ) {
29- // gitbook adds \\ in front of a _ char in an id. TO remove that we have to do this.
30- const videoId = match [ 1 ] . replaceAll ( "%5C" , "" ) ;
31- docString = docString . replace (
32- YT_EMBEDDING_SELECTION_REGEX ,
33- `<iframe width="100%" height="280" src="https://www.youtube.com/embed/ ${ videoId } " title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>` ,
34- ) ;
35- }
34+ YT_EMBEDDING_SELECTION_REGEX . forEach ( ( ytRegex ) => {
35+ while ( ( match = ytRegex . exec ( docString ) ) !== null ) {
36+ // gitbook adds \\ in front of a _ char in an id. TO remove that we have to do this.
37+ let videoId = match [ 1 ] . replaceAll ( "%5C" , "" ) ;
38+ videoId = videoId . replaceAll ( "\\" , "" ) ;
39+ docString = docString . replace ( ytRegex , getYtIframe ( videoId ) ) ;
40+ }
41+ } ) ;
3642 return docString ;
3743} ;
3844
@@ -223,7 +229,7 @@ const parseDocumentationContent = (item: any): string | undefined => {
223229
224230 // Remove highlight for nodes that don't match well
225231 removeBadHighlights ( documentObj , query ) ;
226- let content = updateYoutubeEmbedingsWithIframe ( documentObj . body . innerHTML ) ;
232+ let content = updateYoutubeEmbeddingsWithIframe ( documentObj . body . innerHTML ) ;
227233 content = strip ( content ) . trim ( ) ;
228234 return content ;
229235 } catch ( e ) {
0 commit comments