From 44bb42448612c10eaa68c4564d1d64081bd2d623 Mon Sep 17 00:00:00 2001 From: Jean-Francois Cere Date: Mon, 12 Nov 2018 22:56:18 -0500 Subject: [PATCH] Validate platform for html decode (#117) --- lib/src/markdown.service.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/src/markdown.service.ts b/lib/src/markdown.service.ts index 3864fcad..e4e3c76f 100644 --- a/lib/src/markdown.service.ts +++ b/lib/src/markdown.service.ts @@ -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'; @@ -22,6 +23,7 @@ export class MarkdownService { } constructor( + @Inject(PLATFORM_ID) private platform: Object, @Optional() private http: HttpClient, private domSanitizer: DomSanitizer, public options: MarkedOptions, @@ -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