Преглед на файлове

Remove htmlToAsciiMarkup filter

Danilo Bargen преди 8 години
родител
ревизия
78976af60c
променени са 3 файла, в които са добавени 1 реда и са изтрити 74 реда
  1. 1 2
      src/directives/compose_area.ts
  2. 0 23
      src/filters.ts
  3. 0 49
      tests/filters.js

+ 1 - 2
src/directives/compose_area.ts

@@ -339,13 +339,12 @@ export default [
                         const text = ev.clipboardData.getData('text/plain');
 
                         // Look up some filter functions
-                        const htmlToAsciiMarkup = $filter('htmlToAsciiMarkup') as (a: string) => string;
                         const escapeHtml = $filter('escapeHtml') as (a: string) => string;
                         const emojify = $filter('emojify') as (a: string, b?: boolean) => string;
                         const nlToBr = $filter('nlToBr') as (a: string, b?: boolean) => string;
 
                         // Escape HTML markup
-                        const escaped = escapeHtml(htmlToAsciiMarkup(text));
+                        const escaped = escapeHtml(text);
 
                         // Apply filters (emojify, convert newline, etc)
                         const formatted = nlToBr(emojify(escaped, true), true);

+ 0 - 23
src/filters.ts

@@ -50,29 +50,6 @@ angular.module('3ema.filters', [])
     };
 })
 
-/**
- * Replace formatting HTML with ASCII alternatives.
- */
-.filter('htmlToAsciiMarkup', function() {
-    return (text) => {
-        let tags = [
-            ['b', '*'],
-            ['strong', '*'],
-            ['i', '_'],
-            ['em', '_'],
-            ['strike', '~'],
-            ['del', '~'],
-            ['s', '~'],
-        ];
-        let out = text;
-        for (let tag of tags) {
-            out = out.replace(new RegExp('<\\s*' + tag[0] + '(\\s[^>]*|\\s*)>', 'gi'), tag[1]);
-            out = out.replace(new RegExp('<\\s*\/\\s*' + tag[0] + '\\s*>', 'gi'), tag[1]);
-        }
-        return out;
-    };
-})
-
 /**
  * Convert links in text to <a> tags.
  */

+ 0 - 49
tests/filters.js

@@ -98,55 +98,6 @@ describe('Filters', function() {
 
     });
 
-    describe('htmlToAsciiMarkup', function() {
-
-        this.testPatterns = (cases) => testPatterns('htmlToAsciiMarkup', cases);
-
-        it('converts bold text', () => {
-            this.testPatterns([
-                ['<b>bold</b>', '*bold*'],
-                ['< 	b >bold</b>', '*bold*'],
-                ['<B>bold</b>', '*bold*'],
-                ['<b class="gsdf">bold</b>', '*bold*'],
-                ['<strong>bold</strong>', '*bold*'],
-                ['<b><b>bold</b></b>', '**bold**'],
-                ['<b><strong>bold</strong></b>', '**bold**'],
-            ]);
-        });
-
-        it('converts italic text', () => {
-            this.testPatterns([
-                ['<i>italic</i>', '_italic_'],
-                ['<i onclick="alert(1)">italic</i>', '_italic_'],
-                ['<em>italic</em>', '_italic_'],
-                ['<i><em>italic</em></i>', '__italic__'],
-            ]);
-        });
-
-        it('converts strikethrough text', () => {
-            this.testPatterns([
-                ['<strike>strikethrough</strike>', '~strikethrough~'],
-                ['<del>strikethrough</del>', '~strikethrough~'],
-                ['<del href="/">strikethrough</del>', '~strikethrough~'],
-                ['<s>strikethrough</s>', '~strikethrough~'],
-                ['<strike><del><s>strikethrough</s></del></strike>', '~~~strikethrough~~~'],
-            ]);
-        });
-
-        it('does not affect other tags', () => {
-            this.testPatterns([
-                ['<script>alert("pho soup time")</script>', '<script>alert("pho soup time")</script>'],
-            ]);
-        });
-
-        it('combination of all', () => {
-            this.testPatterns([
-                ['<b><em><del>foo</del></em></b>', '*_~foo~_*'],
-            ]);
-        });
-
-    });
-
     describe('escapeHtml', function() {
 
         this.testPatterns = (cases) => testPatterns('escapeHtml', cases);