x-star-editor 0.6.1 → 0.6.2

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.
@@ -43,7 +43,7 @@ export declare const toHTML: (sourceCode: string) => string;
43
43
  * @returns Markdown 文本
44
44
  */
45
45
  export declare const toMarkdown: (sourceCode: string) => string;
46
- export interface ToTextOptions extends ToStringOptions {
46
+ interface ToTextOptions extends ToStringOptions {
47
47
  /**
48
48
  * 替换图片的 alt 文本
49
49
  */
@@ -56,3 +56,4 @@ export interface ToTextOptions extends ToStringOptions {
56
56
  * @returns 纯文本
57
57
  */
58
58
  export declare const toText: (sourceCode: string, options?: ToTextOptions) => string;
59
+ export {};
@@ -8,7 +8,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
8
  var _excluded = ["checked"];
9
9
  import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
10
10
  import { toText as hastToText } from 'hast-util-to-text';
11
- import { toString } from 'mdast-util-to-string';
11
+ import { toString as mdastToString } from 'mdast-util-to-string';
12
12
  import { Fragment, jsx, jsxs } from 'react/jsx-runtime';
13
13
  import rehypeKatex from 'rehype-katex';
14
14
  import rehypeMermaid from 'rehype-mermaidjs';
@@ -273,15 +273,28 @@ var toHastProcessor = unified().use(remarkBreaks).use(remarkRehype, {
273
273
  image: function image(h, node) {
274
274
  try {
275
275
  var _node$alt;
276
- var styles = (_node$alt = node.alt) === null || _node$alt === void 0 ? void 0 : _node$alt.split(' ');
276
+ var alts = [];
277
+ var styles = [];
278
+ (_node$alt = node.alt) === null || _node$alt === void 0 ? void 0 : _node$alt.split(' ').forEach(function (word) {
279
+ var s = word.split(':');
280
+ if (s.length !== 2) {
281
+ alts.push(word);
282
+ } else {
283
+ if (s[0] === 'w') {
284
+ s[0] = 'width';
285
+ } else if (s[0] === 'h') {
286
+ s[0] = 'height';
287
+ }
288
+ if ((s[0] === 'width' || s[0] === 'height') && /^\d+$/.test(s[1])) {
289
+ s[1] += 'px';
290
+ }
291
+ styles.push(s.join(':'));
292
+ }
293
+ });
277
294
  return h(node, 'img', {
278
295
  src: node.url,
279
- alt: styles === null || styles === void 0 ? void 0 : styles.filter(function (i) {
280
- return !i.includes(':');
281
- }).join(' '),
282
- style: styles === null || styles === void 0 ? void 0 : styles.filter(function (i) {
283
- return i.includes(':');
284
- }).join(';')
296
+ alt: alts.join(' '),
297
+ style: styles.join(';')
285
298
  });
286
299
  } catch (_unused) {
287
300
  return h(node, 'img', {
@@ -453,5 +466,5 @@ export var toText = function toText(sourceCode, options) {
453
466
  node.alt = options.replaceImageAlt;
454
467
  });
455
468
  }
456
- return toString(root, options);
469
+ return mdastToString(root, options);
457
470
  };
@@ -1,5 +1,5 @@
1
1
  // import _ from 'lodash';
2
- // import { CanvasData } from 'x-star-editor/x-star-slide-viewer';
2
+ // import { CanvasData } from '../../x-star-slide-viewer';
3
3
 
4
4
  // /**
5
5
  // *
@@ -104,17 +104,14 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
104
104
  return sourceCodeLatest.current;
105
105
  },
106
106
  setValue: function setValue(value) {
107
- return exec(function (_ref2) {
108
- var selection = _ref2.selection,
109
- dispatch = _ref2.dispatch;
110
- return dispatch({
111
- type: 'set',
112
- payload: {
113
- sourceCode: value,
114
- selection: selection
115
- },
107
+ var selection = getSelection();
108
+ dispatch({
109
+ type: 'set',
110
+ payload: {
111
+ sourceCode: value,
116
112
  selection: selection
117
- });
113
+ },
114
+ selection: selection
118
115
  });
119
116
  }
120
117
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ViewerOptions } from "../x-star-md-viewer/index.js";
2
+ import type { ViewerOptions } from '../x-star-md-viewer';
3
3
  export interface XStarSlideViewerPlugin {
4
4
  (ctx: ViewerOptions): void;
5
5
  }