@lobehub/editor 4.0.0 → 4.0.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.
|
@@ -27,6 +27,7 @@ import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
|
|
|
27
27
|
import { createDebugLogger } from "../../../utils/debug";
|
|
28
28
|
import { registerMathCommand } from "../command";
|
|
29
29
|
import { $createMathBlockNode, $createMathInlineNode, MathBlockNode, MathInlineNode } from "../node";
|
|
30
|
+
import { isLikelyMathContent } from "../utils";
|
|
30
31
|
|
|
31
32
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
32
33
|
|
|
@@ -103,10 +104,11 @@ export var MathPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
103
104
|
var _this2 = this;
|
|
104
105
|
var markdownService = this.kernel.requireService(IMarkdownShortCutService);
|
|
105
106
|
markdownService === null || markdownService === void 0 || markdownService.registerMarkdownShortCut({
|
|
106
|
-
regExp: /\$([^$]
|
|
107
|
+
regExp: /\$([^\s$](?:[^$]*[^\s$])?)\$\s?$/,
|
|
107
108
|
replace: function replace(textNode, match) {
|
|
108
109
|
var _match = _slicedToArray(match, 2),
|
|
109
110
|
code = _match[1];
|
|
111
|
+
if (!isLikelyMathContent(code)) return;
|
|
110
112
|
var mathNode = $createMathInlineNode(code);
|
|
111
113
|
_this2.logger.debug('Math node inserted:', mathNode);
|
|
112
114
|
// textNode.replace(mathNode);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Heuristic: does the content between `$...$` look like a math formula?
|
|
3
|
+
*
|
|
4
|
+
* Positive signals (any one → math):
|
|
5
|
+
* - LaTeX commands \alpha \frac …
|
|
6
|
+
* - Structural chars ^ _ { } ( )
|
|
7
|
+
* - Operators / relations + - * / = < > | ! ,
|
|
8
|
+
* - Digits 0-9
|
|
9
|
+
* - Single ASCII letter x y n (common math variable)
|
|
10
|
+
*
|
|
11
|
+
* Everything else (multi-char words, CJK, spaced plain text) → not math.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isLikelyMathContent(content: string): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Heuristic: does the content between `$...$` look like a math formula?
|
|
3
|
+
*
|
|
4
|
+
* Positive signals (any one → math):
|
|
5
|
+
* - LaTeX commands \alpha \frac …
|
|
6
|
+
* - Structural chars ^ _ { } ( )
|
|
7
|
+
* - Operators / relations + - * / = < > | ! ,
|
|
8
|
+
* - Digits 0-9
|
|
9
|
+
* - Single ASCII letter x y n (common math variable)
|
|
10
|
+
*
|
|
11
|
+
* Everything else (multi-char words, CJK, spaced plain text) → not math.
|
|
12
|
+
*/
|
|
13
|
+
export function isLikelyMathContent(content) {
|
|
14
|
+
var trimmed = content.trim();
|
|
15
|
+
if (!trimmed) return false;
|
|
16
|
+
|
|
17
|
+
// LaTeX commands
|
|
18
|
+
if (/\\[A-Za-z]/.test(trimmed)) return true;
|
|
19
|
+
|
|
20
|
+
// Math structural chars, operators, or digits
|
|
21
|
+
if (/[\d!()*+,/<=>^_{|}-]/.test(trimmed)) return true;
|
|
22
|
+
|
|
23
|
+
// Single ASCII letter → likely a variable (x, y, n, …)
|
|
24
|
+
if (/^[A-Za-z]$/.test(trimmed)) return true;
|
|
25
|
+
return false;
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/editor",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lobehub",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"use-merge-value": "^1.2.0"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
|
-
"@lobehub/ui": "^
|
|
97
|
+
"@lobehub/ui": "^5.0.0",
|
|
98
98
|
"antd": "^6.1.1",
|
|
99
99
|
"motion": "^12.0.0",
|
|
100
100
|
"react": "^19.0.0",
|