@webc.site/math 0.1.3 → 0.1.4
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/README.md +6 -6
- package/mathml.d.ts +1 -0
- package/md.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,12 +31,12 @@ The world's smallest and fastest web Markdown formula renderer designed to parse
|
|
|
31
31
|
|
|
32
32
|
### JavaScript Example
|
|
33
33
|
|
|
34
|
-
#### 1. Replace Formulas in Markdown (using `@webc.site/math/md`)
|
|
34
|
+
#### 1. Replace Formulas in Markdown (using `@webc.site/math/md.js`)
|
|
35
35
|
|
|
36
36
|
Parses Markdown text, automatically identifying and replacing inline/block equations with MathML.
|
|
37
37
|
|
|
38
38
|
```javascript
|
|
39
|
-
import mdMath from "@webc.site/math/md";
|
|
39
|
+
import mdMath from "@webc.site/math/md.js";
|
|
40
40
|
|
|
41
41
|
const markdown = "Euler's identity: $$e^{i\\pi} + 1 = 0$$";
|
|
42
42
|
const html = mdMath(markdown);
|
|
@@ -210,7 +210,7 @@ Currently, the following LaTeX extensions, macro definitions, or custom styling
|
|
|
210
210
|
|
|
211
211
|
## Error Handling and Fault Tolerance
|
|
212
212
|
|
|
213
|
-
When parsing Markdown text using `@webc.site/math/md`, if a mathematical formula contains invalid LaTeX syntax (such as an unclosed `\left`), the parser automatically catches the compilation error internally and gracefully falls back to displaying the raw formula text (e.g., `$$x + \left( y$$`). This ensures that a single syntax error in a formula won't throw JavaScript exceptions or crash your application. Therefore, you **do not** need to wrap it in a `try...catch` block when calling this function.
|
|
213
|
+
When parsing Markdown text using `@webc.site/math/md.js`, if a mathematical formula contains invalid LaTeX syntax (such as an unclosed `\left`), the parser automatically catches the compilation error internally and gracefully falls back to displaying the raw formula text (e.g., `$$x + \left( y$$`). This ensures that a single syntax error in a formula won't throw JavaScript exceptions or crash your application. Therefore, you **do not** need to wrap it in a `try...catch` block when calling this function.
|
|
214
214
|
|
|
215
215
|
Note that calling `@webc.site/math` (the TeX compiler core) directly with invalid LaTeX syntax will throw an array containing an error code (see the internal error codes table below). If you are using the core TeX compiler directly, it is recommended to wrap the call in a `try...catch` block.
|
|
216
216
|
|
|
@@ -417,12 +417,12 @@ The `18s` project provides a optimized math font `m` (Latin Modern Math, derived
|
|
|
417
417
|
|
|
418
418
|
### JavaScript 示例
|
|
419
419
|
|
|
420
|
-
#### 1. 替换 Markdown 中的公式(使用 `@webc.site/math/md`)
|
|
420
|
+
#### 1. 替换 Markdown 中的公式(使用 `@webc.site/math/md.js`)
|
|
421
421
|
|
|
422
422
|
输入 Markdown 文本,自动识别其中的行内/块级公式并替换为 MathML。
|
|
423
423
|
|
|
424
424
|
```javascript
|
|
425
|
-
import mdMath from "@webc.site/math/md";
|
|
425
|
+
import mdMath from "@webc.site/math/md.js";
|
|
426
426
|
|
|
427
427
|
const markdown = "欧拉恒等式:$$e^{i\\pi} + 1 = 0$$";
|
|
428
428
|
const html = mdMath(markdown);
|
|
@@ -596,7 +596,7 @@ math {
|
|
|
596
596
|
|
|
597
597
|
## 错误处理与容错机制
|
|
598
598
|
|
|
599
|
-
在使用 `@webc.site/math/md` 解析 Markdown 文本时,如果数学公式中包含非法的 LaTeX 语法(例如未闭合的 `\left`),内部会自动捕获该语法错误,并优雅地退化为显示原始的公式文本(如 `$$x + \left( y$$`),而不会抛出 JavaScript 异常或导致网页/应用渲染崩溃。因此,调用该函数时**无需**使用 `try...catch` 块包裹。
|
|
599
|
+
在使用 `@webc.site/math/md.js` 解析 Markdown 文本时,如果数学公式中包含非法的 LaTeX 语法(例如未闭合的 `\left`),内部会自动捕获该语法错误,并优雅地退化为显示原始的公式文本(如 `$$x + \left( y$$`),而不会抛出 JavaScript 异常或导致网页/应用渲染崩溃。因此,调用该函数时**无需**使用 `try...catch` 块包裹。
|
|
600
600
|
|
|
601
601
|
但需要注意的是,如果直接使用 `@webc.site/math` 的默认导出(TeX 编译器核心)来渲染非法的 LaTeX 语法,它会抛出包含错误码的数组(详见下文错误码表)。因此,直接调用 TeX 编译器时建议使用 `try...catch` 进行包裹。
|
|
602
602
|
|
package/mathml.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function mathml(tex: string, block?: boolean): string;
|
package/md.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function mdMath(md: string): string;
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@webc.site/math","version":"0.1.
|
|
1
|
+
{"name":"@webc.site/math","version":"0.1.4","description":"The world's smallest and fastest web Markdown formula renderer / 全球最小最快的网页Markdown公式渲染器","keywords":["markdown","math","mathml","render","tex"],"homepage":"https://math.webc.site","license":"MulanPSL-2.0","author":"i18n.site@gmail.com","repository":{"type":"git","url":"git+https://github.com/webc-site/math.git"},"type":"module","exports":{".":{"types":"./mathml.d.ts","default":"./mathml.js"},"./md.js":{"types":"./md.d.ts","default":"./md.js"},"./*":"./*"},"dependencies":{}}
|