diff --git a/src/app/core/services/formatter.service.spec.ts b/src/app/core/services/formatter.service.spec.ts index cc1f13e..de6db7e 100644 --- a/src/app/core/services/formatter.service.spec.ts +++ b/src/app/core/services/formatter.service.spec.ts @@ -249,6 +249,42 @@ describe('Service: Formatter', () => { } )); + it('should add closing slash to col elements but not colgroup', inject( + [FormatterService], + (service: FormatterService) => { + const str = ` + + + + + + + + + `; + const result = ` + + + + + + + + + `; + expect(service.useReactSyntax(str)).toBe(result); + } + )); + + it('should not add a closing slash to col elements if it already has one', inject( + [FormatterService], + (service: FormatterService) => { + const str = ``; + const result = ``; + expect(service.useReactSyntax(str)).toBe(result); + } + )); + it('should change svg properties to camelCase', inject( [FormatterService], (service: FormatterService) => { diff --git a/src/app/core/services/formatter.service.ts b/src/app/core/services/formatter.service.ts index c1f5210..2eeb636 100644 --- a/src/app/core/services/formatter.service.ts +++ b/src/app/core/services/formatter.service.ts @@ -108,17 +108,32 @@ export class FormatterService { } useReactSyntax(codeStr: string): string { - const cleanStroke = codeStr.replace(/(stroke)-[a-z]/g, prop => { - const parts = prop.split('-'); - return parts[0] + parts[1].toUpperCase(); - }); - const cleanSVGs = cleanStroke.replace(/(fill|clip)-rule/g, prop => { - const parts = prop.split('-'); - return parts[0] + parts[1].charAt(0).toUpperCase() + parts[1].slice(1); - }); - const closeImgTags = cleanSVGs.replace(//g, ''); - const closeInputTags = closeImgTags.replace(//g, ''); - return closeInputTags.replace(/class=/gm, 'className='); + const reactSyntax = codeStr + .replace(/(stroke)-[a-z]/g, prop => { + const parts = prop.split('-'); + return parts[0] + parts[1].toUpperCase(); + }) + .replace(/(fill|clip)-rule/g, prop => { + const parts = prop.split('-'); + return parts[0] + parts[1].charAt(0).toUpperCase() + parts[1].slice(1); + }) + .replace(//g, '') + .replace(//g, '') + .replace(//g, '') + .replace(//g, '') + .replace(//g, '
') + .replace(//g, '') + .replace(//g, '') + .replace(//g, '') + .replace(//g, '
') + .replace(//g, '') + .replace(//g, '') + .replace(//g, '') + .replace(//g, '') + .replace(//g, '') + .replace(//g, '') + .replace(/class=/gm, 'className='); + return reactSyntax; } toVue(codeStr: string): string {