Skip to content

Commit

Permalink
fix(core): fix interface geometry paste error #WIK-15877 (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
MissLixf authored and pubuzhixing8 committed Jul 8, 2024
1 parent 650ef63 commit 68a47e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-taxis-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plait/core': patch
---

fix interface geometry paste error
21 changes: 16 additions & 5 deletions packages/core/src/utils/clipboard/common.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { ClipboardData, WritableClipboardContext, WritableClipboardData, WritableClipboardType } from './types';

export const buildPlaitHtml = (type: WritableClipboardType, data: WritableClipboardData) => {
const stringifiedClipboard = JSON.stringify({
type,
data
});
const stringifiedClipboard = replaceAngleBrackets(
JSON.stringify({
type,
data
})
);
return `<plait>${stringifiedClipboard}</plait>`;
};

export const getClipboardFromHtml = (html: string): ClipboardData | null => {
const plaitString = html?.match(/<plait[^>]*>(.*)<\/plait>/)?.[1];
let plaitString = html?.match(/<plait[^>]*>(.*)<\/plait>/)?.[1];
if (plaitString) {
plaitString = reverseReplaceAngleBrackets(plaitString);
try {
const plaitJson = JSON.parse(plaitString);
if (plaitJson) {
Expand Down Expand Up @@ -77,3 +80,11 @@ export const addClipboardContext = (
}
return clipboardContext;
};

export const replaceAngleBrackets = (str: string) => {
return str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
};

export const reverseReplaceAngleBrackets = (str: string) => {
return str.replace(/&lt;/g, '<').replace(/&gt;/g, '>');
};

0 comments on commit 68a47e6

Please sign in to comment.