@seafile/sdoc-editor 3.0.234 → 3.0.236
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/extension/plugins/html/helper.js +11 -8
- package/dist/extension/plugins/html/plugin.js +1 -2
- package/dist/extension/plugins/html/rules/code-block.js +11 -2
- package/dist/extension/plugins/html/rules/list.js +21 -0
- package/dist/slate-convert/html-to-slate/rules/code-block.js +11 -2
- package/dist/slate-convert/html-to-slate/rules/list.js +21 -0
- package/package.json +2 -2
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.deserializePastedHtml = exports.deserializeHtml = void 0;
|
|
8
8
|
var _slugid = _interopRequireDefault(require("slugid"));
|
|
9
9
|
var _typeOf = _interopRequireDefault(require("type-of"));
|
|
10
10
|
var _constants = require("../../constants");
|
|
@@ -122,13 +122,7 @@ var parseHtml = function parseHtml(html) {
|
|
|
122
122
|
var body = parsed.body;
|
|
123
123
|
return body;
|
|
124
124
|
};
|
|
125
|
-
var
|
|
126
|
-
var fragment = parseHtml(html);
|
|
127
|
-
(0, _wechatPasteNormalizer.normalizeWechatPastedFragment)(fragment);
|
|
128
|
-
return fragment.innerHTML;
|
|
129
|
-
};
|
|
130
|
-
var deserializeHtml = exports.deserializeHtml = function deserializeHtml(html) {
|
|
131
|
-
var fragment = parseHtml(html);
|
|
125
|
+
var deserializeFragment = function deserializeFragment(fragment) {
|
|
132
126
|
var children = Array.from(fragment.childNodes);
|
|
133
127
|
var nodes = [];
|
|
134
128
|
nodes = deserializeElements(children, true);
|
|
@@ -144,4 +138,13 @@ var deserializeHtml = exports.deserializeHtml = function deserializeHtml(html) {
|
|
|
144
138
|
}];
|
|
145
139
|
}
|
|
146
140
|
return nodes;
|
|
141
|
+
};
|
|
142
|
+
var deserializeHtml = exports.deserializeHtml = function deserializeHtml(html) {
|
|
143
|
+
return deserializeFragment(parseHtml(html));
|
|
144
|
+
};
|
|
145
|
+
var deserializePastedHtml = exports.deserializePastedHtml = function deserializePastedHtml(html) {
|
|
146
|
+
var fragment = parseHtml(html);
|
|
147
|
+
// Normalize WeChat-specific DOM before applying the generic HTML-to-Slate rules.
|
|
148
|
+
(0, _wechatPasteNormalizer.normalizeWechatPastedFragment)(fragment);
|
|
149
|
+
return deserializeFragment(fragment);
|
|
147
150
|
};
|
|
@@ -37,8 +37,7 @@ var withHtml = function withHtml(editor) {
|
|
|
37
37
|
}
|
|
38
38
|
var htmlContent = data.getData('text/html') || '';
|
|
39
39
|
if (htmlContent) {
|
|
40
|
-
var
|
|
41
|
-
var content = (0, _helper.deserializeHtml)(normalizedHtmlContent);
|
|
40
|
+
var content = (0, _helper.deserializePastedHtml)(htmlContent);
|
|
42
41
|
_localStorageUtils["default"].setItem(_constants.RECENT_COPY_CONTENT, htmlContent);
|
|
43
42
|
editor.insertFragment(content);
|
|
44
43
|
return;
|
|
@@ -16,7 +16,7 @@ var normalizeCodeText = function normalizeCodeText() {
|
|
|
16
16
|
};
|
|
17
17
|
var isFormattingWhitespace = function isFormattingWhitespace() {
|
|
18
18
|
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
19
|
-
return text !== '' && text.trim() === '';
|
|
19
|
+
return text !== '' && !text.includes("\xA0") && text.trim() === '';
|
|
20
20
|
};
|
|
21
21
|
var appendTextToLines = function appendTextToLines(lines) {
|
|
22
22
|
var text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
@@ -90,11 +90,20 @@ var buildCodeLines = function buildCodeLines(element) {
|
|
|
90
90
|
};
|
|
91
91
|
});
|
|
92
92
|
};
|
|
93
|
+
var buildWechatMultiLineCodeLines = function buildWechatMultiLineCodeLines(element) {
|
|
94
|
+
var codeChildren = Array.from(element.children);
|
|
95
|
+
var isWechatMultiLineCodeBlock = element.classList.contains('code-snippet__js') && codeChildren.length > 1 && codeChildren.every(function (child) {
|
|
96
|
+
return child.nodeName === 'CODE';
|
|
97
|
+
});
|
|
98
|
+
return isWechatMultiLineCodeBlock ? codeChildren.flatMap(buildCodeLines) : null;
|
|
99
|
+
};
|
|
93
100
|
var codeBlockRule = function codeBlockRule(element, parseChild) {
|
|
94
101
|
var nodeName = element.nodeName,
|
|
95
102
|
childNodes = element.childNodes;
|
|
96
103
|
if (nodeName === 'PRE') {
|
|
97
104
|
var codeChild = element.querySelector('code');
|
|
105
|
+
// Process WeChat multi-line code blocks based on their multiple direct <code> children.
|
|
106
|
+
var wechatMultiLineCodeLines = buildWechatMultiLineCodeLines(element);
|
|
98
107
|
var lang = codeChild === null || codeChild === void 0 ? void 0 : codeChild.getAttribute('lang');
|
|
99
108
|
lang = (0, _prismjs.genCodeLangs)().find(function (item) {
|
|
100
109
|
return item.value === lang;
|
|
@@ -103,7 +112,7 @@ var codeBlockRule = function codeBlockRule(element, parseChild) {
|
|
|
103
112
|
id: _slugid["default"].nice(),
|
|
104
113
|
language: lang,
|
|
105
114
|
type: _constants.CODE_BLOCK,
|
|
106
|
-
children: buildCodeLines(codeChild || element)
|
|
115
|
+
children: wechatMultiLineCodeLines !== null && wechatMultiLineCodeLines !== void 0 ? wechatMultiLineCodeLines : buildCodeLines(codeChild || element)
|
|
107
116
|
};
|
|
108
117
|
}
|
|
109
118
|
if (nodeName === 'CODE' && element.parentElement.nodeName === 'PRE') {
|
|
@@ -59,9 +59,30 @@ var normalizeListItemChildren = function normalizeListItemChildren() {
|
|
|
59
59
|
}
|
|
60
60
|
return nextChildren;
|
|
61
61
|
};
|
|
62
|
+
var isWechatCodeLineIndex = function isWechatCodeLineIndex(element) {
|
|
63
|
+
if (element.nodeName !== 'UL' || !element.classList.contains('code-snippet__line-index') || !element.classList.contains('code-snippet__js')) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
var snippet = element.parentElement;
|
|
67
|
+
var codeBlock = element.nextElementSibling;
|
|
68
|
+
|
|
69
|
+
// Match a complete WeChat code snippet when the clipboard preserves its outer <section> wrapper.
|
|
70
|
+
var isCompleteWechatSnippet = (snippet === null || snippet === void 0 ? void 0 : snippet.nodeName) === 'SECTION' && snippet.classList.contains('code-snippet__fix') && snippet.classList.contains('code-snippet__js');
|
|
71
|
+
|
|
72
|
+
// Match a standalone WeChat code snippet when the clipboard omits the outer wrapper.
|
|
73
|
+
var lineItems = Array.from(element.children);
|
|
74
|
+
var isStandaloneWechatSnippet = (snippet === null || snippet === void 0 ? void 0 : snippet.nodeName) === 'BODY' && lineItems.length > 0 && lineItems.every(function (item) {
|
|
75
|
+
return item.nodeName === 'LI' && item.children.length === 0 && item.textContent.trim() === '';
|
|
76
|
+
});
|
|
77
|
+
return (isCompleteWechatSnippet || isStandaloneWechatSnippet) && (codeBlock === null || codeBlock === void 0 ? void 0 : codeBlock.nodeName) === 'PRE' && codeBlock.classList.contains('code-snippet__js') && codeBlock.parentElement === snippet;
|
|
78
|
+
};
|
|
62
79
|
var listRule = function listRule(element, parseChild) {
|
|
63
80
|
var nodeName = element.nodeName,
|
|
64
81
|
childNodes = element.childNodes;
|
|
82
|
+
// Discard the line-index list from a recognized WeChat code snippet to avoid generating extra list items.
|
|
83
|
+
if (isWechatCodeLineIndex(element)) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
65
86
|
if (nodeName === 'UL') {
|
|
66
87
|
var validChildNodes = Array.from(childNodes).filter(function (item) {
|
|
67
88
|
return item.nodeName === 'LI';
|
|
@@ -16,7 +16,7 @@ var normalizeCodeText = function normalizeCodeText() {
|
|
|
16
16
|
};
|
|
17
17
|
var isFormattingWhitespace = function isFormattingWhitespace() {
|
|
18
18
|
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
19
|
-
return text !== '' && text.trim() === '';
|
|
19
|
+
return text !== '' && !text.includes("\xA0") && text.trim() === '';
|
|
20
20
|
};
|
|
21
21
|
var appendTextToLines = function appendTextToLines(lines) {
|
|
22
22
|
var text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
@@ -90,11 +90,20 @@ var buildCodeLines = function buildCodeLines(element) {
|
|
|
90
90
|
};
|
|
91
91
|
});
|
|
92
92
|
};
|
|
93
|
+
var buildWechatMultiLineCodeLines = function buildWechatMultiLineCodeLines(element) {
|
|
94
|
+
var codeChildren = Array.from(element.children);
|
|
95
|
+
var isWechatMultiLineCodeBlock = element.classList.contains('code-snippet__js') && codeChildren.length > 1 && codeChildren.every(function (child) {
|
|
96
|
+
return child.nodeName === 'CODE';
|
|
97
|
+
});
|
|
98
|
+
return isWechatMultiLineCodeBlock ? codeChildren.flatMap(buildCodeLines) : null;
|
|
99
|
+
};
|
|
93
100
|
var codeBlockRule = function codeBlockRule(element, parseChild) {
|
|
94
101
|
var nodeName = element.nodeName,
|
|
95
102
|
childNodes = element.childNodes;
|
|
96
103
|
if (nodeName === 'PRE') {
|
|
97
104
|
var codeChild = element.querySelector('code');
|
|
105
|
+
// Process WeChat multi-line code blocks based on their multiple direct <code> children.
|
|
106
|
+
var wechatMultiLineCodeLines = buildWechatMultiLineCodeLines(element);
|
|
98
107
|
var lang = codeChild === null || codeChild === void 0 ? void 0 : codeChild.getAttribute('lang');
|
|
99
108
|
lang = (0, _helper.genCodeLangs)().find(function (item) {
|
|
100
109
|
return item.value === lang;
|
|
@@ -103,7 +112,7 @@ var codeBlockRule = function codeBlockRule(element, parseChild) {
|
|
|
103
112
|
id: _slugid["default"].nice(),
|
|
104
113
|
language: lang,
|
|
105
114
|
type: _constants.CODE_BLOCK,
|
|
106
|
-
children: buildCodeLines(codeChild || element)
|
|
115
|
+
children: wechatMultiLineCodeLines !== null && wechatMultiLineCodeLines !== void 0 ? wechatMultiLineCodeLines : buildCodeLines(codeChild || element)
|
|
107
116
|
};
|
|
108
117
|
}
|
|
109
118
|
if (nodeName === 'CODE' && element.parentElement.nodeName === 'PRE') {
|
|
@@ -59,9 +59,30 @@ var normalizeListItemChildren = function normalizeListItemChildren() {
|
|
|
59
59
|
}
|
|
60
60
|
return nextChildren;
|
|
61
61
|
};
|
|
62
|
+
var isWechatCodeLineIndex = function isWechatCodeLineIndex(element) {
|
|
63
|
+
if (element.nodeName !== 'UL' || !element.classList.contains('code-snippet__line-index') || !element.classList.contains('code-snippet__js')) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
var snippet = element.parentElement;
|
|
67
|
+
var codeBlock = element.nextElementSibling;
|
|
68
|
+
|
|
69
|
+
// Match a complete WeChat code snippet when the clipboard preserves its outer <section> wrapper.
|
|
70
|
+
var isCompleteWechatSnippet = (snippet === null || snippet === void 0 ? void 0 : snippet.nodeName) === 'SECTION' && snippet.classList.contains('code-snippet__fix') && snippet.classList.contains('code-snippet__js');
|
|
71
|
+
|
|
72
|
+
// Match a standalone WeChat code snippet when the clipboard omits the outer wrapper.
|
|
73
|
+
var lineItems = Array.from(element.children);
|
|
74
|
+
var isStandaloneWechatSnippet = (snippet === null || snippet === void 0 ? void 0 : snippet.nodeName) === 'BODY' && lineItems.length > 0 && lineItems.every(function (item) {
|
|
75
|
+
return item.nodeName === 'LI' && item.children.length === 0 && item.textContent.trim() === '';
|
|
76
|
+
});
|
|
77
|
+
return (isCompleteWechatSnippet || isStandaloneWechatSnippet) && (codeBlock === null || codeBlock === void 0 ? void 0 : codeBlock.nodeName) === 'PRE' && codeBlock.classList.contains('code-snippet__js') && codeBlock.parentElement === snippet;
|
|
78
|
+
};
|
|
62
79
|
var listRule = function listRule(element, parseChild) {
|
|
63
80
|
var nodeName = element.nodeName,
|
|
64
81
|
childNodes = element.childNodes;
|
|
82
|
+
// Discard the line-index list from a recognized WeChat code snippet to avoid generating extra list items.
|
|
83
|
+
if (isWechatCodeLineIndex(element)) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
65
86
|
if (nodeName === 'UL') {
|
|
66
87
|
var validChildNodes = Array.from(childNodes).filter(function (item) {
|
|
67
88
|
return item.nodeName === 'LI';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seafile/sdoc-editor",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.236",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "73a28faf84d02af9d9bc6b7e533a076bed1aaf3f"
|
|
75
75
|
}
|