Skip to content

Commit

Permalink
Clean inline styles from comments. Closes #1577
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Aug 3, 2023
1 parent 6d416c7 commit 71afca6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/parser/model/ParserHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ const ParserHtml = (em?: EditorModel, config: ParserConfig & { returnArray?: boo
*/
parseStyle(str: string) {
const result: Record<string, string | string[]> = {};

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++) {
Expand Down
6 changes: 6 additions & 0 deletions test/specs/parser/model/ParserHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down

0 comments on commit 71afca6

Please sign in to comment.