Browse Source

Clean inline styles from comments. Closes #1577

canvas-spot
Artur Arseniev 3 years ago
parent
commit
71afca6543
  1. 7
      src/parser/model/ParserHtml.ts
  2. 6
      test/specs/parser/model/ParserHtml.ts

7
src/parser/model/ParserHtml.ts

@ -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++) {

6
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'];

Loading…
Cancel
Save