ng2-markdown-to-html
Version:
Angular 2+ library that uses marked to parse markdown to html combined with Prism.js for synthax highlights
1 lines • 4.37 kB
JavaScript
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/http"),require("rxjs/Observable"),require("rxjs/add/operator/catch"),require("rxjs/add/operator/map"),require("marked"),require("prismjs"),require("prismjs/prism"),require("prismjs/components/prism-c"),require("prismjs/components/prism-cpp"),require("prismjs/components/prism-csharp"),require("prismjs/components/prism-css"),require("prismjs/components/prism-diff"),require("prismjs/components/prism-java"),require("prismjs/components/prism-javascript"),require("prismjs/components/prism-perl"),require("prismjs/components/prism-php"),require("prismjs/components/prism-python"),require("prismjs/components/prism-sass"),require("prismjs/components/prism-scss"),require("prismjs/components/prism-typescript")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/http","rxjs/Observable","rxjs/add/operator/catch","rxjs/add/operator/map","marked","prismjs","prismjs/prism","prismjs/components/prism-c","prismjs/components/prism-cpp","prismjs/components/prism-csharp","prismjs/components/prism-css","prismjs/components/prism-diff","prismjs/components/prism-java","prismjs/components/prism-javascript","prismjs/components/prism-perl","prismjs/components/prism-php","prismjs/components/prism-python","prismjs/components/prism-sass","prismjs/components/prism-scss","prismjs/components/prism-typescript"],e):e((r.ng=r.ng||{},r.ng.markdowntohtml={}),r.ng.core,r.ng.http,r.Rx,null,null,r.marked,r.prismjs)}(this,function(r,e,t,s,n,o,p,i){"use strict";var a=function(){function r(){}return r.prototype.transform=function(r,e){return"string"!=typeof e?(console.error("LanguagePipe has been invoked with an invalid parameter ["+e+"]"),r):"```"+e+"\n"+r+"\n```"},r.decorators=[{type:e.Pipe,args:[{name:"language"}]}],r.ctorParameters=function(){return[]},r}(),m=function(){function r(r){this.http=r}return r.prototype.getSource=function(r){return this.http.get(r).map(this.extractData).catch(this.handleError)},r.prototype.extractData=function(r){return r.text()||""},r.prototype.handleError=function(r){var e;if(r instanceof t.Response){var n=r.json()||"",o=n.error||JSON.stringify(n);e=r.status+" - "+(r.statusText||"")+" "+o}else e=r.message?r.message:r.toString();return console.error(e),s.Observable.throw(e)},r.decorators=[{type:e.Injectable}],r.ctorParameters=function(){return[{type:t.Http}]},r}(),c=p,u=function(){function r(r,e){this.element=r,this.mthService=e}return r.prototype.ngAfterViewInit=function(){this.data?this.handleData():this.src?this.handleSrc():this.handleRaw(this.element.nativeElement.innerHTML)},r.prototype.ngOnChanges=function(r){"data"in r?this.handleData():"src"in r&&this.handleSrc()},r.prototype.handleData=function(){this.handleRaw(this.data)},r.prototype.handleSrc=function(){var r=this,e=this.src?this.src.split(".").splice(-1).join():null;this.mthService.getSource(this.src).subscribe(function(t){var s="md"!==e?"```"+e+"\n"+t+"\n```":t;r.handleRaw(s)})},r.prototype.handleRaw=function(r){var e=this.prepare(r);this.element.nativeElement.innerHTML=c(e),i.highlightAll(!1)},r.prototype.prepare=function(r){if(!r)return"";var e;return r.replace(/\>/g,">").split("\n").map(function(r){return r.length>0&&isNaN(e)&&(e=r.search(/\S|$/)),e?r.substring(e):r}).join("\n")},r.decorators=[{type:e.Component,args:[{selector:"markdown-to-html, [markdown-to-html]",template:"<ng-content></ng-content>",styles:[":host /deep/ table{border-spacing:0;border-collapse:collapse;margin-bottom:16px}:host /deep/ table td,:host /deep/ table th{padding:6px 13px;border:1px solid #ddd}:host /deep/ table tr:nth-child(2n){background-color:rgba(0,0,0,.03)}:host /deep/ blockquote{padding:0 1em;color:rgba(0,0,0,.535);border-left:.25em solid rgba(0,0,0,.11)}"]}]}],r.ctorParameters=function(){return[{type:e.ElementRef},{type:m}]},r.propDecorators={data:[{type:e.Input}],src:[{type:e.Input}]},r}(),l=function(){function r(){}return r.forRoot=function(){return{ngModule:r,providers:[m]}},r.forChild=function(){return{ngModule:r}},r.decorators=[{type:e.NgModule,args:[{exports:[u,a],imports:[t.HttpModule],declarations:[u,a]}]}],r.ctorParameters=function(){return[]},r}();r.LanguagePipe=a,r.MarkdownToHtmlComponent=u,r.MarkdownToHtmlModule=l,r.MarkdownToHtmlService=m,Object.defineProperty(r,"__esModule",{value:!0})});