From 71afca65438c56a2e15648f9312d5c4cf107920c Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 3 Aug 2023 16:10:08 +0400 Subject: [PATCH] Clean inline styles from comments. Closes #1577 --- src/parser/model/ParserHtml.ts | 7 +++++++ test/specs/parser/model/ParserHtml.ts | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/parser/model/ParserHtml.ts b/src/parser/model/ParserHtml.ts index d83b32f22..b53bdff74 100644 --- a/src/parser/model/ParserHtml.ts +++ b/src/parser/model/ParserHtml.ts @@ -78,6 +78,13 @@ const ParserHtml = (em?: EditorModel, config: ParserConfig & { returnArray?: boo */ parseStyle(str: string) { const result: Record = {}; + + while (str.indexOf('/*') >= 0) { + const start = str.indexOf('/*'); + const end = str.indexOf('*/') + 2; + str = str.replace(str.slice(start, end), ''); + } + const decls = str.split(';'); for (let i = 0, len = decls.length; i < len; i++) { diff --git a/test/specs/parser/model/ParserHtml.ts b/test/specs/parser/model/ParserHtml.ts index 2f1302c45..e4001e950 100644 --- a/test/specs/parser/model/ParserHtml.ts +++ b/test/specs/parser/model/ParserHtml.ts @@ -68,6 +68,12 @@ describe('ParserHtml', () => { expect(obj.parseStyle(CSS_BG_STR)).toEqual(CSS_BG_OBJ); }); + test('Parse style with comments', () => { + expect(obj.parseStyle('/* color #ffffff; */ width: 100px;')).toEqual({ + width: '100px', + }); + }); + test('Parse class string to array', () => { var str = 'test1 test2 test3 test-4'; var result = ['test1', 'test2', 'test3', 'test-4'];