platejs 54.0.0-beta.13 → 54.0.0-beta.14
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/dist/{EditorStatic-CKG5xM3y.d.ts → EditorStatic-eXOA489B.d.ts} +4 -4
- package/dist/ai/index.d.ts +2 -2
- package/dist/ai/lib/aiDraftSession.js +9 -7
- package/dist/ai/lib/aiPolicy.internal.js +43 -6
- package/dist/ai/lib/editorAgent.js +30 -21
- package/dist/ai/lib/editorAgentSync.internal.js +2 -2
- package/dist/ai/lib/lockedContext.js +5 -4
- package/dist/ai/react/copilotInline.internal.js +6 -5
- package/dist/ai/react/index.d.ts +7 -7
- package/dist/ai/react/useEditorAgent.js +14 -3
- package/dist/authored/index.d.ts +4 -4
- package/dist/{authored-CJL7S8qI-BxC9ip4d.d.ts → authored-qetvpvU--DSWESzxK.d.ts} +3 -3
- package/dist/clipboard-format-key-BBu85J9m-BLhtd159.d.ts +1 -0
- package/dist/code-block/codemirror/index.d.ts +2 -2
- package/dist/{comment-anchor.internal-DTBP1huU.d.ts → comment-anchor.internal-CoNK9gTD.d.ts} +2 -2
- package/dist/compiler/index.d.ts +3 -3
- package/dist/{core-CTB0OBoh.d.ts → core-By92GWYW.d.ts} +45 -20
- package/dist/diff/index.d.ts +2 -2
- package/dist/docs/agents/skills.md +6 -2
- package/dist/docs/agents.md +1 -1
- package/dist/docs/ai-agents.md +8 -4
- package/dist/docs/ai.md +5 -0
- package/dist/docs/api/plate.md +15 -7
- package/dist/docs/api/react-hooks.md +32 -2
- package/dist/docs/authored-changes.md +4 -0
- package/dist/docs/block-menu.md +4 -0
- package/dist/docs/board.md +4 -0
- package/dist/docs/callout.md +63 -9
- package/dist/docs/collaboration.md +6 -1
- package/dist/docs/combobox.md +9 -2
- package/dist/docs/comment.md +4 -0
- package/dist/docs/components/toolbar-buttons.md +1 -1
- package/dist/docs/copilot.md +4 -0
- package/dist/docs/deck.md +173 -0
- package/dist/docs/details.md +4 -0
- package/dist/docs/diff.md +4 -0
- package/dist/docs/discussion.md +4 -0
- package/dist/docs/dnd.md +4 -0
- package/dist/docs/docx.md +6 -0
- package/dist/docs/emoji.md +2 -2
- package/dist/docs/equation.md +4 -0
- package/dist/docs/examples/collaboration-example.md +4 -0
- package/dist/docs/examples/export.md +40 -28
- package/dist/docs/examples/merge.md +4 -0
- package/dist/docs/examples/version-history.md +4 -0
- package/dist/docs/field.md +4 -0
- package/dist/docs/footnote.md +4 -0
- package/dist/docs/format-painter.md +1 -1
- package/dist/docs/html.md +4 -0
- package/dist/docs/index.md +4 -0
- package/dist/docs/ink.md +6 -0
- package/dist/docs/installation/manual.md +2 -4
- package/dist/docs/installation/next.md +1 -3
- package/dist/docs/installation/plate-ui.md +6 -2
- package/dist/docs/installation/rsc.md +1 -1
- package/dist/docs/installation.md +4 -0
- package/dist/docs/link.md +4 -0
- package/dist/docs/llms.txt +3 -1
- package/dist/docs/lock.md +34 -2
- package/dist/docs/markdown.md +4 -0
- package/dist/docs/media.md +4 -0
- package/dist/docs/mention.md +5 -0
- package/dist/docs/pagination.md +4 -0
- package/dist/docs/prompt-editor.md +17 -1
- package/dist/docs/reference.md +192 -0
- package/dist/docs/roots.md +4 -0
- package/dist/docs/serializing.md +23 -0
- package/dist/docs/slash-command.md +58 -4
- package/dist/docs/static.md +29 -20
- package/dist/docs/suggestion.md +4 -0
- package/dist/docs/sync.md +4 -0
- package/dist/docs/table.md +31 -0
- package/dist/docs/toolbar.md +4 -0
- package/dist/docs/unit-testing.md +4 -0
- package/dist/docs/upload.md +4 -0
- package/dist/docx/export/index.d.ts +5 -5
- package/dist/docx/import/index.d.ts +5 -5
- package/dist/docx/paste/index.d.ts +4 -4
- package/dist/dom/index.d.ts +1 -1
- package/dist/features/basic-nodes/lib/BaseMarkPlugins.js +1 -1
- package/dist/features/basic-styles/lib/BaseFormattingPlugin.js +61 -28
- package/dist/features/basic-styles/lib/BaseStylePlugins.js +28 -7
- package/dist/features/board/index.d.ts +1 -1
- package/dist/features/callout/index.d.ts +2 -160
- package/dist/features/callout/lib/BaseCalloutPlugin.js +109 -9
- package/dist/features/column/index.d.ts +1 -1
- package/dist/features/comments/index.d.ts +2 -2
- package/dist/features/date/index.d.ts +3 -3
- package/dist/features/details/index.d.ts +3 -3
- package/dist/features/field/index.d.ts +1 -1
- package/dist/features/field/lib/BaseFieldPlugin.js +111 -53
- package/dist/features/field/lib/fieldCache.internal.js +9 -21
- package/dist/features/find/index.d.ts +3 -3
- package/dist/features/footnote/index.d.ts +3 -3
- package/dist/features/ink/index.d.ts +1 -1
- package/dist/features/link/lib/BaseLinkPlugin.js +5 -2
- package/dist/features/lint/index.d.ts +3 -3
- package/dist/features/list/lib/listKeyboard.internal.js +7 -2
- package/dist/features/lock/index.d.ts +1 -1
- package/dist/features/media/index.d.ts +1 -1
- package/dist/features/mention/index.d.ts +1 -1
- package/dist/features/reference/index.d.ts +236 -0
- package/dist/features/reference/index.js +2 -0
- package/dist/features/reference/lib/BaseReferencePlugin.js +589 -0
- package/dist/features/table/index.d.ts +2 -2
- package/dist/features/toc/index.d.ts +1 -1
- package/dist/features/upload/index.d.ts +1 -1
- package/dist/history/index.d.ts +1 -1
- package/dist/html/index.d.ts +4 -4
- package/dist/html/server/index.d.ts +2 -2
- package/dist/html/server/serverCssParser.internal.js +14 -25
- package/dist/html/server/serverCssStyle.internal.js +4 -7
- package/dist/{htmlConversion-Y-M6PLRi.d.ts → htmlConversion-CRnxMGw-.d.ts} +2 -2
- package/dist/{htmlTypes-CNhoCFjK.d.ts → htmlTypes-3laowz-3.d.ts} +3 -3
- package/dist/hyperscript/index.d.ts +1 -1
- package/dist/{index-B-8L9f6a2.d.ts → index-B3VOCxNR.d.ts} +5 -5
- package/dist/{index-B8JeECEk.d.ts → index-B9UlNijk.d.ts} +2 -2
- package/dist/{index-Bqva6PJc.d.ts → index-BJPT0Tv_.d.ts} +3 -3
- package/dist/{index-CWutqVQ_-BO-UgVeK.d.ts → index-BKPWmnLg-Bp_vItjr.d.ts} +1 -1
- package/dist/{index-BFWK852j.d.ts → index-BcD2RAB9.d.ts} +3 -3
- package/dist/{index-DhsryaAC.d.ts → index-C5Xw3JDc.d.ts} +1 -1
- package/dist/{index-BEXBAmJf.d.ts → index-CAshLTjV.d.ts} +3 -3
- package/dist/{index-qqrnWAk_.d.ts → index-CHlITvuq.d.ts} +7 -7
- package/dist/index-CKSwab_O.d.ts +1 -0
- package/dist/{index-DJhwDkfd.d.ts → index-CRQoHk18.d.ts} +3 -3
- package/dist/index-CyY3O6c7.d.ts +3 -0
- package/dist/index-D8EGVCeT.d.ts +305 -0
- package/dist/{index-B0R9sXv2-T1dxG9oM.d.ts → index-DAKucat0--VOaL_NN.d.ts} +4 -4
- package/dist/{index-UYpvOBXG.d.ts → index-DCTRNYwy.d.ts} +2 -2
- package/dist/{index-CXd5hwaH.d.ts → index-DQpHoxDX.d.ts} +1 -1
- package/dist/{index-BfJKfAwk.d.ts → index-DTd1D-BF.d.ts} +3 -3
- package/dist/index-DUhUT9bV.d.ts +1 -0
- package/dist/{index-B4aToRMv.d.ts → index-DXm_v0Qq.d.ts} +3 -3
- package/dist/{index-D3bhjdRz.d.ts → index-Djwcl0Ff.d.ts} +3 -3
- package/dist/{index-DYuqsDrP.d.ts → index-Dyw6BJx8.d.ts} +3 -3
- package/dist/{index-CLPMcGC5.d.ts → index-KG95XVaC.d.ts} +4 -4
- package/dist/{index-mcBtG6pK-CitQV9Bq.d.ts → index-LEcSTRgn-BR_p4GVY.d.ts} +2 -2
- package/dist/{index-D54VPeky.d.ts → index-k-wvVxKl.d.ts} +2 -2
- package/dist/{index-CHud6Aa-.d.ts → index-s34W6hUI.d.ts} +3 -3
- package/dist/{index-DXCdafUk.d.ts → index-wEkvA-wI.d.ts} +43 -20
- package/dist/index.d.ts +3 -3
- package/dist/internal/plugin/pluginInjectNodeProps.js +33 -5
- package/dist/internal/utils/urlPolicy.js +11 -1
- package/dist/lib/editor/withPlite.js +8 -6
- package/dist/lib/plugins/html/cssLexer.internal.js +126 -29
- package/dist/lib/plugins/html/cssSafety.internal.js +100 -0
- package/dist/lib/plugins/html/htmlDecode.internal.js +2 -2
- package/dist/lib/plugins/html/htmlMatcher.internal.js +1 -1
- package/dist/lib/plugins/html/htmlRules.internal.js +2 -13
- package/dist/lib/plugins/html/htmlSafety.js +17 -24
- package/dist/lib/plugins/html/htmlSerialize.internal.js +16 -2
- package/dist/lib/plugins/html/htmlStyleInline.internal.js +22 -23
- package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +27 -1
- package/dist/markdown/index.d.ts +1 -1
- package/dist/markdown/lib/internal/markdownAttributes.js +16 -7
- package/dist/markdown/lib/internal/markdownMappings.js +123 -16
- package/dist/markdown/lib/serializer/convertPhrasingSerialize.js +16 -1
- package/dist/math/index.d.ts +3 -3
- package/dist/math/react/index.d.ts +4 -4
- package/dist/migrations/index.d.ts +4 -4
- package/dist/migrations/migratePlateV54Urls.internal.js +63 -1
- package/dist/pagination/index.d.ts +1 -1
- package/dist/pagination/react/index.d.ts +3 -3
- package/dist/{protocol-CSuP7AWG-DAorqpaF.d.ts → protocol-Cp9xayOe-0OSfTMnt.d.ts} +1 -1
- package/dist/react/authored/index.d.ts +4 -4
- package/dist/react/components/PlateView.js +7 -1
- package/dist/react/features/board/index.d.ts +5 -5
- package/dist/react/features/callout/index.d.ts +93 -4
- package/dist/react/features/column/index.d.ts +5 -5
- package/dist/react/features/combobox/combobox.internal.js +35 -22
- package/dist/react/features/combobox/comboboxOwner.internal.js +29 -2
- package/dist/react/features/combobox/index.d.ts +8 -6
- package/dist/react/features/comments/index.d.ts +6 -6
- package/dist/react/features/date/index.d.ts +4 -4
- package/dist/react/features/details/index.d.ts +4 -4
- package/dist/react/features/field/FieldPlugin.js +2 -2
- package/dist/react/features/field/index.d.ts +5 -5
- package/dist/react/features/footnote/index.d.ts +4 -4
- package/dist/react/features/format-painter/FormatPainterPlugin.js +27 -34
- package/dist/react/features/format-painter/index.d.ts +4 -4
- package/dist/react/features/ink/index.d.ts +5 -5
- package/dist/react/features/lock/index.d.ts +5 -5
- package/dist/react/features/media/index.d.ts +5 -5
- package/dist/react/features/mention/index.d.ts +4 -4
- package/dist/react/features/table/index.d.ts +6 -6
- package/dist/react/features/toc/index.d.ts +2 -2
- package/dist/react/features/upload/index.d.ts +5 -5
- package/dist/react/index.d.ts +6 -6
- package/dist/react/virtualized.d.ts +3 -3
- package/dist/refusal-CwFxNUf7-BLhtd159.d.ts +1 -0
- package/dist/{registerEditorTools-Cl-o_Wnq.d.ts → registerEditorTools-D_3hPpTx.d.ts} +16 -8
- package/dist/shared-room-26tNRhZE-BLhtd159.d.ts +1 -0
- package/dist/skills/plate/SKILL.md +4 -3
- package/dist/skills/plate/references/ai-and-agents.md +2 -2
- package/dist/skills/plate/references/pricing.md +3 -3
- package/dist/skills/plate/references/setup.md +6 -0
- package/dist/skills/plate/references/ui-and-sync.md +4 -3
- package/dist/{source-DUP5aKcT.d.ts → source-BW7JD_oS.d.ts} +3 -3
- package/dist/static/index.d.ts +23 -9
- package/dist/static/internal/staticPendingMedia.internal.js +2 -1
- package/dist/static/internal/staticPresentation.js +1 -0
- package/dist/static/renderStaticHtml.js +85 -39
- package/dist/{storage-EzfLDqRy-Cu4DQ-Rf.d.ts → storage-C7xSH1I5-BJLoUfo9.d.ts} +2 -2
- package/dist/sync/cloudflare/index.d.ts +3 -3
- package/dist/sync/index.d.ts +4 -4
- package/dist/sync/postgres/index.d.ts +1 -1
- package/dist/sync/react/index.d.ts +6 -6
- package/dist/sync/server/index.d.ts +5 -5
- package/dist/tabbable/react/index.d.ts +4 -4
- package/dist/testing/index.d.ts +3 -3
- package/dist/{transport-DAforzBt-BFwAhC-N.d.ts → transport-B-ON68Y4-DCfT5-eN.d.ts} +1 -1
- package/dist/utils/plate-keys.js +1 -0
- package/dist/{widths-BjIZxtaJ.d.ts → widths-9NNziDRW.d.ts} +5 -5
- package/package.json +9 -2
- package/dist/clipboard-format-key-D9rnh20X-CR00YA0H.d.ts +0 -1
- package/dist/index-CKAkaSJK.d.ts +0 -3
- package/dist/index-CxyK4HrT.d.ts +0 -1
- package/dist/index-zcb_RtZC.d.ts +0 -1
- package/dist/refusal-DCzeB9nD-CR00YA0H.d.ts +0 -1
- package/dist/shared-room-Bg8qMvm1-CR00YA0H.d.ts +0 -1
- /package/dist/{tx-only-CWT-IURY-BqIFhy44.d.ts → tx-only-sIj7BcYh-BMFkGMuq.d.ts} +0 -0
|
@@ -1,7 +1,58 @@
|
|
|
1
1
|
//#region src/lib/plugins/html/cssLexer.internal.ts
|
|
2
2
|
const STANDARD_PROPERTY_RE = /^-?[a-z][a-z0-9-]*$/;
|
|
3
|
+
const CSS_ESCAPE_RE = /\\(?:([\da-f]{1,6})[\t\n\f\r ]?|([^\n\f\r\da-f]))/giu;
|
|
3
4
|
const isCssWhitespaceCode = (code) => code === 32 || code === 9 || code === 10 || code === 12 || code === 13;
|
|
4
5
|
const isCssWhitespaceChar = (ch) => ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f";
|
|
6
|
+
const isHexDigitCode = (code) => code >= 48 && code <= 57 || code >= 65 && code <= 70 || code >= 97 && code <= 102;
|
|
7
|
+
const decodeHexCodePoint = (hex) => {
|
|
8
|
+
const codePoint = Number.parseInt(hex, 16);
|
|
9
|
+
return String.fromCodePoint(codePoint === 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343 ? 65533 : codePoint);
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Advance past one CSS backslash escape starting at `index` per CSS Syntax
|
|
13
|
+
* Level 3 §4.3.7 (1..6 hex digits plus optional single `\r\n` or whitespace,
|
|
14
|
+
* CRLF line continuation, or one escaped character).
|
|
15
|
+
*/
|
|
16
|
+
const stepCssEscape = (text, index) => {
|
|
17
|
+
if (index + 1 >= text.length) return index + 1;
|
|
18
|
+
if (text[index + 1] === "\r" && text[index + 2] === "\n") return index + 3;
|
|
19
|
+
let hexEnd = index + 1;
|
|
20
|
+
while (hexEnd < text.length && hexEnd - (index + 1) < 6 && isHexDigitCode(text.charCodeAt(hexEnd))) hexEnd += 1;
|
|
21
|
+
if (hexEnd > index + 1) {
|
|
22
|
+
if (text[hexEnd] === "\r" && text[hexEnd + 1] === "\n") return hexEnd + 2;
|
|
23
|
+
if (hexEnd < text.length && isCssWhitespaceChar(text[hexEnd])) return hexEnd + 1;
|
|
24
|
+
return hexEnd;
|
|
25
|
+
}
|
|
26
|
+
return index + 2;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Decode one CSS escape sequence starting at `text[index] === '\\'` per CSS
|
|
30
|
+
* Syntax Level 3 §4.3.7. Returns `null` for an escaped newline (`\n`, `\r`, `\f`).
|
|
31
|
+
*/
|
|
32
|
+
const decodeCssEscapeAt = (text, index) => {
|
|
33
|
+
const next = text[index + 1];
|
|
34
|
+
if (next === void 0) return {
|
|
35
|
+
char: "�",
|
|
36
|
+
end: index + 1
|
|
37
|
+
};
|
|
38
|
+
if (next === "\n" || next === "\r" || next === "\f") return null;
|
|
39
|
+
let hexEnd = index + 1;
|
|
40
|
+
while (hexEnd < text.length && hexEnd - (index + 1) < 6 && isHexDigitCode(text.charCodeAt(hexEnd))) hexEnd += 1;
|
|
41
|
+
if (hexEnd > index + 1) {
|
|
42
|
+
let end = hexEnd;
|
|
43
|
+
if (text[end] === "\r" && text[end + 1] === "\n") end += 2;
|
|
44
|
+
else if (end < text.length && isCssWhitespaceChar(text[end])) end += 1;
|
|
45
|
+
return {
|
|
46
|
+
char: decodeHexCodePoint(text.slice(index + 1, hexEnd)),
|
|
47
|
+
end
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
char: next,
|
|
52
|
+
end: index + 2
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const decodeCssEscapes = (value) => value.replaceAll("\r\n", "\n").replaceAll(CSS_ESCAPE_RE, (_, hex, character) => hex === void 0 ? character ?? "" : decodeHexCodePoint(hex));
|
|
5
56
|
const normalizeCssPropertyName = (rawName) => {
|
|
6
57
|
const trimmed = rawName.trim();
|
|
7
58
|
if (trimmed.startsWith("--")) return trimmed.length > 2 && !/\s/.test(trimmed) ? trimmed : null;
|
|
@@ -14,9 +65,10 @@ const findClosingCssQuote = (text, start) => {
|
|
|
14
65
|
while (i < text.length) {
|
|
15
66
|
const ch = text[i];
|
|
16
67
|
if (ch === "\\") {
|
|
17
|
-
i
|
|
68
|
+
i = stepCssEscape(text, i);
|
|
18
69
|
continue;
|
|
19
70
|
}
|
|
71
|
+
if (ch === "\n" || ch === "\r" || ch === "\f") return -1;
|
|
20
72
|
if (ch === quote) return i + 1;
|
|
21
73
|
i += 1;
|
|
22
74
|
}
|
|
@@ -24,18 +76,27 @@ const findClosingCssQuote = (text, start) => {
|
|
|
24
76
|
};
|
|
25
77
|
const skipQuotedCssString = (text, start) => {
|
|
26
78
|
const end = findClosingCssQuote(text, start);
|
|
27
|
-
|
|
79
|
+
if (end !== -1) return end;
|
|
80
|
+
let i = start + 1;
|
|
81
|
+
while (i < text.length) {
|
|
82
|
+
const ch = text[i];
|
|
83
|
+
if (ch === "\\") {
|
|
84
|
+
i = stepCssEscape(text, i);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (ch === "\n" || ch === "\r" || ch === "\f") return i;
|
|
88
|
+
i += 1;
|
|
89
|
+
}
|
|
90
|
+
return text.length;
|
|
28
91
|
};
|
|
29
92
|
const hasUnbalancedCssDelimiters = (text) => {
|
|
30
|
-
|
|
31
|
-
let bracketDepth = 0;
|
|
32
|
-
let braceDepth = 0;
|
|
93
|
+
const stack = [];
|
|
33
94
|
let i = 0;
|
|
34
95
|
while (i < text.length) {
|
|
35
96
|
const ch = text[i];
|
|
36
97
|
if (ch === "\\") {
|
|
37
98
|
if (i + 1 >= text.length) return true;
|
|
38
|
-
i
|
|
99
|
+
i = stepCssEscape(text, i);
|
|
39
100
|
continue;
|
|
40
101
|
}
|
|
41
102
|
if (ch === "\"" || ch === "'") {
|
|
@@ -44,38 +105,52 @@ const hasUnbalancedCssDelimiters = (text) => {
|
|
|
44
105
|
i = end;
|
|
45
106
|
continue;
|
|
46
107
|
}
|
|
47
|
-
if (ch === "("
|
|
48
|
-
else if (ch === ")") {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
} else if (ch === "[") bracketDepth += 1;
|
|
52
|
-
else if (ch === "]") {
|
|
53
|
-
if (bracketDepth === 0) return true;
|
|
54
|
-
bracketDepth -= 1;
|
|
55
|
-
} else if (ch === "{") braceDepth += 1;
|
|
56
|
-
else if (ch === "}") {
|
|
57
|
-
if (braceDepth === 0) return true;
|
|
58
|
-
braceDepth -= 1;
|
|
108
|
+
if (ch === "(" || ch === "[" || ch === "{") stack.push(ch);
|
|
109
|
+
else if (ch === ")" || ch === "]" || ch === "}") {
|
|
110
|
+
const expected = ch === ")" ? "(" : ch === "]" ? "[" : "{";
|
|
111
|
+
if (stack.pop() !== expected) return true;
|
|
59
112
|
}
|
|
60
113
|
i += 1;
|
|
61
114
|
}
|
|
62
|
-
return
|
|
115
|
+
return stack.length !== 0;
|
|
63
116
|
};
|
|
64
117
|
const skipBalancedCssBlock = (text, start) => {
|
|
65
|
-
|
|
118
|
+
const stack = ["{"];
|
|
119
|
+
let openBraces = 1;
|
|
120
|
+
let openParens = 0;
|
|
121
|
+
let openBrackets = 0;
|
|
66
122
|
let i = start + 1;
|
|
67
|
-
while (i < text.length &&
|
|
123
|
+
while (i < text.length && stack.length > 0) {
|
|
68
124
|
const ch = text[i];
|
|
69
125
|
if (ch === "\"" || ch === "'") {
|
|
70
126
|
i = skipQuotedCssString(text, i);
|
|
71
127
|
continue;
|
|
72
128
|
}
|
|
73
129
|
if (ch === "\\") {
|
|
74
|
-
i
|
|
130
|
+
i = stepCssEscape(text, i);
|
|
75
131
|
continue;
|
|
76
132
|
}
|
|
77
|
-
if (ch === "{")
|
|
78
|
-
|
|
133
|
+
if (ch === "{") {
|
|
134
|
+
stack.push("{");
|
|
135
|
+
openBraces += 1;
|
|
136
|
+
} else if (ch === "(") {
|
|
137
|
+
stack.push("(");
|
|
138
|
+
openParens += 1;
|
|
139
|
+
} else if (ch === "[") {
|
|
140
|
+
stack.push("[");
|
|
141
|
+
openBrackets += 1;
|
|
142
|
+
} else if (ch === "}" || ch === ")" || ch === "]") {
|
|
143
|
+
if (ch === "}" ? openBraces > 0 : ch === ")" ? openParens > 0 : openBrackets > 0) {
|
|
144
|
+
const expected = ch === "}" ? "{" : ch === ")" ? "(" : "[";
|
|
145
|
+
while (stack.length > 0) {
|
|
146
|
+
const popped = stack.pop();
|
|
147
|
+
if (popped === "{") openBraces -= 1;
|
|
148
|
+
else if (popped === "(") openParens -= 1;
|
|
149
|
+
else if (popped === "[") openBrackets -= 1;
|
|
150
|
+
if (popped === expected) break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
79
154
|
i += 1;
|
|
80
155
|
}
|
|
81
156
|
return i;
|
|
@@ -98,8 +173,9 @@ const stripCssComments = (input, options) => {
|
|
|
98
173
|
continue;
|
|
99
174
|
}
|
|
100
175
|
if (ch === "\\" && i + 1 < input.length) {
|
|
101
|
-
|
|
102
|
-
|
|
176
|
+
const next = stepCssEscape(input, i);
|
|
177
|
+
out += input.slice(i, next);
|
|
178
|
+
i = next;
|
|
103
179
|
continue;
|
|
104
180
|
}
|
|
105
181
|
if (ch === "/" && input[i + 1] === "*") {
|
|
@@ -136,7 +212,7 @@ const scanCssTopLevel = (value, onChar) => {
|
|
|
136
212
|
continue;
|
|
137
213
|
}
|
|
138
214
|
if (ch === "\\") {
|
|
139
|
-
i
|
|
215
|
+
i = stepCssEscape(value, i);
|
|
140
216
|
continue;
|
|
141
217
|
}
|
|
142
218
|
if (ch === "(") parenDepth += 1;
|
|
@@ -192,6 +268,27 @@ const parseCssDeclarationPriority = (property, rawValue) => {
|
|
|
192
268
|
value: rawValue
|
|
193
269
|
};
|
|
194
270
|
};
|
|
271
|
+
/**
|
|
272
|
+
* Parse one CSS `property: value [!important]` declaration, rejecting invalid
|
|
273
|
+
* property names, unbalanced delimiters, and malformed `!` suffixes.
|
|
274
|
+
*/
|
|
275
|
+
const parseCssDeclaration = (rawDeclaration) => {
|
|
276
|
+
const trimmed = rawDeclaration.trim();
|
|
277
|
+
if (!trimmed) return null;
|
|
278
|
+
const colonIndex = findTopLevelCssColon(trimmed);
|
|
279
|
+
if (colonIndex <= 0) return null;
|
|
280
|
+
const property = normalizeCssPropertyName(trimmed.slice(0, colonIndex));
|
|
281
|
+
if (!property) return null;
|
|
282
|
+
const rawValue = trimmed.slice(colonIndex + 1).trim();
|
|
283
|
+
if (!rawValue || hasUnbalancedCssDelimiters(rawValue)) return null;
|
|
284
|
+
const parsed = parseCssDeclarationPriority(property, rawValue);
|
|
285
|
+
if (!parsed) return null;
|
|
286
|
+
return {
|
|
287
|
+
important: parsed.important,
|
|
288
|
+
property,
|
|
289
|
+
value: parsed.value
|
|
290
|
+
};
|
|
291
|
+
};
|
|
195
292
|
const splitCssTopLevel = (text, separator, maxItems = Number.POSITIVE_INFINITY) => {
|
|
196
293
|
const items = [];
|
|
197
294
|
let start = 0;
|
|
@@ -232,7 +329,7 @@ const splitCssDeclarations = (cssText, options) => {
|
|
|
232
329
|
continue;
|
|
233
330
|
}
|
|
234
331
|
if (ch === "\\") {
|
|
235
|
-
i
|
|
332
|
+
i = stepCssEscape(source, i);
|
|
236
333
|
continue;
|
|
237
334
|
}
|
|
238
335
|
if (ch === "(") {
|
|
@@ -299,4 +396,4 @@ const splitCssDeclarations = (cssText, options) => {
|
|
|
299
396
|
return items;
|
|
300
397
|
};
|
|
301
398
|
//#endregion
|
|
302
|
-
export { findLastTopLevelCssBang, findTopLevelCssColon, hasUnbalancedCssDelimiters, isCssWhitespaceChar, isCssWhitespaceCode, normalizeCssPropertyName, parseCssDeclarationPriority, scanCssTopLevel, skipBalancedCssBlock, skipQuotedCssString, splitCssDeclarations, splitCssTopLevel, stripCssComments };
|
|
399
|
+
export { decodeCssEscapeAt, decodeCssEscapes, findClosingCssQuote, findLastTopLevelCssBang, findTopLevelCssColon, hasUnbalancedCssDelimiters, isCssWhitespaceChar, isCssWhitespaceCode, normalizeCssPropertyName, parseCssDeclaration, parseCssDeclarationPriority, scanCssTopLevel, skipBalancedCssBlock, skipQuotedCssString, splitCssDeclarations, splitCssTopLevel, stepCssEscape, stripCssComments };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { decodeCssEscapes, findClosingCssQuote, findLastTopLevelCssBang, findTopLevelCssColon, hasUnbalancedCssDelimiters, normalizeCssPropertyName, splitCssDeclarations, stepCssEscape, stripCssComments } from "./cssLexer.internal.js";
|
|
2
|
+
//#region src/lib/plugins/html/cssSafety.internal.ts
|
|
3
|
+
const CSS_UNSAFE_FUNCTION_RE = /(?:\burl\s*\(|\bimage-set\s*\(|\bsrc\s*\(|@import\b|\bexpression\s*\(|\battr\s*\()/iu;
|
|
4
|
+
const CSS_UNSAFE_UNQUOTED_PUNCT_RE = /[;:{}]|\/\*|\*\//;
|
|
5
|
+
const CSS_UNSAFE_ATTR_UNQUOTED_PUNCT_RE = /[{}]|\/\*|\*\//;
|
|
6
|
+
const CSS_UNSAFE_IMPORTANT_RE = /!\s*important\b/iu;
|
|
7
|
+
const hasControlCharacter = (value) => {
|
|
8
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
9
|
+
const code = value.charCodeAt(index);
|
|
10
|
+
if (code <= 31 || code >= 127 && code <= 159) return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
};
|
|
14
|
+
const extractUnquotedCss = (value) => {
|
|
15
|
+
let unquoted = "";
|
|
16
|
+
let i = 0;
|
|
17
|
+
while (i < value.length) {
|
|
18
|
+
const ch = value[i];
|
|
19
|
+
if (ch === "\\") {
|
|
20
|
+
const next = stepCssEscape(value, i);
|
|
21
|
+
unquoted += value.slice(i, next);
|
|
22
|
+
i = next;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (ch === "\"" || ch === "'") {
|
|
26
|
+
const end = findClosingCssQuote(value, i);
|
|
27
|
+
if (end === -1) return null;
|
|
28
|
+
unquoted += " ";
|
|
29
|
+
i = end;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
unquoted += ch;
|
|
33
|
+
i += 1;
|
|
34
|
+
}
|
|
35
|
+
return unquoted;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Return `true` when CSS text outside comments and quoted strings references an
|
|
39
|
+
* external resource or active expression (`url()`, `image-set()`, `src()`,
|
|
40
|
+
* `@import`, `expression()`, `attr()`), accounting for CSS escape sequences.
|
|
41
|
+
*/
|
|
42
|
+
const isResourceBearingCss = (value) => {
|
|
43
|
+
const stripped = stripCssComments(value);
|
|
44
|
+
const unquoted = extractUnquotedCss(stripped);
|
|
45
|
+
if (unquoted === null) return CSS_UNSAFE_FUNCTION_RE.test(decodeCssEscapes(stripped));
|
|
46
|
+
return CSS_UNSAFE_FUNCTION_RE.test(decodeCssEscapes(unquoted));
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Return `true` when a single CSS property value is safe to persist, serialize
|
|
50
|
+
* into HTML or Markdown `style` attributes, and pass into React/static inline
|
|
51
|
+
* styles. Quoted CSS string literals (such as `font-family: "Foo;Bar !important"`,
|
|
52
|
+
* `font-family: "url(Notes)"`, and `'\5FAE\8F6F\96C5\9ED1'`) and escaped idents
|
|
53
|
+
* (`O\'Reilly`) remain valid while unquoted declaration breaks, comments,
|
|
54
|
+
* `<`/`>`, `!important`, unbalanced delimiters, non-whitespace control
|
|
55
|
+
* characters, and resource/expression functions are rejected.
|
|
56
|
+
*/
|
|
57
|
+
const isSafeStyleValue = (value) => {
|
|
58
|
+
if (value.trim().length === 0) return false;
|
|
59
|
+
if (hasControlCharacter(value)) return false;
|
|
60
|
+
if (value.includes("<") || value.includes(">")) return false;
|
|
61
|
+
if (hasUnbalancedCssDelimiters(value)) return false;
|
|
62
|
+
const unquoted = extractUnquotedCss(value);
|
|
63
|
+
if (unquoted === null) return false;
|
|
64
|
+
if (CSS_UNSAFE_UNQUOTED_PUNCT_RE.test(unquoted)) return false;
|
|
65
|
+
if (findLastTopLevelCssBang(value) !== -1) return false;
|
|
66
|
+
const decoded = decodeCssEscapes(unquoted);
|
|
67
|
+
if (decoded.includes("<") || decoded.includes(">")) return false;
|
|
68
|
+
if (CSS_UNSAFE_UNQUOTED_PUNCT_RE.test(decoded)) return false;
|
|
69
|
+
if (CSS_UNSAFE_IMPORTANT_RE.test(decoded)) return false;
|
|
70
|
+
if (CSS_UNSAFE_FUNCTION_RE.test(decoded)) return false;
|
|
71
|
+
return true;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Return `true` when a serialized HTML `style` attribute declaration list is
|
|
75
|
+
* safe: every `;`-separated declaration must have a valid CSS property name and
|
|
76
|
+
* satisfy `isSafeStyleValue`, with zero unquoted comments, blocks, `<`/`>`,
|
|
77
|
+
* control characters, or unbalanced delimiters.
|
|
78
|
+
*/
|
|
79
|
+
const isSafeStyleAttribute = (value) => {
|
|
80
|
+
if (hasControlCharacter(value)) return false;
|
|
81
|
+
if (value.includes("<") || value.includes(">")) return false;
|
|
82
|
+
if (hasUnbalancedCssDelimiters(value)) return false;
|
|
83
|
+
const unquoted = extractUnquotedCss(value);
|
|
84
|
+
if (unquoted === null) return false;
|
|
85
|
+
if (CSS_UNSAFE_ATTR_UNQUOTED_PUNCT_RE.test(unquoted)) return false;
|
|
86
|
+
const decoded = decodeCssEscapes(unquoted);
|
|
87
|
+
if (decoded.includes("<") || decoded.includes(">")) return false;
|
|
88
|
+
if (CSS_UNSAFE_ATTR_UNQUOTED_PUNCT_RE.test(decoded)) return false;
|
|
89
|
+
if (CSS_UNSAFE_FUNCTION_RE.test(decoded)) return false;
|
|
90
|
+
for (const declaration of splitCssDeclarations(value)) {
|
|
91
|
+
const colonIndex = findTopLevelCssColon(declaration);
|
|
92
|
+
if (colonIndex <= 0) return false;
|
|
93
|
+
if (!normalizeCssPropertyName(declaration.slice(0, colonIndex))) return false;
|
|
94
|
+
const rawValue = declaration.slice(colonIndex + 1).trim();
|
|
95
|
+
if (!rawValue || !isSafeStyleValue(rawValue)) return false;
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
};
|
|
99
|
+
//#endregion
|
|
100
|
+
export { isResourceBearingCss, isSafeStyleAttribute, isSafeStyleValue };
|
|
@@ -2,8 +2,8 @@ import { ElementApi, TextApi, reportEditorLifecycleError } from "../../../facade
|
|
|
2
2
|
import { failInvariant } from "../../../internal/failInvariant.js";
|
|
3
3
|
import { isTextBlockElement } from "../../../internal/plugin/pluginFormatOperation.js";
|
|
4
4
|
import { isHtmlBlockElement, isHtmlElement } from "./htmlDom.js";
|
|
5
|
-
import { withHtmlDocumentQuery } from "./htmlMatcher.internal.js";
|
|
6
|
-
import { EMBEDDED_HTML_CONTENT, HTML_FORMAT, getMatchedRules, htmlTreeLocation, isContainerElement,
|
|
5
|
+
import { isRecord, withHtmlDocumentQuery } from "./htmlMatcher.internal.js";
|
|
6
|
+
import { EMBEDDED_HTML_CONTENT, HTML_FORMAT, getMatchedRules, htmlTreeLocation, isContainerElement, normalizeAttributeName } from "./htmlRules.internal.js";
|
|
7
7
|
import { coalesceAdjacentText, htmlBrToNewLine, htmlTextNodeToString, inferWhiteSpaceRule } from "./htmlWhitespace.internal.js";
|
|
8
8
|
import isEqual from "lodash/isEqual.js";
|
|
9
9
|
import { nanoid } from "nanoid";
|
|
@@ -105,4 +105,4 @@ const isHtmlContainerBoundary = (element) => {
|
|
|
105
105
|
/** @internal */
|
|
106
106
|
const isHtmlMappedBlock = (element) => (element.ownerDocument ? HTML_DOCUMENT_QUERIES.get(element.ownerDocument)?.isMappedBlock(element) : void 0) ?? false;
|
|
107
107
|
//#endregion
|
|
108
|
-
export { HTML_ATTRIBUTE_RE, compileMatcher, getHtmlPluginState, isHtmlContainerBoundary, isHtmlMappedBlock, matches, normalizeStyleName, withHtmlDocumentQuery };
|
|
108
|
+
export { HTML_ATTRIBUTE_RE, compileMatcher, getHtmlPluginState, isHtmlContainerBoundary, isHtmlMappedBlock, isRecord, matches, normalizeStyleName, withHtmlDocumentQuery };
|
|
@@ -3,8 +3,7 @@ import { failInvariant } from "../../../internal/failInvariant.js";
|
|
|
3
3
|
import { getHtmlMappingSchemaFamilies, getPluginSchemaFamily } from "../../../internal/utils/mergePlugins.js";
|
|
4
4
|
import { assertErrorFirstDiagnostics, repairLocation } from "../../../internal/plugin/conversionLaws.js";
|
|
5
5
|
import { createPluginContext } from "../../plugin/createPluginContext.internal.js";
|
|
6
|
-
import {
|
|
7
|
-
import { compileMatcher, matches, normalizeStyleName } from "./htmlMatcher.internal.js";
|
|
6
|
+
import { compileMatcher, isRecord, matches, normalizeStyleName } from "./htmlMatcher.internal.js";
|
|
8
7
|
//#region src/lib/plugins/html/htmlRules.internal.ts
|
|
9
8
|
const HTML_FORMAT = "text/html";
|
|
10
9
|
const HTML_HOST_KEY = "core:html";
|
|
@@ -57,7 +56,6 @@ const HTML_VOID_TAGS = /* @__PURE__ */ new Set([
|
|
|
57
56
|
]);
|
|
58
57
|
const HTML_TAG_RE = /^[a-z][a-z0-9-]*$/;
|
|
59
58
|
const HTML_STYLE_NAME_RE = /^(?:--[A-Za-z_][A-Za-z0-9_-]*|-?[a-z][a-z0-9-]*)$/;
|
|
60
|
-
const HTML_UNSAFE_STYLE_VALUE_RE = /[;{}\\]|\/\*|\*\//;
|
|
61
59
|
const EMBEDDED_HTML_CONTENT = /* @__PURE__ */ new Set([
|
|
62
60
|
"audio",
|
|
63
61
|
"canvas",
|
|
@@ -68,15 +66,6 @@ const EMBEDDED_HTML_CONTENT = /* @__PURE__ */ new Set([
|
|
|
68
66
|
const COMPILED_PLATE_HTML = /* @__PURE__ */ new WeakMap();
|
|
69
67
|
const COMPILED_PLATE_HTML_BY_SCHEMA = /* @__PURE__ */ new WeakMap();
|
|
70
68
|
const isContainerElement = (value) => typeof value === "object" && value !== null && "nodeType" in value && value.nodeType === 1;
|
|
71
|
-
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
72
|
-
const hasControlCharacter = (value) => {
|
|
73
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
74
|
-
const code = value.charCodeAt(index);
|
|
75
|
-
if (code <= 31 || code >= 127 && code <= 159) return true;
|
|
76
|
-
}
|
|
77
|
-
return false;
|
|
78
|
-
};
|
|
79
|
-
const isSafeStyleValue = (value) => !hasControlCharacter(value) && !HTML_UNSAFE_STYLE_VALUE_RE.test(value) && !isResourceBearingCss(value);
|
|
80
69
|
const normalizeAttributeName = (name) => name.toLowerCase();
|
|
81
70
|
const compareRules = (left, right) => right.rulePriority - left.rulePriority || left.owner.localeCompare(right.owner);
|
|
82
71
|
const compileProperties = (owner, binding) => {
|
|
@@ -425,4 +414,4 @@ const repairDiagnostic = (repair, lossPolicy) => {
|
|
|
425
414
|
});
|
|
426
415
|
};
|
|
427
416
|
//#endregion
|
|
428
|
-
export { COMPILED_PLATE_HTML, COMPILED_PLATE_HTML_BY_SCHEMA, EMBEDDED_HTML_CONTENT, HTML_CONTENT_TOKEN, HTML_FORMAT, HTML_HOST_KEY, HTML_NODE_FIELDS, HTML_PATCH_FIELDS, HTML_PLUGIN_NAME, HTML_STYLE_NAME_RE, HTML_TAG_RE, HTML_VOID_TAGS, HTML_WRAPPER_FIELDS, assertStaticConflicts, compareRules, compileMatcherIndex, compileRule, compileSerializerIndex, failedHtmlDiagnostics, getMatchedRules, htmlMappingDiagnostics, htmlTreeLocation, isContainerElement, isRecord, isRejectedRemoval,
|
|
417
|
+
export { COMPILED_PLATE_HTML, COMPILED_PLATE_HTML_BY_SCHEMA, EMBEDDED_HTML_CONTENT, HTML_CONTENT_TOKEN, HTML_FORMAT, HTML_HOST_KEY, HTML_NODE_FIELDS, HTML_PATCH_FIELDS, HTML_PLUGIN_NAME, HTML_STYLE_NAME_RE, HTML_TAG_RE, HTML_VOID_TAGS, HTML_WRAPPER_FIELDS, assertStaticConflicts, compareRules, compileMatcherIndex, compileRule, compileSerializerIndex, failedHtmlDiagnostics, getMatchedRules, htmlMappingDiagnostics, htmlTreeLocation, isContainerElement, isRecord, isRejectedRemoval, normalizeAttributeName, repairDiagnostic, ruleClaimKeys, schemaFailure, unsafeContentDiagnostic };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { decideUrl, isScriptCapableUrl, isScriptUrl } from "../../../internal/utils/urlPolicy.js";
|
|
2
2
|
import { isCssWhitespaceCode } from "./cssLexer.internal.js";
|
|
3
|
+
import { isResourceBearingCss } from "./cssSafety.internal.js";
|
|
3
4
|
import { MATHML_ELEMENTS, isHtmlElement } from "./htmlDom.js";
|
|
4
5
|
//#region src/lib/plugins/html/htmlSafety.ts
|
|
5
6
|
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
@@ -29,8 +30,6 @@ const NON_RENDERING_TAGS = /* @__PURE__ */ new Set([
|
|
|
29
30
|
"style",
|
|
30
31
|
"template"
|
|
31
32
|
]);
|
|
32
|
-
const CSS_RESOURCE = /(?:\burl\s*\(|\bimage-set\s*\(|\bsrc\s*\(|@import\b)/iu;
|
|
33
|
-
const CSS_ESCAPE = /\\(?:([\da-f]{1,6})[\t\n\f\r ]?|([^\n\f\r\da-f]))/giu;
|
|
34
33
|
const trimHtmlWhitespace = (value) => {
|
|
35
34
|
let start = 0;
|
|
36
35
|
let end = value.length;
|
|
@@ -45,12 +44,6 @@ const urlRole = (tag, name) => {
|
|
|
45
44
|
if (tag === "img") return "image";
|
|
46
45
|
return tag === "iframe" || tag === "frame" ? "embed" : "media";
|
|
47
46
|
};
|
|
48
|
-
const decodeCssEscapes = (value) => value.replaceAll("\r\n", "\n").replaceAll(CSS_ESCAPE, (_, hex, character) => {
|
|
49
|
-
if (hex === void 0) return character ?? "";
|
|
50
|
-
const codePoint = Number.parseInt(hex, 16);
|
|
51
|
-
return String.fromCodePoint(codePoint === 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343 ? 65533 : codePoint);
|
|
52
|
-
});
|
|
53
|
-
const isResourceBearingCss = (value) => CSS_RESOURCE.test(decodeCssEscapes(value));
|
|
54
47
|
/**
|
|
55
48
|
* Decide whether an element is removed with its subtree. `isDecorative` is
|
|
56
49
|
* read only for a removal: content hidden from assistive technology is not
|
|
@@ -105,15 +98,15 @@ const isAriaHidden = (element) => {
|
|
|
105
98
|
*/
|
|
106
99
|
const sanitizeHtmlDom = (root, report, options) => {
|
|
107
100
|
const admitsMathml = options?.admitsMathml ?? false;
|
|
108
|
-
const mathmlPlace = (element, tag) => {
|
|
109
|
-
if (!
|
|
110
|
-
if (tag === "math" && element.parentElement?.closest("math")
|
|
101
|
+
const mathmlPlace = (element, tag, allowMathml) => {
|
|
102
|
+
if (!allowMathml) return void 0;
|
|
103
|
+
if (tag === "math" && !element.parentElement?.closest("math")) return "outside";
|
|
111
104
|
if (element.closest("math") !== null) return isAriaHidden(element) ? "hidden" : "inside";
|
|
112
105
|
};
|
|
113
|
-
const sanitizeAttributes = (element, tag) => {
|
|
106
|
+
const sanitizeAttributes = (element, tag, allowMathml) => {
|
|
114
107
|
let removedSource = false;
|
|
115
108
|
for (const name of element.getAttributeNames()) {
|
|
116
|
-
const decision = decideHtmlAttribute(tag, name, element.getAttribute(name) ?? "", element.closest("math") !== null);
|
|
109
|
+
const decision = decideHtmlAttribute(tag, name, element.getAttribute(name) ?? "", allowMathml && element.closest("math") !== null);
|
|
117
110
|
if (!decision) continue;
|
|
118
111
|
if ("value" in decision) {
|
|
119
112
|
element.setAttribute(name, decision.value);
|
|
@@ -125,39 +118,39 @@ const sanitizeHtmlDom = (root, report, options) => {
|
|
|
125
118
|
}
|
|
126
119
|
return removedSource;
|
|
127
120
|
};
|
|
128
|
-
const sanitizeChildren = (parent) => {
|
|
121
|
+
const sanitizeChildren = (parent, allowMathml) => {
|
|
129
122
|
for (const element of Array.from(parent.childNodes)) {
|
|
130
123
|
if (!isHtmlElement(element)) continue;
|
|
131
124
|
const tag = element.tagName.toLowerCase();
|
|
132
|
-
const removal = decideHtmlElement(element.namespaceURI, tag, () => isAriaHidden(element), mathmlPlace(element, tag));
|
|
125
|
+
const removal = decideHtmlElement(element.namespaceURI, tag, () => isAriaHidden(element), mathmlPlace(element, tag, allowMathml));
|
|
133
126
|
if (removal) {
|
|
134
127
|
report(element, removal);
|
|
135
128
|
element.remove();
|
|
136
129
|
continue;
|
|
137
130
|
}
|
|
138
|
-
if (sanitizeAttributes(element, tag) && tag === "img") {
|
|
131
|
+
if (sanitizeAttributes(element, tag, allowMathml) && tag === "img") {
|
|
139
132
|
const alt = element.getAttribute("alt");
|
|
140
133
|
if (alt) element.replaceWith(element.ownerDocument.createTextNode(alt));
|
|
141
134
|
else element.remove();
|
|
142
135
|
continue;
|
|
143
136
|
}
|
|
144
|
-
sanitizeContent(element, tag);
|
|
137
|
+
sanitizeContent(element, tag, allowMathml);
|
|
145
138
|
}
|
|
146
139
|
};
|
|
147
|
-
const sanitizeContent = (element, tag) => {
|
|
148
|
-
sanitizeChildren(element);
|
|
149
|
-
if (tag === "template" && "content" in element) sanitizeChildren(element.content);
|
|
140
|
+
const sanitizeContent = (element, tag, allowMathml) => {
|
|
141
|
+
sanitizeChildren(element, allowMathml);
|
|
142
|
+
if (tag === "template" && "content" in element) sanitizeChildren(element.content, false);
|
|
150
143
|
};
|
|
151
144
|
const tag = root.tagName.toLowerCase();
|
|
152
|
-
const removal = decideHtmlElement(root.namespaceURI, tag, () => isAriaHidden(root), mathmlPlace(root, tag));
|
|
145
|
+
const removal = decideHtmlElement(root.namespaceURI, tag, () => isAriaHidden(root), mathmlPlace(root, tag, admitsMathml));
|
|
153
146
|
if (removal) {
|
|
154
147
|
report(root, removal);
|
|
155
148
|
root.replaceChildren();
|
|
156
149
|
for (const name of root.getAttributeNames()) root.removeAttribute(name);
|
|
157
150
|
return;
|
|
158
151
|
}
|
|
159
|
-
sanitizeAttributes(root, tag);
|
|
160
|
-
sanitizeContent(root, tag);
|
|
152
|
+
sanitizeAttributes(root, tag, admitsMathml);
|
|
153
|
+
sanitizeContent(root, tag, admitsMathml);
|
|
161
154
|
};
|
|
162
155
|
//#endregion
|
|
163
|
-
export { HTML_UNSAFE_TAGS, decideHtmlAttribute, decideHtmlElement,
|
|
156
|
+
export { HTML_UNSAFE_TAGS, decideHtmlAttribute, decideHtmlElement, sanitizeHtmlDom };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ElementApi, TextApi, getCompiledEditorSchemaFromApi, readNamedRootChildren, reportEditorLifecycleError } from "../../../facade.js";
|
|
2
2
|
import { failInvariant } from "../../../internal/failInvariant.js";
|
|
3
3
|
import { createContentFormatDocument, createPluginFormatModelView } from "../../../internal/plugin/pluginFormatOperation.js";
|
|
4
|
+
import { isSafeStyleAttribute, isSafeStyleValue } from "./cssSafety.internal.js";
|
|
4
5
|
import { HTML_UNSAFE_TAGS, decideHtmlAttribute } from "./htmlSafety.js";
|
|
5
|
-
import { HTML_ATTRIBUTE_RE, normalizeStyleName } from "./htmlMatcher.internal.js";
|
|
6
|
-
import { HTML_CONTENT_TOKEN, HTML_FORMAT, HTML_NODE_FIELDS, HTML_PATCH_FIELDS, HTML_STYLE_NAME_RE, HTML_TAG_RE, HTML_VOID_TAGS, HTML_WRAPPER_FIELDS,
|
|
6
|
+
import { HTML_ATTRIBUTE_RE, isRecord, normalizeStyleName } from "./htmlMatcher.internal.js";
|
|
7
|
+
import { HTML_CONTENT_TOKEN, HTML_FORMAT, HTML_NODE_FIELDS, HTML_PATCH_FIELDS, HTML_STYLE_NAME_RE, HTML_TAG_RE, HTML_VOID_TAGS, HTML_WRAPPER_FIELDS, normalizeAttributeName, ruleClaimKeys } from "./htmlRules.internal.js";
|
|
7
8
|
import isEqual from "lodash/isEqual.js";
|
|
8
9
|
//#region src/lib/plugins/html/htmlSerialize.internal.ts
|
|
9
10
|
var ReportedHtmlEncodeError = class extends Error {
|
|
@@ -45,6 +46,19 @@ const compileWrites = (value, label, tag, onUnsafe) => {
|
|
|
45
46
|
const name = normalizeAttributeName(rawName);
|
|
46
47
|
if (!HTML_ATTRIBUTE_RE.test(name) || name.startsWith("on") || name === "srcdoc") throw new Error(`${label} has unsafe attribute "${rawName}".`);
|
|
47
48
|
const normalized = normalizeHtmlValue(rawValue, `${label} attribute "${name}"`);
|
|
49
|
+
if (name === "style" && typeof normalized === "string") {
|
|
50
|
+
if (!isSafeStyleAttribute(normalized)) {
|
|
51
|
+
onUnsafe(Object.freeze({
|
|
52
|
+
action: "removed",
|
|
53
|
+
impact: "lossy",
|
|
54
|
+
kind: "style",
|
|
55
|
+
message: `Removed unsafe HTML attribute "${rawName}" from <${tag}>.`
|
|
56
|
+
}));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
setWrite(attributeWrites, name, normalized, "attribute");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
48
62
|
const decision = typeof normalized === "string" ? decideHtmlAttribute(tag, name, normalized) : void 0;
|
|
49
63
|
if (decision && "removal" in decision) {
|
|
50
64
|
onUnsafe(decision.removal);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_TEXT_PARSE_LIMITS } from "../../../internal/plugin/conversionLaws.js";
|
|
2
|
-
import {
|
|
3
|
-
import { isResourceBearingCss } from "./
|
|
2
|
+
import { decodeCssEscapeAt, isCssWhitespaceChar, parseCssDeclaration, skipBalancedCssBlock, skipQuotedCssString, splitCssDeclarations, splitCssTopLevel, stepCssEscape, stripCssComments } from "./cssLexer.internal.js";
|
|
3
|
+
import { isResourceBearingCss } from "./cssSafety.internal.js";
|
|
4
4
|
import { defaultTreeAdapter, html } from "parse5";
|
|
5
5
|
//#region src/lib/plugins/html/htmlStyleInline.internal.ts
|
|
6
6
|
const HTML_NAMESPACE = html.NS.HTML;
|
|
@@ -34,20 +34,12 @@ const parseDeclarations = (block, filterUnsafe) => {
|
|
|
34
34
|
});
|
|
35
35
|
const declarations = [];
|
|
36
36
|
for (const part of parts) {
|
|
37
|
-
const
|
|
38
|
-
if (!trimmed) continue;
|
|
39
|
-
const colonIndex = findTopLevelCssColon(trimmed);
|
|
40
|
-
if (colonIndex <= 0) continue;
|
|
41
|
-
const property = normalizeCssPropertyName(trimmed.slice(0, colonIndex));
|
|
42
|
-
if (!property) continue;
|
|
43
|
-
const rawValue = trimmed.slice(colonIndex + 1).trim();
|
|
44
|
-
if (!rawValue || hasUnbalancedCssDelimiters(rawValue)) continue;
|
|
45
|
-
const parsed = parseCssDeclarationPriority(property, rawValue);
|
|
37
|
+
const parsed = parseCssDeclaration(part);
|
|
46
38
|
if (!parsed) continue;
|
|
47
39
|
if (filterUnsafe && isResourceBearingCss(parsed.value)) continue;
|
|
48
40
|
declarations.push({
|
|
49
41
|
important: parsed.important,
|
|
50
|
-
raw: `${property}: ${parsed.value}`
|
|
42
|
+
raw: `${parsed.property}: ${parsed.value}`
|
|
51
43
|
});
|
|
52
44
|
}
|
|
53
45
|
return declarations;
|
|
@@ -57,9 +49,11 @@ const readCssIdentifier = (selector, start) => {
|
|
|
57
49
|
let value = "";
|
|
58
50
|
while (i < selector.length) {
|
|
59
51
|
const ch = selector[i];
|
|
60
|
-
if (ch === "\\"
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
if (ch === "\\") {
|
|
53
|
+
const decoded = decodeCssEscapeAt(selector, i);
|
|
54
|
+
if (!decoded) break;
|
|
55
|
+
value += decoded.char;
|
|
56
|
+
i = decoded.end;
|
|
63
57
|
continue;
|
|
64
58
|
}
|
|
65
59
|
if (/^[A-Za-z0-9_-]$/.test(ch) || ch.charCodeAt(0) >= 128) {
|
|
@@ -104,9 +98,12 @@ const parseAttributeSelector = (selector, start) => {
|
|
|
104
98
|
const quote = selector[i];
|
|
105
99
|
i += 1;
|
|
106
100
|
while (i < selector.length && selector[i] !== quote) {
|
|
107
|
-
if (selector[i] === "\\"
|
|
108
|
-
|
|
109
|
-
|
|
101
|
+
if (selector[i] === "\\") {
|
|
102
|
+
const decoded = decodeCssEscapeAt(selector, i);
|
|
103
|
+
if (decoded) {
|
|
104
|
+
value += decoded.char;
|
|
105
|
+
i = decoded.end;
|
|
106
|
+
} else i = stepCssEscape(selector, i);
|
|
110
107
|
continue;
|
|
111
108
|
}
|
|
112
109
|
value += selector[i];
|
|
@@ -117,9 +114,11 @@ const parseAttributeSelector = (selector, start) => {
|
|
|
117
114
|
} else {
|
|
118
115
|
const valueStart = i;
|
|
119
116
|
while (i < selector.length && selector[i] !== "]" && !isCssWhitespaceChar(selector[i])) {
|
|
120
|
-
if (selector[i] === "\\"
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
if (selector[i] === "\\") {
|
|
118
|
+
const decoded = decodeCssEscapeAt(selector, i);
|
|
119
|
+
if (!decoded) return null;
|
|
120
|
+
value += decoded.char;
|
|
121
|
+
i = decoded.end;
|
|
123
122
|
continue;
|
|
124
123
|
}
|
|
125
124
|
value += selector[i];
|
|
@@ -266,7 +265,7 @@ const parseStyleBlockInto = (css, state, rules, mediaDepth) => {
|
|
|
266
265
|
continue;
|
|
267
266
|
}
|
|
268
267
|
if (ch === "\\") {
|
|
269
|
-
i
|
|
268
|
+
i = stepCssEscape(css, i);
|
|
270
269
|
continue;
|
|
271
270
|
}
|
|
272
271
|
if (ch === "(") parenDepth += 1;
|
|
@@ -298,7 +297,7 @@ const parseStyleBlockInto = (css, state, rules, mediaDepth) => {
|
|
|
298
297
|
continue;
|
|
299
298
|
}
|
|
300
299
|
if (ch === "\\") {
|
|
301
|
-
i
|
|
300
|
+
i = stepCssEscape(css, i);
|
|
302
301
|
continue;
|
|
303
302
|
}
|
|
304
303
|
if (ch === "(") parenDepth += 1;
|
|
@@ -35,6 +35,32 @@ const isInputRuleVetoed = (editor, state, options) => {
|
|
|
35
35
|
return false;
|
|
36
36
|
};
|
|
37
37
|
const leafHasVetoedMark = (leaf, vetoedMarks) => vetoedMarks.some((key) => Boolean(Reflect.get(leaf, key)));
|
|
38
|
+
const hasInputRuleVetoAt = (editor, state, range) => {
|
|
39
|
+
const { elements, marks } = getInputRuleVetos(editor);
|
|
40
|
+
if (elements.length === 0 && marks.length === 0) return false;
|
|
41
|
+
if (elements.length > 0 && state.nodes.some({
|
|
42
|
+
at: range,
|
|
43
|
+
type: elements
|
|
44
|
+
})) return true;
|
|
45
|
+
if (marks.length === 0) return false;
|
|
46
|
+
if (state.selection.isCollapsed()) {
|
|
47
|
+
const activeMarks = state.marks();
|
|
48
|
+
if (activeMarks && marks.some((key) => Boolean(activeMarks[key]))) return true;
|
|
49
|
+
}
|
|
50
|
+
const [start, end] = RangeApi.edges(range);
|
|
51
|
+
if (PointApi.equals(start, end)) return false;
|
|
52
|
+
for (const [leaf, path] of state.nodes.entries({
|
|
53
|
+
at: {
|
|
54
|
+
anchor: start,
|
|
55
|
+
focus: end
|
|
56
|
+
},
|
|
57
|
+
match: TextApi.isText
|
|
58
|
+
})) {
|
|
59
|
+
const sliceStart = PathApi.equals(path, start.path) ? start.offset : 0;
|
|
60
|
+
if ((PathApi.equals(path, end.path) ? end.offset : leaf.text.length) > sliceStart && leafHasVetoedMark(leaf, marks)) return true;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
};
|
|
38
64
|
const rangeHasVetoedMark = (readEditor, range) => {
|
|
39
65
|
const editor = resolveInputRuleEditor(readEditor);
|
|
40
66
|
if (!editor) return false;
|
|
@@ -115,4 +141,4 @@ const hasUnclosedLiteralMarkOpener = (context, currentStart) => {
|
|
|
115
141
|
return false;
|
|
116
142
|
};
|
|
117
143
|
//#endregion
|
|
118
|
-
export { getInputRuleVetos, hasUnclosedLiteralMarkOpener, isInputRuleVetoed, rangeHasVetoedMark, registerInputRuleReadEditor, resolveInputRuleEditor };
|
|
144
|
+
export { getInputRuleVetos, hasInputRuleVetoAt, hasUnclosedLiteralMarkOpener, isInputRuleVetoed, rangeHasVetoedMark, registerInputRuleReadEditor, resolveInputRuleEditor };
|