Skip to content

Commit

Permalink
Validate platform for html decode (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfcere authored Nov 13, 2018
1 parent 250ab40 commit 44bb424
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/src/markdown.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isPlatformBrowser } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { Injectable, Optional, SecurityContext } from '@angular/core';
import { Inject, Injectable, Optional, PLATFORM_ID, SecurityContext } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { parse, Renderer } from 'marked';
import { Observable } from 'rxjs';
Expand All @@ -22,6 +23,7 @@ export class MarkdownService {
}

constructor(
@Inject(PLATFORM_ID) private platform: Object,
@Optional() private http: HttpClient,
private domSanitizer: DomSanitizer,
public options: MarkedOptions,
Expand Down Expand Up @@ -57,10 +59,12 @@ export class MarkdownService {
}

private decodeHtml(html: string) {
const textarea = document.createElement('textarea');
textarea.innerHTML = html;
return textarea.value;
}
if (isPlatformBrowser(this.platform)) {
const textarea = document.createElement('textarea');
textarea.innerHTML = html;
return textarea.value;
}
}

private handleExtension(src: string, markdown: string): string {
const extension = src
Expand Down

0 comments on commit 44bb424

Please sign in to comment.