text: import { SecurityContext, Injectable, ɵɵdefineInjectable, ɵɵinject, EventEmitter, Component, ElementRef, Inject, PLATFORM_ID, Output, Input, NgModule } from '@angular/core';
  import { HttpClient } from '@angular/common/http';
  import { throwError } from 'rxjs';
  import { map, catchError } from 'rxjs/operators';
  import { Renderer, setOptions, parse } from 'marked';
  import { DomSanitizer } from '@angular/platform-browser';
  import { isPlatformBrowser, CommonModule } from '@angular/common';
  import { highlightAll } from 'prismjs';
  
  /**
   * @fileoverview added by tsickle
   * Generated from: lib/ngx-md.service.ts
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  var NgxMdService = /** @class */ (function () {
      function NgxMdService(_http, _domSanitizer) {
          this._http = _http;
          this._domSanitizer = _domSanitizer;
          this._renderer = new Renderer();
          this.extendRenderer();
          this.setMarkedOptions({});
      }
      // get the content from remote resource
      // get the content from remote resource
      /**
       * @param {?} path
       * @return {?}
       */
      NgxMdService.prototype.getContent = 
      // get the content from remote resource
      /**
       * @param {?} path
       * @return {?}
       */
      function (path) {
          var _this = this;
          return this._http.get(path, { responseType: 'text' }).pipe(map((/**
           * @param {?} res
           * @return {?}
           */
          function (res) { return _this.extractData(res); })), catchError(this.handleError));
      };
      Object.defineProperty(NgxMdService.prototype, "renderer", {
          get: /**
           * @return {?}
           */
          function () {
              return this._renderer;
          },
          enumerable: true,
          configurable: true
      });
      // handle data
      // handle data
      /**
       * @param {?} res
       * @return {?}
       */
      NgxMdService.prototype.extractData = 
      // handle data
      /**
       * @param {?} res
       * @return {?}
       */
      function (res) {
          return res || '';
      };
      /**
       * @param {?} options
       * @return {?}
       */
      NgxMdService.prototype.setMarkedOptions = /**
       * @param {?} options
       * @return {?}
       */
      function (options) {
          options = Object.assign({
              gfm: true,
              tables: true,
              breaks: false,
              pedantic: false,
              sanitize: false,
              smartLists: true,
              smartypants: false,
          }, options);
          options.renderer = this._renderer;
          setOptions(options);
      };
      // comple markdown to html
      // comple markdown to html
      /**
       * @param {?} data
       * @param {?=} sanitize
       * @return {?}
       */
      NgxMdService.prototype.compile = 
      // comple markdown to html
      /**
       * @param {?} data
       * @param {?=} sanitize
       * @return {?}
       */
      function (data, sanitize) {
          if (sanitize === void 0) { sanitize = true; }
          return this._domSanitizer.sanitize(sanitize ? SecurityContext.HTML : SecurityContext.NONE, parse(data).trim());
      };
      // handle error
      // handle error
      /**
       * @private
       * @param {?} error
       * @return {?}
       */
      NgxMdService.prototype.handleError = 
      // handle error
      /**
       * @private
       * @param {?} error
       * @return {?}
       */
      function (error) {
          /** @type {?} */
          var errMsg = error.message ? error.message : error.toString();
          return throwError(errMsg);
      };
      // extend marked render to support todo checkbox
      // extend marked render to support todo checkbox
      /**
       * @private
       * @return {?}
       */
      NgxMdService.prototype.extendRenderer = 
      // extend marked render to support todo checkbox
      /**
       * @private
       * @return {?}
       */
      function () {
          this._renderer.listitem = (/**
           * @param {?} text
           * @return {?}
           */
          function (text) {
              if (/^\s*\[[x ]\]\s*/.test(text)) {
                  text = text
                      .replace(/^\s*\[ \]\s*/, '<input type="checkbox" class="md-checkbox" disabled> ')
                      .replace(/^\s*\[x\]\s*/, '<input type="checkbox" class="md-checkbox" checked disabled> ');
                  return '<li style="list-style: none">' + text + '</li>';
              }
              else {
                  return '<li>' + text + '</li>';
              }
          });
      };
      NgxMdService.decorators = [
          { type: Injectable, args: [{
                      providedIn: 'root',
                  },] }
      ];
      /** @nocollapse */
      NgxMdService.ctorParameters = function () { return [
          { type: HttpClient },
          { type: DomSanitizer }
      ]; };
      /** @nocollapse */ NgxMdService.ngInjectableDef = ɵɵdefineInjectable({ factory: function NgxMdService_Factory() { return new NgxMdService(ɵɵinject(HttpClient), ɵɵinject(DomSanitizer)); }, token: NgxMdService, providedIn: "root" });
      return NgxMdService;
  }());
  if (false) {
      /**
       * @type {?}
       * @private
       */
      NgxMdService.prototype._renderer;
      /**
       * @type {?}
       * @private
       */
      NgxMdService.prototype._http;
      /**
       * @type {?}
       * @private
       */
      NgxMdService.prototype._domSanitizer;
  }
  
  /**
   * @fileoverview added by tsickle
   * Generated from: lib/ngx-md.component.ts
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  var NgxMdComponent = /** @class */ (function () {
      function NgxMdComponent(_mdService, _el, platformId) {
          this._mdService = _mdService;
          this._el = _el;
          this.platformId = platformId;
          this.changeLog = [];
          this.error = new EventEmitter();
          this.loaded = new EventEmitter();
          /**
           * Boolean indicating if the markdown content should be sanitized to avoid script injections
           */
          this.sanitizeHtml = true;
      }
      Object.defineProperty(NgxMdComponent.prototype, "path", {
          set: /**
           * @param {?} value
           * @return {?}
           */
          function (value) {
              if (value) {
                  this._path = value;
                  this.onPathChange();
              }
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(NgxMdComponent.prototype, "data", {
          set: /**
           * @param {?} value
           * @return {?}
           */
          function (value) {
              if (value) {
                  this._data = value;
                  this.onDataChange(value);
              }
          },
          enumerable: true,
          configurable: true
      });
      // on input
      // on input
      /**
       * @param {?} data
       * @return {?}
       */
      NgxMdComponent.prototype.onDataChange = 
      // on input
      /**
       * @param {?} data
       * @return {?}
       */
      function (data) {
          if (data) {
              this._el.nativeElement.innerHTML = this._mdService.compile(data, this.sanitizeHtml);
          }
          else {
              this._el.nativeElement.innerHTML = '';
          }
          this.highlightContent(false);
      };
      /**
       *  After view init
       */
      /**
       *  After view init
       * @return {?}
       */
      NgxMdComponent.prototype.ngAfterViewInit = /**
       *  After view init
       * @return {?}
       */
      function () {
          if (this._path) {
              this.onPathChange();
          }
          else if (!this._data) {
              this.processRaw();
          }
      };
      /**
       * @return {?}
       */
      NgxMdComponent.prototype.processRaw = /**
       * @return {?}
       */
      function () {
          this._md = this.prepare(decodeHtml(this._el.nativeElement.innerHTML));
          this._el.nativeElement.innerHTML = this._mdService.compile(this._md, this.sanitizeHtml);
          this.highlightContent(false);
      };
      /**
       * get remote conent;
       */
      /**
       * get remote conent;
       * @return {?}
       */
      NgxMdComponent.prototype.onPathChange = /**
       * get remote conent;
       * @return {?}
       */
      function () {
          var _this = this;
          this._ext =
              this._path &&
                  this._path
                      .split('.')
                      .splice(-1)
                      .join();
          this._mdService
              .getContent(this._path)
              .pipe(catchError(this.handleError))
              .subscribe((/**
           * @param {?} data
           * @return {?}
           */
          function (data) {
              _this.loaded.emit(data);
              _this._md =
                  _this._ext !== 'md' ? '```' + _this._ext + '\n' + data + '\n```' : data;
              _this._el.nativeElement.innerHTML = _this._mdService.compile(_this.prepare(_this._md), _this.sanitizeHtml);
              _this.highlightContent(false);
          }));
      };
      /**
       * catch http error
       */
      /**
       * catch http error
       * @private
       * @param {?} error
       * @return {?}
       */
      NgxMdComponent.prototype.handleError = /**
       * catch http error
       * @private
       * @param {?} error
       * @return {?}
       */
      function (error) {
          this.error.emit(error);
          console.error('An error occurred', error); // for demo purposes only
          return error.message || error;
      };
      /**
       * Prepare string
       */
      /**
       * Prepare string
       * @param {?} raw
       * @return {?}
       */
      NgxMdComponent.prototype.prepare = /**
       * Prepare string
       * @param {?} raw
       * @return {?}
       */
      function (raw) {
          var _this = this;
          if (!raw) {
              return '';
          }
          if (this._ext === 'md' || !this.path) {
              /** @type {?} */
              var isCodeBlock_1 = false;
              return raw
                  .split('\n')
                  .map((/**
               * @param {?} line
               * @return {?}
               */
              function (line) {
                  // If the first non-blank chars are an opening/closing code block, toggle the flag
                  if (_this.trimLeft(line).substring(0, 3) === '```') {
                      isCodeBlock_1 = !isCodeBlock_1;
                  }
                  return isCodeBlock_1 ? line : line.trim();
              }))
                  .join('\n');
          }
          return raw.replace(/\"/g, '\'');
      };
      /**
       * Trim left whitespace
       */
      /**
       * Trim left whitespace
       * @private
       * @param {?} line
       * @return {?}
       */
      NgxMdComponent.prototype.trimLeft = /**
       * Trim left whitespace
       * @private
       * @param {?} line
       * @return {?}
       */
      function (line) {
          return line.replace(/^\s+|\s+$/g, '');
      };
      /**
       * Use Prism to highlight code snippets only on the browser
       */
      /**
       * Use Prism to highlight code snippets only on the browser
       * @private
       * @param {?} async
       * @return {?}
       */
      NgxMdComponent.prototype.highlightContent = /**
       * Use Prism to highlight code snippets only on the browser
       * @private
       * @param {?} async
       * @return {?}
       */
      function (async) {
          if (isPlatformBrowser(this.platformId)) {
              highlightAll(async);
          }
      };
      NgxMdComponent.decorators = [
          { type: Component, args: [{
                      selector: 'markdown,[Markdown],ngx-md,[NgxMd]',
                      template: '<ng-content></ng-content>',
                      styles: ["\n      .token.operator,\n      .token.entity,\n      .token.url,\n      .language-css .token.string,\n      .style .token.string {\n        background: none;\n      }\n      .md-checkbox {\n        vertical-align: middle;\n        margin: 0 0.2em 0.25em -1.6em;\n        font-size: 16px;\n      }\n    "]
                  }] }
      ];
      /** @nocollapse */
      NgxMdComponent.ctorParameters = function () { return [
          { type: NgxMdService },
          { type: ElementRef },
          { type: String, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] }
      ]; };
      NgxMdComponent.propDecorators = {
          error: [{ type: Output }],
          loaded: [{ type: Output }],
          path: [{ type: Input }],
          data: [{ type: Input }],
          sanitizeHtml: [{ type: Input }]
      };
      return NgxMdComponent;
  }());
  if (false) {
      /** @type {?} */
      NgxMdComponent.prototype._path;
      /** @type {?} */
      NgxMdComponent.prototype._data;
      /** @type {?} */
      NgxMdComponent.prototype._md;
      /** @type {?} */
      NgxMdComponent.prototype._ext;
      /** @type {?} */
      NgxMdComponent.prototype.changeLog;
      /** @type {?} */
      NgxMdComponent.prototype.error;
      /** @type {?} */
      NgxMdComponent.prototype.loaded;
      /**
       * Boolean indicating if the markdown content should be sanitized to avoid script injections
       * @type {?}
       */
      NgxMdComponent.prototype.sanitizeHtml;
      /** @type {?} */
      NgxMdComponent.prototype._mdService;
      /** @type {?} */
      NgxMdComponent.prototype._el;
      /** @type {?} */
      NgxMdComponent.prototype.platformId;
  }
  /**
   * @param {?} html
   * @return {?}
   */
  function decodeHtml(html) {
      // https://stackoverflow.com/a/7394787/588521
      /** @type {?} */
      var txt = document.createElement('textarea');
      txt.innerHTML = html;
      return txt.value;
  }
  
  /**
   * @fileoverview added by tsickle
   * Generated from: lib/ngx-md.config.ts
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  var NgxMdConfig = /** @class */ (function () {
      function NgxMdConfig() {
      }
      NgxMdConfig.decorators = [
          { type: Injectable }
      ];
      return NgxMdConfig;
  }());
  
  /**
   * @fileoverview added by tsickle
   * Generated from: lib/ngx-md.module.ts
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  var NgxMdModule = /** @class */ (function () {
      function NgxMdModule() {
      }
      /**
       * @return {?}
       */
      NgxMdModule.forRoot = /**
       * @return {?}
       */
      function () {
          return {
              ngModule: NgxMdModule,
              providers: [NgxMdConfig],
          };
      };
      NgxMdModule.decorators = [
          { type: NgModule, args: [{
                      imports: [CommonModule],
                      declarations: [NgxMdComponent],
                      providers: [NgxMdService],
                      exports: [NgxMdComponent],
                  },] }
      ];
      return NgxMdModule;
  }());
  
  /**
   * @fileoverview added by tsickle
   * Generated from: index.ts
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  
  /**
   * @fileoverview added by tsickle
   * Generated from: ngx-md.ts
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  
  export { NgxMdComponent, NgxMdModule, NgxMdService, NgxMdConfig as ɵa };
  //# sourceMappingURL=ngx-md.js.map
  