@humanspeak/svelte-markdown 1.4.2 → 1.4.3

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.
@@ -32,10 +32,15 @@ export interface MarkedKatexOptions {
32
32
  * | Delimiter pair | Level | `displayMode` |
33
33
  * |---|---|---|
34
34
  * | `\(...\)` | inline | `false` |
35
- * | `\[...\]` (own-line) | block | `true` |
36
- * | `$$...$$` (own-line) | block | `true` |
35
+ * | `\[...\]` (own-line **or** single-line) | block | `true` |
36
+ * | `$$...$$` (own-line **or** single-line) | block | `true` |
37
37
  * | `\begin{equation}...\end{equation}` and other AMS envs | block | `true` |
38
38
  *
39
+ * Both `\[x\]` and `\[\nx\n\]` parse as block math; same for `$$x$$` and the
40
+ * own-line `$$\nx\n$$` form. LLMs overwhelmingly emit the single-line form,
41
+ * so accepting both keeps the extension drop-in compatible with their output
42
+ * without losing the canonical own-line shape.
43
+ *
39
44
  * Supported AMS environments: `equation`, `align`, `alignat`, `gather`, `CD`,
40
45
  * plus their starred variants (e.g. `equation*`).
41
46
  *
@@ -8,14 +8,20 @@ const AMS_ENVIRONMENTS = ['equation', 'align', 'alignat', 'gather', 'CD'];
8
8
  // in a regex would mean "equatio + zero-or-more n", which silently fails to
9
9
  // match `\begin{equation*}`.
10
10
  const AMS_NAMES = AMS_ENVIRONMENTS.flatMap((n) => [n, `${n}\\*`]).join('|');
11
- const blockBracketRule = /^\\\[[ \t]*\n([\s\S]+?)\n[ \t]*\\\](?:\n|$)/;
12
- const blockDollarRule = /^\$\$[ \t]*\n([\s\S]+?)\n[ \t]*\$\$(?:\n|$)/;
11
+ // `\s*` (instead of `[ \t]*\n`) lets these rules match both the canonical
12
+ // own-line form (`$$\nx\n$$`) and the single-line form (`$$x$$`) that LLMs
13
+ // emit constantly. Without this, `$$x = \frac{...}{2a}$$` survives as
14
+ // paragraph text because the inline tokenizer also rejects `$$` openers.
15
+ const blockBracketRule = /^\\\[\s*([\s\S]+?)\s*\\\](?:\n|$)/;
16
+ const blockDollarRule = /^\$\$\s*([\s\S]+?)\s*\$\$(?:\n|$)/;
13
17
  const blockAmsRule = new RegExp(`^\\\\begin\\{(${AMS_NAMES})\\}[\\s\\S]+?\\\\end\\{\\1\\}(?:\\n|$)?`);
14
18
  const inlineParenRule = /^\\\(([\s\S]+?)\\\)/;
15
- // Mirrors the "standard" rule from upstream marked-katex-extension: requires a
16
- // whitespace, end-of-string, or punctuation boundary after the closing `$` so
17
- // strings like `$5,000` do not match.
18
- const inlineDollarRule = /^\$(?!\$)((?:\\.|[^\\\n$])+?)\$(?=[\s?!.,:?!。,:]|$)/;
19
+ // Mirrors the "standard" rule from upstream marked-katex-extension but
20
+ // extends the boundary class with `)`, `]`, `}` so expressions like
21
+ // `$0$)`, `$x$]`, `$x$}` (closing math right before a closing bracket)
22
+ // still match. Currency strings like `$5,000 across $42` remain unmatched
23
+ // because digits after the closing `$` aren't in any boundary class.
24
+ const inlineDollarRule = /^\$(?!\$)((?:\\.|[^\\\n$])+?)\$(?=[\s?!.,:)\]}?!。,:]|$)/;
19
25
  const earliestIndex = (src, needles) => {
20
26
  let best = -1;
21
27
  for (const needle of needles) {
@@ -34,10 +40,15 @@ const earliestIndex = (src, needles) => {
34
40
  * | Delimiter pair | Level | `displayMode` |
35
41
  * |---|---|---|
36
42
  * | `\(...\)` | inline | `false` |
37
- * | `\[...\]` (own-line) | block | `true` |
38
- * | `$$...$$` (own-line) | block | `true` |
43
+ * | `\[...\]` (own-line **or** single-line) | block | `true` |
44
+ * | `$$...$$` (own-line **or** single-line) | block | `true` |
39
45
  * | `\begin{equation}...\end{equation}` and other AMS envs | block | `true` |
40
46
  *
47
+ * Both `\[x\]` and `\[\nx\n\]` parse as block math; same for `$$x$$` and the
48
+ * own-line `$$\nx\n$$` form. LLMs overwhelmingly emit the single-line form,
49
+ * so accepting both keeps the extension drop-in compatible with their output
50
+ * without losing the canonical own-line shape.
51
+ *
41
52
  * Supported AMS environments: `equation`, `align`, `alignat`, `gather`, `CD`,
42
53
  * plus their starred variants (e.g. `equation*`).
43
54
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@humanspeak/svelte-markdown",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "Fast, customizable markdown renderer for Svelte with built-in caching, TypeScript support, and Svelte 5 runes",
5
5
  "keywords": [
6
6
  "svelte",