render HTML posts properly, issues #4 and #17

This commit is contained in:
Morgan McMillian 2017-06-18 10:02:10 -07:00
parent 2612c0853f
commit 357776e0f3
4 changed files with 28 additions and 5 deletions

View file

@ -12,6 +12,7 @@ import { SplashScreen } from '@ionic-native/splash-screen';
import { IonicStorageModule } from '@ionic/storage'; import { IonicStorageModule } from '@ionic/storage';
import { Device } from '@ionic-native/device'; import { Device } from '@ionic-native/device';
import { TimeagoPipe } from '../pipes/timeago/timeago'; import { TimeagoPipe } from '../pipes/timeago/timeago';
import { ParserPipe } from '../pipes/parser/parser';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -20,7 +21,8 @@ import { TimeagoPipe } from '../pipes/timeago/timeago';
StreamPage, StreamPage,
ThreadPage, ThreadPage,
TimeagoPipe, TimeagoPipe,
NewPostModal NewPostModal,
ParserPipe
], ],
imports: [ imports: [
BrowserModule, BrowserModule,

View file

@ -38,7 +38,10 @@
</ion-note> </ion-note>
</ion-item> </ion-item>
<ion-card-content> <ion-card-content>
<p>{{ post.is_deleted ? '{post deleted}' : post.content.text }}</p> <div *ngIf="post.is_deleted; else renderBlock"></div>
<ng-template #renderBlock >
<div [innerHTML]="post.content.html | parser"></div>
</ng-template>
</ion-card-content> </ion-card-content>
<div *ngIf="post.raw"> <div *ngIf="post.raw">
<div *ngFor="let r of post.raw"> <div *ngFor="let r of post.raw">

View file

@ -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);
}
}

View file

@ -12,9 +12,7 @@ import * as moment from 'moment';
}) })
export class TimeagoPipe implements PipeTransform { export class TimeagoPipe implements PipeTransform {
now: any; now: any;
/**
* Takes a value and makes it lowercase.
*/
transform(value: string, ...args) { transform(value: string, ...args) {
this.now = moment(value).fromNow(true); this.now = moment(value).fromNow(true);
return this.now; return this.now;