@opencode-ai/ui 0.0.0-dev-18672 → 0.0.0-dev-18677
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.
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function createMarkdownParser(highlight: (code: string, language: string) => string | Promise<string>): Marked<string, string>;
|
|
1
|
+
export declare function createMarkdownParser(highlight: (code: string, language: string) => string | Promise<string>): import("marked").Marked<string, string>;
|
package/package.json
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Marked } from "marked"
|
|
2
|
+
|
|
3
|
+
export function createMarkdownBase() {
|
|
4
|
+
return new Marked({
|
|
5
|
+
renderer: {
|
|
6
|
+
link({ href, title, text }) {
|
|
7
|
+
const titleAttr = title ? ` title="${title}"` : ""
|
|
8
|
+
return `<a href="${href}"${titleAttr} class="external-link" target="_blank" rel="noopener noreferrer">${text}</a>`
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let smallParser: Marked | undefined
|
|
15
|
+
|
|
16
|
+
export function parseSmallMarkdown(text: string) {
|
|
17
|
+
// Any possible KaTeX delimiter stays on the worker, including escaped ones.
|
|
18
|
+
if (text.length > 1024 || text.includes("\\(") || text.includes("$$")) return
|
|
19
|
+
const parser = (smallParser ??= createMarkdownBase())
|
|
20
|
+
const tokens = parser.lexer(text)
|
|
21
|
+
let code = false
|
|
22
|
+
parser.walkTokens(tokens, (token) => {
|
|
23
|
+
if (token.type === "code") code = true
|
|
24
|
+
})
|
|
25
|
+
if (code) return
|
|
26
|
+
return parser.parser(tokens)
|
|
27
|
+
}
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import katex from "katex"
|
|
2
|
-
import {
|
|
2
|
+
import type { MarkedExtension, Tokens } from "marked"
|
|
3
3
|
import markedShiki from "marked-shiki"
|
|
4
|
+
import { createMarkdownBase } from "./marked-base"
|
|
4
5
|
|
|
5
6
|
export function createMarkdownParser(highlight: (code: string, language: string) => string | Promise<string>) {
|
|
6
|
-
return
|
|
7
|
-
{
|
|
8
|
-
renderer: {
|
|
9
|
-
link({ href, title, text }) {
|
|
10
|
-
const titleAttr = title ? ` title="${title}"` : ""
|
|
11
|
-
return `<a href="${href}"${titleAttr} class="external-link" target="_blank" rel="noopener noreferrer">${text}</a>`
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
katexExtension,
|
|
16
|
-
markedShiki({ highlight }),
|
|
17
|
-
)
|
|
7
|
+
return createMarkdownBase().use(katexExtension, markedShiki({ highlight }))
|
|
18
8
|
}
|
|
19
9
|
|
|
20
10
|
const inlineMathRegex = /^\\\(((?:\\.|[^\\\n])*?)\\\)/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Content, Portal, Root, Trigger } from "@kobalte/core/tooltip"
|
|
2
|
-
import { createEffect, Match, onCleanup, splitProps, Switch, type JSX } from "solid-js"
|
|
2
|
+
import { createEffect, Match, onCleanup, splitProps, Switch, untrack, type JSX } from "solid-js"
|
|
3
3
|
import type { ComponentProps } from "solid-js"
|
|
4
4
|
import { createStore } from "solid-js/store"
|
|
5
5
|
import "./tooltip.css"
|
|
@@ -45,7 +45,7 @@ export function Tooltip(props: TooltipProps) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
const drop = (expand = state.expand) => {
|
|
48
|
-
if (expand) return
|
|
48
|
+
if (expand || !state.block) return
|
|
49
49
|
if (ref?.matches(":hover")) return
|
|
50
50
|
if (inside()) return
|
|
51
51
|
setState("block", false)
|
|
@@ -74,7 +74,7 @@ export function Tooltip(props: TooltipProps) {
|
|
|
74
74
|
|
|
75
75
|
createEffect(() => {
|
|
76
76
|
if (!ref) return
|
|
77
|
-
sync
|
|
77
|
+
untrack(sync)
|
|
78
78
|
const obs = new MutationObserver(sync)
|
|
79
79
|
obs.observe(ref, {
|
|
80
80
|
subtree: true,
|