Skip to content

Commit

Permalink
Revert "Add sanitize HTML (#66)"
Browse files Browse the repository at this point in the history
This reverts commit 769e17a.
  • Loading branch information
jfcere committed Aug 18, 2018
1 parent 769e17a commit 80d3b60
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
24 changes: 8 additions & 16 deletions lib/src/markdown.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { SecurityContext } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { BrowserModule, DomSanitizer } from '@angular/platform-browser';
import { parse } from 'marked';

import { MarkdownService } from './markdown.service';
Expand All @@ -11,16 +9,12 @@ import { MarkedOptions } from './marked-options';
declare var Prism: any;

describe('MarkdowService', () => {
let domSanitizer: DomSanitizer;
let http: HttpTestingController;
let markdownService: MarkdownService;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
BrowserModule,
HttpClientTestingModule,
],
imports: [HttpClientTestingModule],
providers: [
{ provide: MarkedOptions, useValue: {} },
MarkdownService,
Expand All @@ -29,7 +23,6 @@ describe('MarkdowService', () => {
});

beforeEach(() => {
domSanitizer = TestBed.get(DomSanitizer);
http = TestBed.get(HttpTestingController);
markdownService = TestBed.get(MarkdownService);
});
Expand All @@ -47,9 +40,8 @@ describe('MarkdowService', () => {
it('should return parsed markdown correctly', () => {

const mockRaw = '### Markdown-x';
const expected = domSanitizer.sanitize(SecurityContext.HTML, parse(mockRaw));

expect(markdownService.compile(mockRaw)).toBe(expected);
expect(markdownService.compile(mockRaw)).toBe(parse(mockRaw));
});

it('should return empty string when raw is null/undefined/empty', () => {
Expand All @@ -67,13 +59,13 @@ describe('MarkdowService', () => {
' * sub-list', // keep indent while removing from previous row offset
].join('\n');

const expected = domSanitizer.sanitize(SecurityContext.HTML, parse([
const expected = [
'',
'* list',
' * sub-list',
].join('\n')));
].join('\n');

expect(markdownService.compile(mockRaw)).toBe(expected);
expect(markdownService.compile(mockRaw)).toBe(parse(expected));
});

it('should return line with indent correctly', () => {
Expand All @@ -85,14 +77,14 @@ describe('MarkdowService', () => {
'Lorem Ipsum', // keep everthing else
].join('\n');

const expected = domSanitizer.sanitize(SecurityContext.HTML, parse([
const expected = [
'* list',
' * sub-list',
'',
'Lorem Ipsum',
].join('\n')));
].join('\n');

expect(markdownService.compile(mockRaw)).toBe(expected);
expect(markdownService.compile(mockRaw)).toBe(parse(expected));
});
});

Expand Down
7 changes: 2 additions & 5 deletions lib/src/markdown.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { HttpClient } from '@angular/common/http';
import { Injectable, Optional, SecurityContext } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { Injectable, Optional } from '@angular/core';
import { parse, Renderer } from 'marked';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
Expand All @@ -25,7 +24,6 @@ export class MarkdownService {

constructor(
@Optional() private http: HttpClient,
private domSanitizer: DomSanitizer,
public options: MarkedOptions,
) {
if (!this.renderer) {
Expand All @@ -35,8 +33,7 @@ export class MarkdownService {

compile(markdown: string, markedOptions = this.options): string {
const precompiled = this.precompile(markdown);
const compiled = parse(precompiled, markedOptions);
return this.domSanitizer.sanitize(SecurityContext.HTML, compiled);
return parse(precompiled, markedOptions);
}

getSource(src: string): Observable<string> {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"build:lib": "ng build lib",
"postbuild:lib": "cpx ./README.md ./dist/lib",
"link:lib": "rimraf node_modules/ngx-markdown && linklocal",
"lint": "yarn lint:lib && yarn lint:demo",
"lint:demo": "ng lint demo",
"lint:lib": "ng lint lib",
"lint:ci": "ng lint lib --format checkstyle > tslint.xml",
Expand Down

0 comments on commit 80d3b60

Please sign in to comment.