@opencode-ai/ui 0.0.0-dev-202607020425 → 0.0.0-dev-202607020509

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencode-ai/ui",
3
- "version": "0.0.0-dev-202607020425",
3
+ "version": "0.0.0-dev-202607020509",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,5 +1,4 @@
1
- import { marked } from "marked"
2
- import markedKatex from "marked-katex-extension"
1
+ import { marked, type MarkedExtension, type Tokens } from "marked"
3
2
  import markedShiki from "marked-shiki"
4
3
  import katex from "katex"
5
4
  import { bundledLanguages, type BundledLanguage } from "shiki"
@@ -395,8 +394,8 @@ function renderMathInText(text: string): string {
395
394
  }
396
395
  })
397
396
 
398
- // Inline math: $...$
399
- const inlineMathRegex = /(?<!\$)\$(?!\$)((?:[^$\\]|\\.)+?)\$(?!\$)/g
397
+ // Inline math: \(...\)
398
+ const inlineMathRegex = /\\\(((?:\\.|[^\\\n])*?)\\\)/g
400
399
  result = result.replace(inlineMathRegex, (_, math) => {
401
400
  try {
402
401
  return katex.renderToString(math, {
@@ -404,13 +403,63 @@ function renderMathInText(text: string): string {
404
403
  throwOnError: false,
405
404
  })
406
405
  } catch {
407
- return `$${math}$`
406
+ return `\\(${math}\\)`
408
407
  }
409
408
  })
410
409
 
411
410
  return result
412
411
  }
413
412
 
413
+ const inlineMathRegex = /^\\\(((?:\\.|[^\\\n])*?)\\\)/
414
+ const blockMathRegex = /^\$\$\n([\s\S]+?)\n\$\$(?:\n|$)/
415
+
416
+ const katexExtension: MarkedExtension = {
417
+ extensions: [
418
+ {
419
+ name: "inlineKatex",
420
+ level: "inline",
421
+ start(src) {
422
+ const index = src.indexOf("\\(")
423
+ if (index === -1) return
424
+ return index
425
+ },
426
+ tokenizer(src) {
427
+ const match = src.match(inlineMathRegex)
428
+ if (!match) return
429
+ return {
430
+ type: "inlineKatex",
431
+ raw: match[0],
432
+ text: match[1].trim(),
433
+ displayMode: false,
434
+ }
435
+ },
436
+ renderer: renderKatexToken,
437
+ },
438
+ {
439
+ name: "blockKatex",
440
+ level: "block",
441
+ tokenizer(src) {
442
+ const match = src.match(blockMathRegex)
443
+ if (!match) return
444
+ return {
445
+ type: "blockKatex",
446
+ raw: match[0],
447
+ text: match[1].trim(),
448
+ displayMode: true,
449
+ }
450
+ },
451
+ renderer: renderKatexToken,
452
+ },
453
+ ],
454
+ }
455
+
456
+ function renderKatexToken(token: Tokens.Generic) {
457
+ return katex.renderToString(typeof token.text === "string" ? token.text : "", {
458
+ displayMode: token.displayMode === true,
459
+ throwOnError: false,
460
+ })
461
+ }
462
+
414
463
  function renderMathExpressions(html: string): string {
415
464
  // Split on code/pre/kbd tags to avoid processing their contents
416
465
  const codeBlockPattern = /(<(?:pre|code|kbd)[^>]*>[\s\S]*?<\/(?:pre|code|kbd)>)/gi
@@ -480,10 +529,7 @@ export const { use: useMarked, provider: MarkedProvider } = createSimpleContext(
480
529
  },
481
530
  },
482
531
  },
483
- markedKatex({
484
- throwOnError: false,
485
- nonStandard: true,
486
- }),
532
+ katexExtension,
487
533
  markedShiki({
488
534
  async highlight(code, lang) {
489
535
  const highlighter = await getSharedHighlighter({