# All files / src/lib/markdown-it/plugins/markdown-it-block-embed/services YouTubeService.ts

100% Statements 7/7
100% Branches 4/4
100% Functions 3/3
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29

    22x

    22x

    35x

    10x
    10x

    10x
    10x

     // Copyright (c) Rotorz Limited and portions by original markdown-it-video authors
    // Licensed under the MIT license. See LICENSE file in the project root.

    import VideoServiceBase, { VideoServiceOptions } from "./VideoServiceBase";

    export interface YouTubeOptions extends VideoServiceOptions {
      width?: number;
      height?: number;
      [key: string]: any;
    }

    export default class YouTubeService extends VideoServiceBase {

      getDefaultOptions(): YouTubeOptions {
        return { width: 640, height: 390 };
      }

      extractVideoID(reference: string): string {
        let match = reference.match(/^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&\?]*).*/);
        return match && match[7].length === 11 ? match[7] : reference;
      }

      getVideoUrl(videoID: string): string {
        let escapedVideoID = this.env.md.utils.escapeHtml(videoID);
        return `//www.youtube.com/embed/${escapedVideoID}`;
      }

    }