From 357776e0f328046b7a8953add2b5acbd8e361387 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sun, 18 Jun 2017 10:02:10 -0700 Subject: [PATCH] render HTML posts properly, issues #4 and #17 --- src/app/app.module.ts | 4 +++- src/pages/stream/stream.html | 5 ++++- src/pipes/parser/parser.ts | 20 ++++++++++++++++++++ src/pipes/timeago/timeago.ts | 4 +--- 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/pipes/parser/parser.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index c99348a..acb9a40 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -12,6 +12,7 @@ import { SplashScreen } from '@ionic-native/splash-screen'; import { IonicStorageModule } from '@ionic/storage'; import { Device } from '@ionic-native/device'; import { TimeagoPipe } from '../pipes/timeago/timeago'; +import { ParserPipe } from '../pipes/parser/parser'; @NgModule({ declarations: [ @@ -20,7 +21,8 @@ import { TimeagoPipe } from '../pipes/timeago/timeago'; StreamPage, ThreadPage, TimeagoPipe, - NewPostModal + NewPostModal, + ParserPipe ], imports: [ BrowserModule, diff --git a/src/pages/stream/stream.html b/src/pages/stream/stream.html index 95ada91..1ff8778 100644 --- a/src/pages/stream/stream.html +++ b/src/pages/stream/stream.html @@ -38,7 +38,10 @@ -

{{ post.is_deleted ? '{post deleted}' : post.content.text }}

+
+ +
+
diff --git a/src/pipes/parser/parser.ts b/src/pipes/parser/parser.ts new file mode 100644 index 0000000..f60e8bf --- /dev/null +++ b/src/pipes/parser/parser.ts @@ -0,0 +1,20 @@ +import { Pipe, PipeTransform } from '@angular/core'; +import {DomSanitizer, SafeHtml, SafeStyle, SafeScript, SafeUrl, SafeResourceUrl} from '@angular/platform-browser'; + +/** + * Generated class for the ParserPipe pipe. + * + * See https://angular.io/docs/ts/latest/guide/pipes.html for more info on + * Angular Pipes. + */ +@Pipe({ + name: 'parser', +}) +export class ParserPipe implements PipeTransform { + + constructor(protected _sanitizer: DomSanitizer) {} + + transform(value: string, ...args): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl { + return this._sanitizer.bypassSecurityTrustHtml(value); + } +} diff --git a/src/pipes/timeago/timeago.ts b/src/pipes/timeago/timeago.ts index 60ac239..1bd4dd8 100644 --- a/src/pipes/timeago/timeago.ts +++ b/src/pipes/timeago/timeago.ts @@ -12,9 +12,7 @@ import * as moment from 'moment'; }) export class TimeagoPipe implements PipeTransform { now: any; - /** - * Takes a value and makes it lowercase. - */ + transform(value: string, ...args) { this.now = moment(value).fromNow(true); return this.now;