ngx-markdown
Version:
Angular library that uses marked to parse markdown to html combined with Prism.js for synthax highlights
2 lines • 5.87 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("@angular/common/http"),require("@angular/platform-browser"),require("marked"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("ngx-markdown",["exports","@angular/core","@angular/common","@angular/common/http","@angular/platform-browser","marked","rxjs/operators"],t):t(e["ngx-markdown"]={},e.ng.core,e.ng.common,e.ng.common.http,e.ng.platformBrowser,null,e.rxjs.operators)}(this,function(e,i,r,t,n,a,o){"use strict";var s=function(){function e(){}return e.prototype.transform=function(e,t){return"string"!=typeof e?(console.error("LanguagePipe has been invoked with an invalid value type ["+e+"]"),e):"string"!=typeof t?(console.error("LanguagePipe has been invoked with an invalid parameter ["+t+"]"),e):"```"+t+"\n"+e+"\n```"},e.decorators=[{type:i.Pipe,args:[{name:"language"}]}],e}(),u=function b(){},p="[ngx-markdown] When using the [src] attribute you *have to* pass the `HttpClient` as a parameter of the `forRoot` method. See README for more information",c=function(){function e(e,t,r,n){this.platform=e,this.http=t,this.domSanitizer=r,this.options=n,this.renderer||(this.renderer=new a.Renderer)}return Object.defineProperty(e.prototype,"renderer",{get:function(){return this.options.renderer},set:function(e){this.options.renderer=e},enumerable:!0,configurable:!0}),e.prototype.compile=function(e,t,r){void 0===t&&(t=!1),void 0===r&&(r=this.options);var n=this.precompile(e),o=a.parse(t?this.decodeHtml(n):n,r);return r.sanitize&&!r.sanitizer?this.domSanitizer.sanitize(i.SecurityContext.HTML,o):o},e.prototype.getSource=function(t){var r=this;if(!this.http)throw new Error(p);return this.http.get(t,{responseType:"text"}).pipe(o.map(function(e){return r.handleExtension(t,e)}))},e.prototype.highlight=function(){r.isPlatformBrowser(this.platform)&&"undefined"!=typeof Prism&&Prism.highlightAll(!1)},e.prototype.decodeHtml=function(e){if(r.isPlatformBrowser(this.platform)){var t=document.createElement("textarea");return t.innerHTML=e,t.value}return e},e.prototype.handleExtension=function(e,t){var r=e?e.split(".").splice(-1).join():null;return"md"!==r?"```"+r+"\n"+t+"\n```":t},e.prototype.precompile=function(e){return e?e.split("\n").map(function(e){var t=r;return 0<e.length&&(t=isNaN(t)?e.search(/\S|$/):Math.min(e.search(/\S|$/),t)),isNaN(r)&&(r=t),t?e.substring(t):e}).join("\n"):"";var r},e.decorators=[{type:i.Injectable}],e.ctorParameters=function(){return[{type:Object,decorators:[{type:i.Inject,args:[i.PLATFORM_ID]}]},{type:t.HttpClient,decorators:[{type:i.Optional}]},{type:n.DomSanitizer},{type:u}]},e}(),l=function(){function e(e,t){this.element=e,this.markdownService=t,this.error=new i.EventEmitter,this.load=new i.EventEmitter}return Object.defineProperty(e.prototype,"_isTranscluded",{get:function(){return!this._data&&!this._src},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"data",{get:function(){return this._data},set:function(e){this._data=e,this.render(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"src",{get:function(){return this._src},set:function(e){var t=this;this._src=e,this.markdownService.getSource(e).subscribe(function(e){t.render(e),t.load.emit(e)},function(e){return t.error.emit(e)})},enumerable:!0,configurable:!0}),e.prototype.ngAfterViewInit=function(){this._isTranscluded&&this.render(this.element.nativeElement.innerHTML,!0)},e.prototype.render=function(e,t){void 0===t&&(t=!1),this.element.nativeElement.innerHTML=this.markdownService.compile(e,t),this.markdownService.highlight()},e.decorators=[{type:i.Component,args:[{selector:"markdown, [markdown]",template:"<ng-content></ng-content>"}]}],e.ctorParameters=function(){return[{type:i.ElementRef},{type:c}]},e.propDecorators={data:[{type:i.Input}],src:[{type:i.Input}],error:[{type:i.Output}],load:[{type:i.Output}]},e}(),f=function(e,t){return(f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function d(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||0<t--)&&!(n=i.next()).done;)a.push(n.value)}catch(s){o={error:s}}finally{try{n&&!n.done&&(r=i["return"])&&r.call(i)}finally{if(o)throw o.error}}return a}function m(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(d(arguments[t]));return e}var h=function(){function e(e,t){this.markdownService=e,this.zone=t}return e.prototype.transform=function(e){var t=this;if("string"!=typeof e)return console.error("MarkdownPipe has been invoked with an invalid value type ["+e+"]"),e;var r=this.markdownService.compile(e);return this.zone.onStable.pipe(o.first()).subscribe(function(){return t.markdownService.highlight()}),r},e.decorators=[{type:i.Pipe,args:[{name:"markdown"}]}],e.ctorParameters=function(){return[{type:c},{type:i.NgZone}]},e}(),y={provide:u,useValue:{gfm:!0,tables:!0,breaks:!1,pedantic:!1,sanitize:!1,smartLists:!0,smartypants:!1}},g=[s,l,h],v=function(){function t(){}return t.forRoot=function(e){return{ngModule:t,providers:m([c],e?[e.loader||[],e.markedOptions||y]:[y])}},t.forChild=function(){return{ngModule:t}},t.decorators=[{type:i.NgModule,args:[{exports:m(g),declarations:m(g)}]}],t}(),w=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return function n(e,t){function r(){this.constructor=e}f(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}(t,e),t}(a.Renderer);e.LanguagePipe=s,e.MarkdownComponent=l,e.initialMarkedOptions=y,e.MarkdownModule=v,e.MarkdownPipe=h,e.errorSrcWithoutHttpClient=p,e.MarkdownService=c,e.MarkedOptions=u,e.MarkedRenderer=w,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-markdown.umd.min.js.map