x-star-editor 0.3.7 → 0.3.9
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/utils/markdown.d.ts +1 -2
- package/dist/utils/markdown.js +32 -22
- package/dist/utils/rehype/rehype-line.js +2 -2
- package/dist/utils/rehype/rehype-math.js +2 -2
- package/dist/utils/rehype/rehype-raw-positions.js +3 -3
- package/dist/x-star-md-editor/index.js +1 -6
- package/dist/x-star-md-viewer/index.js +13 -5
- package/package.json +1 -1
package/dist/utils/markdown.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { Root as HastRoot } from 'hast';
|
|
3
2
|
import { defaultSchema } from 'rehype-sanitize';
|
|
4
3
|
import type { ViewerOptions } from '../x-star-md-viewer';
|
|
@@ -36,7 +35,7 @@ export declare const viewerRender: (root: HastRoot, schema: Schema) => HastRoot;
|
|
|
36
35
|
* @param options 配置项
|
|
37
36
|
* @returns React 虚拟 DOM 树
|
|
38
37
|
*/
|
|
39
|
-
export declare const postViewerRender: (root: HastRoot, options: ViewerOptions) =>
|
|
38
|
+
export declare const postViewerRender: (root: HastRoot, options: ViewerOptions) => any;
|
|
40
39
|
/**
|
|
41
40
|
* 将 Markdown 文本转成 HTML 文本
|
|
42
41
|
*
|
package/dist/utils/markdown.js
CHANGED
|
@@ -190,10 +190,10 @@ export var editorRender = function editorRender(sourceCode) {
|
|
|
190
190
|
_step;
|
|
191
191
|
try {
|
|
192
192
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
193
|
-
var _node$position, _node$position2;
|
|
193
|
+
var _node$position, _node$position$start, _node$position2, _node$position2$end;
|
|
194
194
|
var node = _step.value;
|
|
195
|
-
var startOffset = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : _node$position.start.offset;
|
|
196
|
-
var endOffset = (_node$position2 = node.position) === null || _node$position2 === void 0 ? void 0 : _node$position2.end.offset;
|
|
195
|
+
var startOffset = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : (_node$position$start = _node$position.start) === null || _node$position$start === void 0 ? void 0 : _node$position$start.offset;
|
|
196
|
+
var endOffset = (_node$position2 = node.position) === null || _node$position2 === void 0 ? void 0 : (_node$position2$end = _node$position2.end) === null || _node$position2$end === void 0 ? void 0 : _node$position2$end.offset;
|
|
197
197
|
if (startOffset === undefined || endOffset === undefined) {
|
|
198
198
|
continue;
|
|
199
199
|
}
|
|
@@ -223,12 +223,12 @@ export var editorRender = function editorRender(sourceCode) {
|
|
|
223
223
|
if (stack.length > 1) {
|
|
224
224
|
pushElement(stack.length - 1);
|
|
225
225
|
} else {
|
|
226
|
-
var _node$position3;
|
|
226
|
+
var _node$position3, _node$position3$start;
|
|
227
227
|
// 如果栈大小为 1,说明为块级元素终点
|
|
228
228
|
stack[0].element.append("\u200B");
|
|
229
229
|
pushElement(0);
|
|
230
230
|
// 记录行号,用于同步滚动
|
|
231
|
-
block.dataset.line = "".concat((_node$position3 = node.position) === null || _node$position3 === void 0 ? void 0 : _node$position3.start.line);
|
|
231
|
+
block.dataset.line = "".concat((_node$position3 = node.position) === null || _node$position3 === void 0 ? void 0 : (_node$position3$start = _node$position3.start) === null || _node$position3$start === void 0 ? void 0 : _node$position3$start.line);
|
|
232
232
|
pushBlock();
|
|
233
233
|
scanOffset++;
|
|
234
234
|
}
|
|
@@ -341,23 +341,33 @@ export var viewerRender = function viewerRender(root, schema) {
|
|
|
341
341
|
* @returns React 虚拟 DOM 树
|
|
342
342
|
*/
|
|
343
343
|
export var postViewerRender = function postViewerRender(root, options) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
344
|
+
try {
|
|
345
|
+
var components = _objectSpread(_objectSpread({}, options.customHTMLElements), {}, {
|
|
346
|
+
input: function input(props) {
|
|
347
|
+
return jsx('input', props);
|
|
348
|
+
},
|
|
349
|
+
custom: function custom(props) {
|
|
350
|
+
var _options$customBlocks;
|
|
351
|
+
return jsx((_options$customBlocks = options.customBlocks[props.meta]) !== null && _options$customBlocks !== void 0 ? _options$customBlocks : 'div', {
|
|
352
|
+
children: props.value
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
return toJsxRuntime(unified().use(rehypeKatex).runSync(root), {
|
|
357
|
+
Fragment: Fragment,
|
|
358
|
+
jsx: jsx,
|
|
359
|
+
jsxs: jsxs,
|
|
360
|
+
components: components
|
|
361
|
+
});
|
|
362
|
+
} catch (_unused) {
|
|
363
|
+
return jsx('div', {
|
|
364
|
+
style: {
|
|
365
|
+
fontStyle: 'italic',
|
|
366
|
+
color: 'red'
|
|
367
|
+
},
|
|
368
|
+
children: 'Parse error!'
|
|
369
|
+
});
|
|
370
|
+
}
|
|
361
371
|
};
|
|
362
372
|
var toHTMLProcessor = unified().use(remarkParse).use(remarkGfm).use(remarkMath).use(remarkRehype, {
|
|
363
373
|
allowDangerousHtml: true,
|
|
@@ -6,10 +6,10 @@ import { SKIP, visit } from 'unist-util-visit';
|
|
|
6
6
|
var rehypeLine = function rehypeLine() {
|
|
7
7
|
return function (root) {
|
|
8
8
|
return visit(root, 'element', function (node) {
|
|
9
|
-
var _node$properties, _node$position;
|
|
9
|
+
var _node$properties, _node$position, _node$position$start;
|
|
10
10
|
(_node$properties = node.properties) !== null && _node$properties !== void 0 ? _node$properties : node.properties = {};
|
|
11
11
|
// 记录行号,用于同步滚动
|
|
12
|
-
node.properties['data-line'] = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : _node$position.start.line;
|
|
12
|
+
node.properties['data-line'] = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : (_node$position$start = _node$position.start) === null || _node$position$start === void 0 ? void 0 : _node$position$start.line;
|
|
13
13
|
return SKIP;
|
|
14
14
|
});
|
|
15
15
|
};
|
|
@@ -156,8 +156,8 @@ var rehypeMath = function rehypeMath() {
|
|
|
156
156
|
return SKIP;
|
|
157
157
|
}
|
|
158
158
|
if (node.type === 'text' && index !== null && parent) {
|
|
159
|
-
var _node$position;
|
|
160
|
-
var startOffset = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : _node$position.start.offset;
|
|
159
|
+
var _node$position, _node$position$start;
|
|
160
|
+
var startOffset = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : (_node$position$start = _node$position.start) === null || _node$position$start === void 0 ? void 0 : _node$position$start.offset;
|
|
161
161
|
if (startOffset === undefined) {
|
|
162
162
|
return;
|
|
163
163
|
}
|
|
@@ -7,9 +7,9 @@ var rehypeRawPositions = function rehypeRawPositions() {
|
|
|
7
7
|
return function (root) {
|
|
8
8
|
var rawPositions = [];
|
|
9
9
|
visit(root, 'raw', function (node) {
|
|
10
|
-
var _node$position, _node$position2;
|
|
11
|
-
var startOffset = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : _node$position.start.offset;
|
|
12
|
-
var endOffset = (_node$position2 = node.position) === null || _node$position2 === void 0 ? void 0 : _node$position2.end.offset;
|
|
10
|
+
var _node$position, _node$position$start, _node$position2, _node$position2$end;
|
|
11
|
+
var startOffset = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : (_node$position$start = _node$position.start) === null || _node$position$start === void 0 ? void 0 : _node$position$start.offset;
|
|
12
|
+
var endOffset = (_node$position2 = node.position) === null || _node$position2 === void 0 ? void 0 : (_node$position2$end = _node$position2.end) === null || _node$position2$end === void 0 ? void 0 : _node$position2$end.offset;
|
|
13
13
|
if (startOffset === undefined || endOffset === undefined) {
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
@@ -125,11 +125,6 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
125
125
|
});
|
|
126
126
|
break;
|
|
127
127
|
}
|
|
128
|
-
case 'compositionstart':
|
|
129
|
-
{
|
|
130
|
-
container.normalizeSelection();
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
128
|
}
|
|
134
129
|
};
|
|
135
130
|
var dragEventHandler = function dragEventHandler(e) {
|
|
@@ -176,6 +171,7 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
176
171
|
{
|
|
177
172
|
// 组合时不触发快捷键
|
|
178
173
|
if (!e.nativeEvent.isComposing) {
|
|
174
|
+
container.normalizeSelection();
|
|
179
175
|
composeHandlers(options.keyboardEventHandlers)({
|
|
180
176
|
history: history,
|
|
181
177
|
sourceCode: sourceCode,
|
|
@@ -377,7 +373,6 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
377
373
|
contentEditable: true,
|
|
378
374
|
onBlur: focusEventHandler,
|
|
379
375
|
onCompositionEnd: compositionEventHandler,
|
|
380
|
-
onCompositionStart: compositionEventHandler,
|
|
381
376
|
onCopy: clipboardEventHandler,
|
|
382
377
|
onCut: clipboardEventHandler,
|
|
383
378
|
onDragStart: dragEventHandler,
|