@truedat/core 8.3.5 → 8.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -3
- package/src/components/Markdown.js +15 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truedat/core",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.6",
|
|
4
4
|
"description": "Truedat Web Core",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@testing-library/jest-dom": "^6.6.3",
|
|
52
52
|
"@testing-library/react": "^16.3.0",
|
|
53
53
|
"@testing-library/user-event": "^14.6.1",
|
|
54
|
-
"@truedat/test": "8.3.
|
|
54
|
+
"@truedat/test": "8.3.6",
|
|
55
55
|
"identity-obj-proxy": "^3.0.0",
|
|
56
56
|
"jest": "^29.7.0",
|
|
57
57
|
"redux-saga-test-plan": "^4.0.6"
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"@tiptap/starter-kit": "^3.20.0",
|
|
67
67
|
"@xyflow/react": "^12.6.4",
|
|
68
68
|
"axios": "^1.13.5",
|
|
69
|
+
"dompurify": "^3.3.3",
|
|
69
70
|
"elkjs": "^0.10.0",
|
|
70
71
|
"graphql": "^16.11.0",
|
|
71
72
|
"immutable": "^4.3.7",
|
|
@@ -96,5 +97,5 @@
|
|
|
96
97
|
"swr": "^2.3.3",
|
|
97
98
|
"turndown": "^7.2.2"
|
|
98
99
|
},
|
|
99
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "767585383b6373e75fa50d7440e9ecf67b0573c2"
|
|
100
101
|
}
|
|
@@ -8,6 +8,7 @@ import Heading from "@tiptap/extension-heading";
|
|
|
8
8
|
import { Menu, Icon } from "semantic-ui-react";
|
|
9
9
|
import { FormattedMessage } from "react-intl";
|
|
10
10
|
import { marked } from "marked";
|
|
11
|
+
import DOMPurify from "dompurify";
|
|
11
12
|
import TurndownService from "turndown";
|
|
12
13
|
import TextPromptModal from "./TextPromptModal";
|
|
13
14
|
|
|
@@ -74,12 +75,20 @@ const validateUrl = (value, allowEmpty = false) => {
|
|
|
74
75
|
return { valid: true, value: urlWithProtocol };
|
|
75
76
|
};
|
|
76
77
|
|
|
78
|
+
function stripOuterCodeFence(text) {
|
|
79
|
+
const match = text.match(/^\s*```(?:markdown)?\s*\n([\s\S]*?)\n\s*```\s*$/);
|
|
80
|
+
return match ? match[1] : text;
|
|
81
|
+
}
|
|
82
|
+
|
|
77
83
|
function markdownToHtml(markdown) {
|
|
78
84
|
if (!markdown || (typeof markdown === "string" && markdown.trim() === "")) {
|
|
79
85
|
return "<p></p>";
|
|
80
86
|
}
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
|
|
88
|
+
const cleaned = stripOuterCodeFence(markdown);
|
|
89
|
+
|
|
90
|
+
const withLinks = marked
|
|
91
|
+
.parse(cleaned, { async: false })
|
|
83
92
|
.replace(
|
|
84
93
|
/<a (?=[^>]*href=)/gi,
|
|
85
94
|
`<a target="_blank" rel="noopener noreferrer" `,
|
|
@@ -88,6 +97,10 @@ function markdownToHtml(markdown) {
|
|
|
88
97
|
/href="(?!https?:\/\/|mailto:)([^"]+)"/gi,
|
|
89
98
|
(match, url) => `href="https://${url}"`,
|
|
90
99
|
);
|
|
100
|
+
|
|
101
|
+
const safeHtml = DOMPurify.sanitize(withLinks, { ADD_ATTR: ["target"] });
|
|
102
|
+
|
|
103
|
+
return safeHtml;
|
|
91
104
|
}
|
|
92
105
|
|
|
93
106
|
function htmlToMarkdown(html) {
|