Skip to content

Commit

Permalink
#171 -- in story doesnt break the svg export anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
HannaWPS committed Jan 3, 2025
1 parent 00c5df5 commit 21f3db1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/app/tools/export/services/svg.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '../domain/export/exportConstants';
import { StoryCreatorService } from '../../replay/services/story-creator.service';
import { StorySentence } from '../../replay/domain/storySentence';
import { sanitizeTextForSVGExport } from 'src/app/utils/sanitizer';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -216,7 +217,10 @@ export class SvgService {
}

private appendDST(data: string, dst: ConfigAndDST): string {
data += '\n<!-- <DST>\n' + JSON.stringify(dst, null, 2) + '\n </DST> -->';
data +=
'\n<!-- <DST>\n' +
sanitizeTextForSVGExport(JSON.stringify(dst, null, 2)) +
'\n </DST> -->';
return data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { assign } from "min-dash";
import { autocomplete, getLabel } from "./dsLabelUtil";

import { ElementTypes } from "src/app/domain/entities/elementTypes";
import { sanitizeTextForSVGExport } from "src/app/utils/sanitizer";
import { is } from "../util";

let dictionaryService;
Expand Down Expand Up @@ -307,5 +308,9 @@ DSLabelEditingProvider.prototype.update = function (
};
}

this._modeling.updateLabel(element, newLabel, newBounds);
this._modeling.updateLabel(
element,
sanitizeTextForSVGExport(newLabel),
newBounds,
);
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { sanitizeTextForSVGExport } from "src/app/utils/sanitizer";

export default function headlineAndDescriptionUpdateHandler(
commandStack,
titleService,
Expand All @@ -13,8 +15,8 @@ export default function headlineAndDescriptionUpdateHandler(
ctx.oldDescription = titleService.getDescription();

titleService.updateTitleAndDescription(
ctx.newTitle,
ctx.newDescription,
sanitizeTextForSVGExport(ctx.newTitle),
sanitizeTextForSVGExport(ctx.newDescription),
false,
);
};
Expand Down
31 changes: 28 additions & 3 deletions src/app/utils/sanitizer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
import { sanitizeForDesktop, sanitizeIconName } from './sanitizer';
import {
sanitizeForDesktop,
sanitizeIconName,
sanitizeTextForSVGExport,
} from './sanitizer';

describe('sanitizer', () => {
describe('sanitize for SVG Export', () => {
it('should not sanitize', () => {
const unsanitized = '-test-';
expect(sanitizeTextForSVGExport(unsanitized)).toEqual('-test-');
});
});

describe('sanitize for SVG Export', () => {
it('should sanitize', () => {
const unsanitized = '-test--';
expect(sanitizeTextForSVGExport(unsanitized)).toEqual('-test––');
});
});

describe('sanitize for SVG Export', () => {
it('should sanitize multiple times', () => {
const unsanitized = '------';
expect(sanitizeTextForSVGExport(unsanitized)).toEqual('––––––');
});
});

describe('sanitize for desktop', () => {
it('should sanitize', () => {
const unsanitized = '/\\:*?"><|test';
expect(sanitizeForDesktop(unsanitized)).toEqual('test');
const unsanitized = '/\\:*?"><|-test--';
expect(sanitizeForDesktop(unsanitized)).toEqual('-test––');
});
});

Expand Down
9 changes: 8 additions & 1 deletion src/app/utils/sanitizer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict';

export function sanitizeTextForSVGExport(str: string): string {
// @ts-ignore Typescript does not realize that replaceAll exists, no idea why not.
return str.replaceAll('--', '––');
}

// sanitize user-Input to be Desktop-Filename safe
export function sanitizeForDesktop(str: string): string {
const map: { [key: string]: string } = {
Expand All @@ -14,7 +19,9 @@ export function sanitizeForDesktop(str: string): string {
'|': '',
};
const reg = /[/\\:*?"<>|]/gi;
return str ? str.replace(reg, (match) => map[match]) : '';
return str
? sanitizeTextForSVGExport(str.replace(reg, (match) => map[match]))
: '';
}

export function sanitizeIconName(name: string): string {
Expand Down

0 comments on commit 21f3db1

Please sign in to comment.