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

95.45% Statements 21/22
75% Branches 3/4
100% Functions 3/3
95.45% Lines 21/22

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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64

    22x
    22x
    22x
    22x
    22x
    22x

    22x

    35x

    35x
    35x

    35x

    35x

    35x
    35x
    35x
    210x
    210x

    210x
    210x

    35x

    35x

     // 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 MarkdownIt from 'markdown-it';
    import { EmbedServiceMap } from './tokenizer';
    import { BlockEmbedOptions } from './index';

    import YouTubeService from './services/YouTubeService';
    import VimeoService from './services/VimeoService';
    import VineService from './services/VineService';
    import PreziService from './services/PreziService';
    import SlideShareService from './services/SlideShareService';
    import PowerPointOnlineService from './services/PowerPointOnlineService';

    export default class PluginEnvironment {
      public md: MarkdownIt;
      public options: BlockEmbedOptions;
      public services: EmbedServiceMap = {};

      constructor(md: MarkdownIt, options: BlockEmbedOptions) {
        this.md = md;
        this.options = Object.assign(this.getDefaultOptions(), options);

        this._initServices();
      }

      _initServices(): void {
        const defaultServiceBindings: Record<string, any> = {
          'youtube': YouTubeService,
          'vimeo': VimeoService,
          'vine': VineService,
          'prezi': PreziService,
          'slideshare': SlideShareService,
          'powerpoint': PowerPointOnlineService,
        };

        let serviceBindings = Object.assign({}, defaultServiceBindings, this.options.services);
        let services: EmbedServiceMap = {};
        for (let serviceName of Object.keys(serviceBindings)) {
          let _serviceClass = serviceBindings[serviceName];
          const ActualConstructor = _serviceClass.default || _serviceClass;

          if (typeof ActualConstructor === 'function') {
            services[serviceName] = new ActualConstructor(serviceName, this.options[serviceName], this);
          } else E{
            console.error(`BlockEmbed Error: Service "${serviceName}" is not a valid constructor.`);
          }
        }

        this.services = services;
      }

      public getDefaultOptions(): BlockEmbedOptions {
        return {
          containerClassName: 'block-embed',
          serviceClassPrefix: 'block-embed-service-',
          outputPlayerSize: true,
          allowFullScreen: true,
          filterUrl: null
        };
      }

    }