summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/components
diff options
context:
space:
mode:
authorDavid Hill <[email protected]>2025-09-23 18:36:27 +0100
committerDavid Hill <[email protected]>2025-09-23 18:36:27 +0100
commit9d53628e192065cd20f5fbae3712dae43b92b1e3 (patch)
tree14e7ac5201c56d011932f1c54a33b975c9cd6e47 /packages/app/src/components
parent869b4761455672535eba878aa90edf21ab6fecec (diff)
parent5ead6d7dd50e96c3cd6213c9be540c1ca8ac2fe5 (diff)
downloadopencode-9d53628e192065cd20f5fbae3712dae43b92b1e3.tar.gz
opencode-9d53628e192065cd20f5fbae3712dae43b92b1e3.zip
Merge branch 'dev' of https://github.com/sst/opencode into dev
Diffstat (limited to 'packages/app/src/components')
-rw-r--r--packages/app/src/components/code.tsx1263
-rw-r--r--packages/app/src/components/markdown.tsx583
2 files changed, 349 insertions, 1497 deletions
diff --git a/packages/app/src/components/code.tsx b/packages/app/src/components/code.tsx
index 4eed5814e..f76bf5e2e 100644
--- a/packages/app/src/components/code.tsx
+++ b/packages/app/src/components/code.tsx
@@ -1,15 +1,6 @@
-import { bundledLanguages, codeToHtml, type ShikiTransformer } from "shiki"
-import {
- createResource,
- splitProps,
- Suspense,
- type ComponentProps,
- createEffect,
- onMount,
- onCleanup,
- createMemo,
-} from "solid-js"
-import { useLocal } from "@/context"
+import { bundledLanguages, type BundledLanguage, type ShikiTransformer } from "shiki"
+import { splitProps, type ComponentProps, createEffect, onMount, onCleanup, createMemo, createResource } from "solid-js"
+import { useLocal, useShiki } from "@/context"
import { getFileExtension, getNodeOffsetInLine, getSelectionInContainer } from "@/utils"
interface Props extends ComponentProps<"div"> {
@@ -17,6 +8,349 @@ interface Props extends ComponentProps<"div"> {
path: string
}
+export function Code(props: Props) {
+ const ctx = useLocal()
+ const highlighter = useShiki()
+ const [local, others] = splitProps(props, ["class", "classList", "code", "path"])
+ const lang = createMemo(() => getFileExtension(local.path))
+
+ let container: HTMLDivElement | undefined
+ let isProgrammaticSelection = false
+
+ const [html] = createResource(async () => {
+ if (!highlighter.getLoadedLanguages().includes(lang())) {
+ await highlighter.loadLanguage(lang() as BundledLanguage)
+ }
+ return highlighter.codeToHtml(local.code || "", {
+ lang: lang() && lang() in bundledLanguages ? lang() : "text",
+ theme: "opencode",
+ transformers: [transformerUnifiedDiff(), transformerDiffGroups()],
+ }) as string
+ })
+
+ onMount(() => {
+ if (!container) return
+
+ let ticking = false
+ const onScroll = () => {
+ if (!container) return
+ if (ctx.file.active()?.path !== local.path) return
+ if (ticking) return
+ ticking = true
+ requestAnimationFrame(() => {
+ ticking = false
+ ctx.file.scroll(local.path, container!.scrollTop)
+ })
+ }
+
+ const onSelectionChange = () => {
+ if (!container) return
+ if (isProgrammaticSelection) return
+ if (ctx.file.active()?.path !== local.path) return
+ const d = getSelectionInContainer(container)
+ if (!d) return
+ const p = ctx.file.node(local.path)?.selection
+ if (p && p.startLine === d.sl && p.endLine === d.el && p.startChar === d.sch && p.endChar === d.ech) return
+ ctx.file.select(local.path, { startLine: d.sl, startChar: d.sch, endLine: d.el, endChar: d.ech })
+ }
+
+ const MOD = typeof navigator === "object" && /(Mac|iPod|iPhone|iPad)/.test(navigator.platform) ? "Meta" : "Control"
+ const onKeyDown = (e: KeyboardEvent) => {
+ if (ctx.file.active()?.path !== local.path) return
+ const ae = document.activeElement as HTMLElement | undefined
+ const tag = (ae?.tagName || "").toLowerCase()
+ const inputFocused = !!ae && (tag === "input" || tag === "textarea" || ae.isContentEditable)
+ if (inputFocused) return
+ if (e.getModifierState(MOD) && e.key.toLowerCase() === "a") {
+ e.preventDefault()
+ if (!container) return
+ const element = container.querySelector("code") as HTMLElement | undefined
+ if (!element) return
+ const lines = Array.from(element.querySelectorAll(".line"))
+ if (!lines.length) return
+ const r = document.createRange()
+ const last = lines[lines.length - 1]
+ r.selectNodeContents(last)
+ const lastLen = r.toString().length
+ ctx.file.select(local.path, { startLine: 1, startChar: 0, endLine: lines.length, endChar: lastLen })
+ }
+ }
+
+ container.addEventListener("scroll", onScroll)
+ document.addEventListener("selectionchange", onSelectionChange)
+ document.addEventListener("keydown", onKeyDown)
+
+ onCleanup(() => {
+ container?.removeEventListener("scroll", onScroll)
+ document.removeEventListener("selectionchange", onSelectionChange)
+ document.removeEventListener("keydown", onKeyDown)
+ })
+ })
+
+ // Restore scroll position from store when content is ready
+ createEffect(() => {
+ const content = html()
+ if (!container || !content) return
+ const top = ctx.file.node(local.path)?.scrollTop
+ if (top !== undefined && container.scrollTop !== top) container.scrollTop = top
+ })
+
+ // Sync selection from store -> DOM
+ createEffect(() => {
+ const content = html()
+ if (!container || !content) return
+ if (ctx.file.active()?.path !== local.path) return
+ const codeEl = container.querySelector("code") as HTMLElement | undefined
+ if (!codeEl) return
+ const target = ctx.file.node(local.path)?.selection
+ const current = getSelectionInContainer(container)
+ const sel = window.getSelection()
+ if (!sel) return
+ if (!target) {
+ if (current) {
+ isProgrammaticSelection = true
+ sel.removeAllRanges()
+ queueMicrotask(() => {
+ isProgrammaticSelection = false
+ })
+ }
+ return
+ }
+ const matches = !!(
+ current &&
+ current.sl === target.startLine &&
+ current.sch === target.startChar &&
+ current.el === target.endLine &&
+ current.ech === target.endChar
+ )
+ if (matches) return
+ const lines = Array.from(codeEl.querySelectorAll(".line"))
+ if (lines.length === 0) return
+ let sIdx = Math.max(0, target.startLine - 1)
+ let eIdx = Math.max(0, target.endLine - 1)
+ let sChar = Math.max(0, target.startChar || 0)
+ let eChar = Math.max(0, target.endChar || 0)
+ if (sIdx > eIdx || (sIdx === eIdx && sChar > eChar)) {
+ const ti = sIdx
+ sIdx = eIdx
+ eIdx = ti
+ const tc = sChar
+ sChar = eChar
+ eChar = tc
+ }
+ if (eChar === 0 && eIdx > sIdx) {
+ eIdx = eIdx - 1
+ eChar = Number.POSITIVE_INFINITY
+ }
+ if (sIdx >= lines.length) return
+ if (eIdx >= lines.length) eIdx = lines.length - 1
+ const s = getNodeOffsetInLine(lines[sIdx], sChar) ?? { node: lines[sIdx], offset: 0 }
+ const e = getNodeOffsetInLine(lines[eIdx], eChar) ?? { node: lines[eIdx], offset: lines[eIdx].childNodes.length }
+ const range = document.createRange()
+ range.setStart(s.node, s.offset)
+ range.setEnd(e.node, e.offset)
+ isProgrammaticSelection = true
+ sel.removeAllRanges()
+ sel.addRange(range)
+ queueMicrotask(() => {
+ isProgrammaticSelection = false
+ })
+ })
+
+ // Build/toggle split layout and apply folding (both unified and split)
+ createEffect(() => {
+ const content = html()
+ if (!container || !content) return
+ const view = ctx.file.view(local.path)
+
+ const pres = Array.from(container.querySelectorAll<HTMLPreElement>("pre"))
+ if (pres.length === 0) return
+ const originalPre = pres[0]
+
+ const split = container.querySelector<HTMLElement>(".diff-split")
+ if (view === "diff-split") {
+ applySplitDiff(container)
+ const next = container.querySelector<HTMLElement>(".diff-split")
+ if (next) next.style.display = ""
+ originalPre.style.display = "none"
+ } else {
+ if (split) split.style.display = "none"
+ originalPre.style.display = ""
+ }
+
+ const expanded = ctx.file.folded(local.path)
+ if (view === "diff-split") {
+ const left = container.querySelector<HTMLElement>(".diff-split pre:nth-child(1) code")
+ const right = container.querySelector<HTMLElement>(".diff-split pre:nth-child(2) code")
+ if (left)
+ applyDiffFolding(left, 3, { expanded, onExpand: (key) => ctx.file.unfold(local.path, key), side: "left" })
+ if (right)
+ applyDiffFolding(right, 3, { expanded, onExpand: (key) => ctx.file.unfold(local.path, key), side: "right" })
+ } else {
+ const code = container.querySelector<HTMLElement>("pre code")
+ if (code)
+ applyDiffFolding(code, 3, {
+ expanded,
+ onExpand: (key) => ctx.file.unfold(local.path, key),
+ })
+ }
+ })
+
+ // Highlight groups + scroll coupling
+ const clearHighlights = () => {
+ if (!container) return
+ container.querySelectorAll<HTMLElement>(".diff-selected").forEach((el) => el.classList.remove("diff-selected"))
+ }
+
+ const applyHighlight = (idx: number, scroll?: boolean) => {
+ if (!container) return
+ const view = ctx.file.view(local.path)
+ if (view === "raw") return
+
+ clearHighlights()
+
+ const nodes: HTMLElement[] = []
+ if (view === "diff-split") {
+ const left = container.querySelector<HTMLElement>(".diff-split pre:nth-child(1) code")
+ const right = container.querySelector<HTMLElement>(".diff-split pre:nth-child(2) code")
+ if (left)
+ nodes.push(...Array.from(left.querySelectorAll<HTMLElement>(`[data-chgrp="${idx}"][data-diff="remove"]`)))
+ if (right)
+ nodes.push(...Array.from(right.querySelectorAll<HTMLElement>(`[data-chgrp="${idx}"][data-diff="add"]`)))
+ } else {
+ const code = container.querySelector<HTMLElement>("pre code")
+ if (code) nodes.push(...Array.from(code.querySelectorAll<HTMLElement>(`[data-chgrp="${idx}"]`)))
+ }
+
+ for (const n of nodes) n.classList.add("diff-selected")
+ if (scroll && nodes.length) nodes[0].scrollIntoView({ block: "center", behavior: "smooth" })
+ }
+
+ const countGroups = () => {
+ if (!container) return 0
+ const code = container.querySelector<HTMLElement>("pre code")
+ if (!code) return 0
+ const set = new Set<string>()
+ for (const el of Array.from(code.querySelectorAll<HTMLElement>(".diff-line[data-chgrp]"))) {
+ const v = el.getAttribute("data-chgrp")
+ if (v != undefined) set.add(v)
+ }
+ return set.size
+ }
+
+ let lastIdx: number | undefined = undefined
+ let lastView: string | undefined
+ let lastContent: string | undefined
+ let lastRawIdx: number | undefined = undefined
+ createEffect(() => {
+ const content = html()
+ if (!container || !content) return
+ const view = ctx.file.view(local.path)
+ const raw = ctx.file.changeIndex(local.path)
+ if (raw === undefined) return
+ const total = countGroups()
+ if (total <= 0) return
+ const next = ((raw % total) + total) % total
+
+ const navigated = lastRawIdx !== undefined && lastRawIdx !== raw
+
+ if (next !== raw) {
+ ctx.file.setChangeIndex(local.path, next)
+ applyHighlight(next, true)
+ } else {
+ if (lastView !== view || lastContent !== content) applyHighlight(next)
+ if ((lastIdx !== undefined && lastIdx !== next) || navigated) applyHighlight(next, true)
+ }
+
+ lastRawIdx = raw
+ lastIdx = next
+ lastView = view
+ lastContent = content
+ })
+
+ return (
+ <div
+ ref={(el) => {
+ container = el
+ }}
+ innerHTML={html()}
+ class="
+ font-mono text-xs tracking-wide overflow-y-auto no-scrollbar h-full
+ [&]:[counter-reset:line]
+ [&_pre]:focus-visible:outline-none
+ [&_pre]:overflow-x-auto [&_pre]:no-scrollbar
+ [&_code]:min-w-full [&_code]:inline-block [&_code]:pb-40
+ [&_.tab]:relative
+ [&_.tab::before]:content['⇥']
+ [&_.tab::before]:absolute
+ [&_.tab::before]:opacity-0
+ [&_.space]:relative
+ [&_.space::before]:content-['·']
+ [&_.space::before]:absolute
+ [&_.space::before]:opacity-0
+ [&_.line]:inline-block [&_.line]:w-full
+ [&_.line]:hover:bg-background-element
+ [&_.line::before]:sticky [&_.line::before]:left-0
+ [&_.line::before]:w-12 [&_.line::before]:pr-4
+ [&_.line::before]:z-10
+ [&_.line::before]:bg-background-panel
+ [&_.line::before]:text-text-muted/60
+ [&_.line::before]:text-right [&_.line::before]:inline-block
+ [&_.line::before]:select-none
+ [&_.line::before]:[counter-increment:line]
+ [&_.line::before]:content-[counter(line)]
+ [&_code.code-diff_.line::before]:content-['']
+ [&_code.code-diff_.line::before]:w-0
+ [&_code.code-diff_.line::before]:pr-0
+ [&_.diff-split_code.code-diff::before]:w-10
+ [&_.diff-split_.diff-newln]:left-0
+ [&_.diff-oldln]:sticky [&_.diff-oldln]:left-0
+ [&_.diff-oldln]:w-10 [&_.diff-oldln]:pr-2
+ [&_.diff-oldln]:z-40
+ [&_.diff-oldln]:text-text-muted/60
+ [&_.diff-oldln]:text-right [&_.diff-oldln]:inline-block
+ [&_.diff-oldln]:select-none
+ [&_.diff-oldln]:bg-background-panel
+ [&_.diff-newln]:sticky [&_.diff-newln]:left-10
+ [&_.diff-newln]:w-10 [&_.diff-newln]:pr-2
+ [&_.diff-newln]:z-40
+ [&_.diff-newln]:text-text-muted/60
+ [&_.diff-newln]:text-right [&_.diff-newln]:inline-block
+ [&_.diff-newln]:select-none
+ [&_.diff-newln]:bg-background-panel
+ [&_.diff-add]:bg-success/20!
+ [&_.diff-add.diff-selected]:bg-success/50!
+ [&_.diff-add_.diff-oldln]:bg-success!
+ [&_.diff-add_.diff-oldln]:text-background-panel!
+ [&_.diff-add_.diff-newln]:bg-success!
+ [&_.diff-add_.diff-newln]:text-background-panel!
+ [&_.diff-remove]:bg-error/20!
+ [&_.diff-remove.diff-selected]:bg-error/50!
+ [&_.diff-remove_.diff-newln]:bg-error!
+ [&_.diff-remove_.diff-newln]:text-background-panel!
+ [&_.diff-remove_.diff-oldln]:bg-error!
+ [&_.diff-remove_.diff-oldln]:text-background-panel!
+ [&_.diff-sign]:inline-block [&_.diff-sign]:px-2 [&_.diff-sign]:select-none
+ [&_.diff-blank]:bg-background-element
+ [&_.diff-blank_.diff-oldln]:bg-background-element
+ [&_.diff-blank_.diff-newln]:bg-background-element
+ [&_.diff-collapsed]:block! [&_.diff-collapsed]:w-full [&_.diff-collapsed]:relative
+ [&_.diff-collapsed]:cursor-pointer [&_.diff-collapsed]:select-none
+ [&_.diff-collapsed]:bg-info/20 [&_.diff-collapsed]:hover:bg-info/40!
+ [&_.diff-collapsed]:text-info/80 [&_.diff-collapsed]:hover:text-info
+ [&_.diff-collapsed]:text-xs
+ [&_.diff-collapsed_.diff-oldln]:bg-info!
+ [&_.diff-collapsed_.diff-newln]:bg-info!
+ "
+ classList={{
+ ...(local.classList || {}),
+ [local.class ?? ""]: !!local.class,
+ }}
+ {...others}
+ ></div>
+ )
+}
+
function transformerUnifiedDiff(): ShikiTransformer {
const kinds = new Map<number, string>()
const meta = new Map<number, { old?: number; new?: number; sign?: string }>()
@@ -451,908 +785,3 @@ function applySplitDiff(container: HTMLElement) {
grid.appendChild(right.pre)
container.appendChild(grid)
}
-
-export function Code(props: Props) {
- const ctx = useLocal()
- const [local, others] = splitProps(props, ["class", "classList", "code", "path"])
- const lang = createMemo(() => getFileExtension(local.path))
-
- let container: HTMLDivElement | undefined
- let isProgrammaticSelection = false
-
- const [html] = createResource(
- () => [local.code, lang()],
- async ([code, lang]) => {
- return (await codeToHtml(code || "", {
- lang: lang && lang in bundledLanguages ? lang : "text",
- theme: {
- colors: {
- "actionBar.toggledBackground": "var(--theme-background-element)",
- "activityBarBadge.background": "var(--theme-accent)",
- "checkbox.border": "var(--theme-border)",
- "editor.background": "transparent",
- "editor.foreground": "var(--theme-text)",
- "editor.inactiveSelectionBackground": "var(--theme-background-element)",
- "editor.selectionHighlightBackground": "var(--theme-border-active)",
- "editorIndentGuide.activeBackground1": "var(--theme-border-subtle)",
- "editorIndentGuide.background1": "var(--theme-border-subtle)",
- "input.placeholderForeground": "var(--theme-text-muted)",
- "list.activeSelectionIconForeground": "var(--theme-text)",
- "list.dropBackground": "var(--theme-background-element)",
- "menu.background": "var(--theme-background-panel)",
- "menu.border": "var(--theme-border)",
- "menu.foreground": "var(--theme-text)",
- "menu.selectionBackground": "var(--theme-primary)",
- "menu.separatorBackground": "var(--theme-border)",
- "ports.iconRunningProcessForeground": "var(--theme-success)",
- "sideBarSectionHeader.background": "transparent",
- "sideBarSectionHeader.border": "var(--theme-border-subtle)",
- "sideBarTitle.foreground": "var(--theme-text-muted)",
- "statusBarItem.remoteBackground": "var(--theme-success)",
- "statusBarItem.remoteForeground": "var(--theme-text)",
- "tab.lastPinnedBorder": "var(--theme-border-subtle)",
- "tab.selectedBackground": "var(--theme-background-element)",
- "tab.selectedForeground": "var(--theme-text-muted)",
- "terminal.inactiveSelectionBackground": "var(--theme-background-element)",
- "widget.border": "var(--theme-border)",
- },
- displayName: "opencode",
- name: "opencode",
- semanticHighlighting: true,
- semanticTokenColors: {
- customLiteral: "var(--theme-syntax-function)",
- newOperator: "var(--theme-syntax-operator)",
- numberLiteral: "var(--theme-syntax-number)",
- stringLiteral: "var(--theme-syntax-string)",
- },
- tokenColors: [
- {
- scope: [
- "meta.embedded",
- "source.groovy.embedded",
- "string meta.image.inline.markdown",
- "variable.legacy.builtin.python",
- ],
- settings: {
- foreground: "var(--theme-text)",
- },
- },
- {
- scope: "emphasis",
- settings: {
- fontStyle: "italic",
- },
- },
- {
- scope: "strong",
- settings: {
- fontStyle: "bold",
- },
- },
- {
- scope: "header",
- settings: {
- foreground: "var(--theme-markdown-heading)",
- },
- },
- {
- scope: "comment",
- settings: {
- foreground: "var(--theme-syntax-comment)",
- },
- },
- {
- scope: "constant.language",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: [
- "constant.numeric",
- "variable.other.enummember",
- "keyword.operator.plus.exponent",
- "keyword.operator.minus.exponent",
- ],
- settings: {
- foreground: "var(--theme-syntax-number)",
- },
- },
- {
- scope: "constant.regexp",
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: "entity.name.tag",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: ["entity.name.tag.css", "entity.name.tag.less"],
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: "entity.other.attribute-name",
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: [
- "entity.other.attribute-name.class.css",
- "source.css entity.other.attribute-name.class",
- "entity.other.attribute-name.id.css",
- "entity.other.attribute-name.parent-selector.css",
- "entity.other.attribute-name.parent.less",
- "source.css entity.other.attribute-name.pseudo-class",
- "entity.other.attribute-name.pseudo-element.css",
- "source.css.less entity.other.attribute-name.id",
- "entity.other.attribute-name.scss",
- ],
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: "invalid",
- settings: {
- foreground: "var(--theme-error)",
- },
- },
- {
- scope: "markup.underline",
- settings: {
- fontStyle: "underline",
- },
- },
- {
- scope: "markup.bold",
- settings: {
- fontStyle: "bold",
- foreground: "var(--theme-markdown-strong)",
- },
- },
- {
- scope: "markup.heading",
- settings: {
- fontStyle: "bold",
- foreground: "var(--theme-markdown-heading)",
- },
- },
- {
- scope: "markup.italic",
- settings: {
- fontStyle: "italic",
- },
- },
- {
- scope: "markup.strikethrough",
- settings: {
- fontStyle: "strikethrough",
- },
- },
- {
- scope: "markup.inserted",
- settings: {
- foreground: "var(--theme-diff-added)",
- },
- },
- {
- scope: "markup.deleted",
- settings: {
- foreground: "var(--theme-diff-removed)",
- },
- },
- {
- scope: "markup.changed",
- settings: {
- foreground: "var(--theme-diff-context)",
- },
- },
- {
- scope: "punctuation.definition.quote.begin.markdown",
- settings: {
- foreground: "var(--theme-markdown-block-quote)",
- },
- },
- {
- scope: "punctuation.definition.list.begin.markdown",
- settings: {
- foreground: "var(--theme-markdown-list-enumeration)",
- },
- },
- {
- scope: "markup.inline.raw",
- settings: {
- foreground: "var(--theme-markdown-code)",
- },
- },
- {
- scope: "punctuation.definition.tag",
- settings: {
- foreground: "var(--theme-syntax-punctuation)",
- },
- },
- {
- scope: ["meta.preprocessor", "entity.name.function.preprocessor"],
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "meta.preprocessor.string",
- settings: {
- foreground: "var(--theme-syntax-string)",
- },
- },
- {
- scope: "meta.preprocessor.numeric",
- settings: {
- foreground: "var(--theme-syntax-number)",
- },
- },
- {
- scope: "meta.structure.dictionary.key.python",
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: "meta.diff.header",
- settings: {
- foreground: "var(--theme-diff-hunk-header)",
- },
- },
- {
- scope: "storage",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "storage.type",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: ["storage.modifier", "keyword.operator.noexcept"],
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: ["string", "meta.embedded.assembly"],
- settings: {
- foreground: "var(--theme-syntax-string)",
- },
- },
- {
- scope: "string.tag",
- settings: {
- foreground: "var(--theme-syntax-string)",
- },
- },
- {
- scope: "string.value",
- settings: {
- foreground: "var(--theme-syntax-string)",
- },
- },
- {
- scope: "string.regexp",
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: [
- "punctuation.definition.template-expression.begin",
- "punctuation.definition.template-expression.end",
- "punctuation.section.embedded",
- ],
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: ["meta.template.expression"],
- settings: {
- foreground: "var(--theme-text)",
- },
- },
- {
- scope: [
- "support.type.vendored.property-name",
- "support.type.property-name",
- "source.css variable",
- "source.coffee.embedded",
- ],
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: "keyword",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "keyword.control",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "keyword.operator",
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: [
- "keyword.operator.new",
- "keyword.operator.expression",
- "keyword.operator.cast",
- "keyword.operator.sizeof",
- "keyword.operator.alignof",
- "keyword.operator.typeid",
- "keyword.operator.alignas",
- "keyword.operator.instanceof",
- "keyword.operator.logical.python",
- "keyword.operator.wordlike",
- ],
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "keyword.other.unit",
- settings: {
- foreground: "var(--theme-syntax-number)",
- },
- },
- {
- scope: ["punctuation.section.embedded.begin.php", "punctuation.section.embedded.end.php"],
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "support.function.git-rebase",
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: "constant.sha.git-rebase",
- settings: {
- foreground: "var(--theme-syntax-number)",
- },
- },
- {
- scope: [
- "storage.modifier.import.java",
- "variable.language.wildcard.java",
- "storage.modifier.package.java",
- ],
- settings: {
- foreground: "var(--theme-text)",
- },
- },
- {
- scope: "variable.language",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: [
- "entity.name.function",
- "support.function",
- "support.constant.handlebars",
- "source.powershell variable.other.member",
- "entity.name.operator.custom-literal",
- ],
- settings: {
- foreground: "var(--theme-syntax-function)",
- },
- },
- {
- scope: [
- "support.class",
- "support.type",
- "entity.name.type",
- "entity.name.namespace",
- "entity.other.attribute",
- "entity.name.scope-resolution",
- "entity.name.class",
- "storage.type.numeric.go",
- "storage.type.byte.go",
- "storage.type.boolean.go",
- "storage.type.string.go",
- "storage.type.uintptr.go",
- "storage.type.error.go",
- "storage.type.rune.go",
- "storage.type.cs",
- "storage.type.generic.cs",
- "storage.type.modifier.cs",
- "storage.type.variable.cs",
- "storage.type.annotation.java",
- "storage.type.generic.java",
- "storage.type.java",
- "storage.type.object.array.java",
- "storage.type.primitive.array.java",
- "storage.type.primitive.java",
- "storage.type.token.java",
- "storage.type.groovy",
- "storage.type.annotation.groovy",
- "storage.type.parameters.groovy",
- "storage.type.generic.groovy",
- "storage.type.object.array.groovy",
- "storage.type.primitive.array.groovy",
- "storage.type.primitive.groovy",
- ],
- settings: {
- foreground: "var(--theme-syntax-type)",
- },
- },
- {
- scope: [
- "meta.type.cast.expr",
- "meta.type.new.expr",
- "support.constant.math",
- "support.constant.dom",
- "support.constant.json",
- "entity.other.inherited-class",
- "punctuation.separator.namespace.ruby",
- ],
- settings: {
- foreground: "var(--theme-syntax-type)",
- },
- },
- {
- scope: [
- "keyword.control",
- "source.cpp keyword.operator.new",
- "keyword.operator.delete",
- "keyword.other.using",
- "keyword.other.directive.using",
- "keyword.other.operator",
- "entity.name.operator",
- ],
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: [
- "variable",
- "meta.definition.variable.name",
- "support.variable",
- "entity.name.variable",
- "constant.other.placeholder",
- ],
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: ["variable.other.constant", "variable.other.enummember"],
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: ["meta.object-literal.key"],
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: [
- "support.constant.property-value",
- "support.constant.font-name",
- "support.constant.media-type",
- "support.constant.media",
- "constant.other.color.rgb-value",
- "constant.other.rgb-value",
- "support.constant.color",
- ],
- settings: {
- foreground: "var(--theme-syntax-string)",
- },
- },
- {
- scope: [
- "punctuation.definition.group.regexp",
- "punctuation.definition.group.assertion.regexp",
- "punctuation.definition.character-class.regexp",
- "punctuation.character.set.begin.regexp",
- "punctuation.character.set.end.regexp",
- "keyword.operator.negation.regexp",
- "support.other.parenthesis.regexp",
- ],
- settings: {
- foreground: "var(--theme-syntax-string)",
- },
- },
- {
- scope: [
- "constant.character.character-class.regexp",
- "constant.other.character-class.set.regexp",
- "constant.other.character-class.regexp",
- "constant.character.set.regexp",
- ],
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: ["keyword.operator.or.regexp", "keyword.control.anchor.regexp"],
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: "keyword.operator.quantifier.regexp",
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: ["constant.character", "constant.other.option"],
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "constant.character.escape",
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: "entity.name.label",
- settings: {
- foreground: "var(--theme-text-muted)",
- },
- },
- ],
- type: "dark",
- },
- transformers: [transformerUnifiedDiff(), transformerDiffGroups()],
- })) as string
- },
- )
-
- onMount(() => {
- if (!container) return
-
- let ticking = false
- const onScroll = () => {
- if (!container) return
- if (ctx.file.active()?.path !== local.path) return
- if (ticking) return
- ticking = true
- requestAnimationFrame(() => {
- ticking = false
- ctx.file.scroll(local.path, container!.scrollTop)
- })
- }
-
- const onSelectionChange = () => {
- if (!container) return
- if (isProgrammaticSelection) return
- if (ctx.file.active()?.path !== local.path) return
- const d = getSelectionInContainer(container)
- if (!d) return
- const p = ctx.file.node(local.path)?.selection
- if (p && p.startLine === d.sl && p.endLine === d.el && p.startChar === d.sch && p.endChar === d.ech) return
- ctx.file.select(local.path, { startLine: d.sl, startChar: d.sch, endLine: d.el, endChar: d.ech })
- }
-
- const MOD = typeof navigator === "object" && /(Mac|iPod|iPhone|iPad)/.test(navigator.platform) ? "Meta" : "Control"
- const onKeyDown = (e: KeyboardEvent) => {
- if (ctx.file.active()?.path !== local.path) return
- const ae = document.activeElement as HTMLElement | undefined
- const tag = (ae?.tagName || "").toLowerCase()
- const inputFocused = !!ae && (tag === "input" || tag === "textarea" || ae.isContentEditable)
- if (inputFocused) return
- if (e.getModifierState(MOD) && e.key.toLowerCase() === "a") {
- e.preventDefault()
- if (!container) return
- const element = container.querySelector("code") as HTMLElement | undefined
- if (!element) return
- const lines = Array.from(element.querySelectorAll(".line"))
- if (!lines.length) return
- const r = document.createRange()
- const last = lines[lines.length - 1]
- r.selectNodeContents(last)
- const lastLen = r.toString().length
- ctx.file.select(local.path, { startLine: 1, startChar: 0, endLine: lines.length, endChar: lastLen })
- }
- }
-
- container.addEventListener("scroll", onScroll)
- document.addEventListener("selectionchange", onSelectionChange)
- document.addEventListener("keydown", onKeyDown)
-
- onCleanup(() => {
- container?.removeEventListener("scroll", onScroll)
- document.removeEventListener("selectionchange", onSelectionChange)
- document.removeEventListener("keydown", onKeyDown)
- })
- })
-
- // Restore scroll position from store when content is ready
- createEffect(() => {
- const content = html()
- if (!container || !content) return
- const top = ctx.file.node(local.path)?.scrollTop
- if (top !== undefined && container.scrollTop !== top) container.scrollTop = top
- })
-
- // Sync selection from store -> DOM
- createEffect(() => {
- const content = html()
- if (!container || !content) return
- if (ctx.file.active()?.path !== local.path) return
- const codeEl = container.querySelector("code") as HTMLElement | undefined
- if (!codeEl) return
- const target = ctx.file.node(local.path)?.selection
- const current = getSelectionInContainer(container)
- const sel = window.getSelection()
- if (!sel) return
- if (!target) {
- if (current) {
- isProgrammaticSelection = true
- sel.removeAllRanges()
- queueMicrotask(() => {
- isProgrammaticSelection = false
- })
- }
- return
- }
- const matches = !!(
- current &&
- current.sl === target.startLine &&
- current.sch === target.startChar &&
- current.el === target.endLine &&
- current.ech === target.endChar
- )
- if (matches) return
- const lines = Array.from(codeEl.querySelectorAll(".line"))
- if (lines.length === 0) return
- let sIdx = Math.max(0, target.startLine - 1)
- let eIdx = Math.max(0, target.endLine - 1)
- let sChar = Math.max(0, target.startChar || 0)
- let eChar = Math.max(0, target.endChar || 0)
- if (sIdx > eIdx || (sIdx === eIdx && sChar > eChar)) {
- const ti = sIdx
- sIdx = eIdx
- eIdx = ti
- const tc = sChar
- sChar = eChar
- eChar = tc
- }
- if (eChar === 0 && eIdx > sIdx) {
- eIdx = eIdx - 1
- eChar = Number.POSITIVE_INFINITY
- }
- if (sIdx >= lines.length) return
- if (eIdx >= lines.length) eIdx = lines.length - 1
- const s = getNodeOffsetInLine(lines[sIdx], sChar) ?? { node: lines[sIdx], offset: 0 }
- const e = getNodeOffsetInLine(lines[eIdx], eChar) ?? { node: lines[eIdx], offset: lines[eIdx].childNodes.length }
- const range = document.createRange()
- range.setStart(s.node, s.offset)
- range.setEnd(e.node, e.offset)
- isProgrammaticSelection = true
- sel.removeAllRanges()
- sel.addRange(range)
- queueMicrotask(() => {
- isProgrammaticSelection = false
- })
- })
-
- // Build/toggle split layout and apply folding (both unified and split)
- createEffect(() => {
- const content = html()
- if (!container || !content) return
- const view = ctx.file.view(local.path)
-
- const pres = Array.from(container.querySelectorAll<HTMLPreElement>("pre"))
- if (pres.length === 0) return
- const originalPre = pres[0]
-
- const split = container.querySelector<HTMLElement>(".diff-split")
- if (view === "diff-split") {
- applySplitDiff(container)
- const next = container.querySelector<HTMLElement>(".diff-split")
- if (next) next.style.display = ""
- originalPre.style.display = "none"
- } else {
- if (split) split.style.display = "none"
- originalPre.style.display = ""
- }
-
- const expanded = ctx.file.folded(local.path)
- if (view === "diff-split") {
- const left = container.querySelector<HTMLElement>(".diff-split pre:nth-child(1) code")
- const right = container.querySelector<HTMLElement>(".diff-split pre:nth-child(2) code")
- if (left)
- applyDiffFolding(left, 3, { expanded, onExpand: (key) => ctx.file.unfold(local.path, key), side: "left" })
- if (right)
- applyDiffFolding(right, 3, { expanded, onExpand: (key) => ctx.file.unfold(local.path, key), side: "right" })
- } else {
- const code = container.querySelector<HTMLElement>("pre code")
- if (code)
- applyDiffFolding(code, 3, {
- expanded,
- onExpand: (key) => ctx.file.unfold(local.path, key),
- })
- }
- })
-
- // Highlight groups + scroll coupling
- const clearHighlights = () => {
- if (!container) return
- container.querySelectorAll<HTMLElement>(".diff-selected").forEach((el) => el.classList.remove("diff-selected"))
- }
-
- const applyHighlight = (idx: number, scroll?: boolean) => {
- if (!container) return
- const view = ctx.file.view(local.path)
- if (view === "raw") return
-
- clearHighlights()
-
- const nodes: HTMLElement[] = []
- if (view === "diff-split") {
- const left = container.querySelector<HTMLElement>(".diff-split pre:nth-child(1) code")
- const right = container.querySelector<HTMLElement>(".diff-split pre:nth-child(2) code")
- if (left)
- nodes.push(...Array.from(left.querySelectorAll<HTMLElement>(`[data-chgrp="${idx}"][data-diff="remove"]`)))
- if (right)
- nodes.push(...Array.from(right.querySelectorAll<HTMLElement>(`[data-chgrp="${idx}"][data-diff="add"]`)))
- } else {
- const code = container.querySelector<HTMLElement>("pre code")
- if (code) nodes.push(...Array.from(code.querySelectorAll<HTMLElement>(`[data-chgrp="${idx}"]`)))
- }
-
- for (const n of nodes) n.classList.add("diff-selected")
- if (scroll && nodes.length) nodes[0].scrollIntoView({ block: "center", behavior: "smooth" })
- }
-
- const countGroups = () => {
- if (!container) return 0
- const code = container.querySelector<HTMLElement>("pre code")
- if (!code) return 0
- const set = new Set<string>()
- for (const el of Array.from(code.querySelectorAll<HTMLElement>(".diff-line[data-chgrp]"))) {
- const v = el.getAttribute("data-chgrp")
- if (v != undefined) set.add(v)
- }
- return set.size
- }
-
- let lastIdx: number | undefined = undefined
- let lastView: string | undefined
- let lastContent: string | undefined
- let lastRawIdx: number | undefined = undefined
- createEffect(() => {
- const content = html()
- if (!container || !content) return
- const view = ctx.file.view(local.path)
- const raw = ctx.file.changeIndex(local.path)
- if (raw === undefined) return
- const total = countGroups()
- if (total <= 0) return
- const next = ((raw % total) + total) % total
-
- const navigated = lastRawIdx !== undefined && lastRawIdx !== raw
-
- if (next !== raw) {
- ctx.file.setChangeIndex(local.path, next)
- applyHighlight(next, true)
- } else {
- if (lastView !== view || lastContent !== content) applyHighlight(next)
- if ((lastIdx !== undefined && lastIdx !== next) || navigated) applyHighlight(next, true)
- }
-
- lastRawIdx = raw
- lastIdx = next
- lastView = view
- lastContent = content
- })
-
- return (
- <Suspense>
- <div
- ref={(el) => {
- container = el
- }}
- innerHTML={html()}
- class="
- font-mono text-xs tracking-wide overflow-y-auto no-scrollbar h-full
- [&]:[counter-reset:line]
- [&_pre]:focus-visible:outline-none
- [&_pre]:overflow-x-auto [&_pre]:no-scrollbar
- [&_code]:min-w-full [&_code]:inline-block [&_code]:pb-40
- [&_.tab]:relative
- [&_.tab::before]:content['⇥']
- [&_.tab::before]:absolute
- [&_.tab::before]:opacity-0
- [&_.space]:relative
- [&_.space::before]:content-['·']
- [&_.space::before]:absolute
- [&_.space::before]:opacity-0
- [&_.line]:inline-block [&_.line]:w-full
- [&_.line]:hover:bg-background-element
- [&_.line::before]:sticky [&_.line::before]:left-0
- [&_.line::before]:w-12 [&_.line::before]:pr-4
- [&_.line::before]:z-10
- [&_.line::before]:bg-background-panel
- [&_.line::before]:text-text-muted/60
- [&_.line::before]:text-right [&_.line::before]:inline-block
- [&_.line::before]:select-none
- [&_.line::before]:[counter-increment:line]
- [&_.line::before]:content-[counter(line)]
- [&_code.code-diff_.line::before]:content-['']
- [&_code.code-diff_.line::before]:w-0
- [&_code.code-diff_.line::before]:pr-0
- [&_.diff-split_code.code-diff::before]:w-10
- [&_.diff-split_.diff-newln]:left-0
- [&_.diff-oldln]:sticky [&_.diff-oldln]:left-0
- [&_.diff-oldln]:w-10 [&_.diff-oldln]:pr-2
- [&_.diff-oldln]:z-40
- [&_.diff-oldln]:text-text-muted/60
- [&_.diff-oldln]:text-right [&_.diff-oldln]:inline-block
- [&_.diff-oldln]:select-none
- [&_.diff-oldln]:bg-background-panel
- [&_.diff-newln]:sticky [&_.diff-newln]:left-10
- [&_.diff-newln]:w-10 [&_.diff-newln]:pr-2
- [&_.diff-newln]:z-40
- [&_.diff-newln]:text-text-muted/60
- [&_.diff-newln]:text-right [&_.diff-newln]:inline-block
- [&_.diff-newln]:select-none
- [&_.diff-newln]:bg-background-panel
- [&_.diff-add]:bg-success/20!
- [&_.diff-add.diff-selected]:bg-success/50!
- [&_.diff-add_.diff-oldln]:bg-success!
- [&_.diff-add_.diff-oldln]:text-background-panel!
- [&_.diff-add_.diff-newln]:bg-success!
- [&_.diff-add_.diff-newln]:text-background-panel!
- [&_.diff-remove]:bg-error/20!
- [&_.diff-remove.diff-selected]:bg-error/50!
- [&_.diff-remove_.diff-newln]:bg-error!
- [&_.diff-remove_.diff-newln]:text-background-panel!
- [&_.diff-remove_.diff-oldln]:bg-error!
- [&_.diff-remove_.diff-oldln]:text-background-panel!
- [&_.diff-sign]:inline-block [&_.diff-sign]:px-2 [&_.diff-sign]:select-none
- [&_.diff-blank]:bg-background-element
- [&_.diff-blank_.diff-oldln]:bg-background-element
- [&_.diff-blank_.diff-newln]:bg-background-element
- [&_.diff-collapsed]:block! [&_.diff-collapsed]:w-full [&_.diff-collapsed]:relative
- [&_.diff-collapsed]:cursor-pointer [&_.diff-collapsed]:select-none
- [&_.diff-collapsed]:bg-info/20 [&_.diff-collapsed]:hover:bg-info/40!
- [&_.diff-collapsed]:text-info/80 [&_.diff-collapsed]:hover:text-info
- [&_.diff-collapsed]:text-xs
- [&_.diff-collapsed_.diff-oldln]:bg-info!
- [&_.diff-collapsed_.diff-newln]:bg-info!
- "
- classList={{
- ...(local.classList || {}),
- [local.class ?? ""]: !!local.class,
- }}
- {...others}
- />
- </Suspense>
- )
-}
diff --git a/packages/app/src/components/markdown.tsx b/packages/app/src/components/markdown.tsx
index 1fb2cf836..ab6232ecf 100644
--- a/packages/app/src/components/markdown.tsx
+++ b/packages/app/src/components/markdown.tsx
@@ -1,584 +1,6 @@
-import { transformerNotationDiff } from "@shikijs/transformers"
-import { marked } from "marked"
-import markedShiki from "marked-shiki"
-import { codeToHtml } from "shiki"
+import { useMarked } from "@/context"
import { createResource } from "solid-js"
-const markedWithShiki = marked.use(
- markedShiki({
- highlight(code, lang) {
- return codeToHtml(code, {
- // structure: "inline",
- lang: lang || "text",
- tabindex: false,
- theme: {
- colors: {
- "actionBar.toggledBackground": "var(--theme-background-element)",
- "activityBarBadge.background": "var(--theme-accent)",
- "checkbox.border": "var(--theme-border)",
- "editor.background": "transparent",
- "editor.foreground": "var(--theme-text)",
- "editor.inactiveSelectionBackground": "var(--theme-background-element)",
- "editor.selectionHighlightBackground": "var(--theme-border-active)",
- "editorIndentGuide.activeBackground1": "var(--theme-border-subtle)",
- "editorIndentGuide.background1": "var(--theme-border-subtle)",
- "input.placeholderForeground": "var(--theme-text-muted)",
- "list.activeSelectionIconForeground": "var(--theme-text)",
- "list.dropBackground": "var(--theme-background-element)",
- "menu.background": "var(--theme-background-panel)",
- "menu.border": "var(--theme-border)",
- "menu.foreground": "var(--theme-text)",
- "menu.selectionBackground": "var(--theme-primary)",
- "menu.separatorBackground": "var(--theme-border)",
- "ports.iconRunningProcessForeground": "var(--theme-success)",
- "sideBarSectionHeader.background": "transparent",
- "sideBarSectionHeader.border": "var(--theme-border-subtle)",
- "sideBarTitle.foreground": "var(--theme-text-muted)",
- "statusBarItem.remoteBackground": "var(--theme-success)",
- "statusBarItem.remoteForeground": "var(--theme-text)",
- "tab.lastPinnedBorder": "var(--theme-border-subtle)",
- "tab.selectedBackground": "var(--theme-background-element)",
- "tab.selectedForeground": "var(--theme-text-muted)",
- "terminal.inactiveSelectionBackground": "var(--theme-background-element)",
- "widget.border": "var(--theme-border)",
- },
- displayName: "opencode",
- name: "opencode",
- semanticHighlighting: true,
- semanticTokenColors: {
- customLiteral: "var(--theme-syntax-function)",
- newOperator: "var(--theme-syntax-operator)",
- numberLiteral: "var(--theme-syntax-number)",
- stringLiteral: "var(--theme-syntax-string)",
- },
- tokenColors: [
- {
- scope: [
- "meta.embedded",
- "source.groovy.embedded",
- "string meta.image.inline.markdown",
- "variable.legacy.builtin.python",
- ],
- settings: {
- foreground: "var(--theme-text)",
- },
- },
- {
- scope: "emphasis",
- settings: {
- fontStyle: "italic",
- },
- },
- {
- scope: "strong",
- settings: {
- fontStyle: "bold",
- },
- },
- {
- scope: "header",
- settings: {
- foreground: "var(--theme-markdown-heading)",
- },
- },
- {
- scope: "comment",
- settings: {
- foreground: "var(--theme-syntax-comment)",
- },
- },
- {
- scope: "constant.language",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: [
- "constant.numeric",
- "variable.other.enummember",
- "keyword.operator.plus.exponent",
- "keyword.operator.minus.exponent",
- ],
- settings: {
- foreground: "var(--theme-syntax-number)",
- },
- },
- {
- scope: "constant.regexp",
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: "entity.name.tag",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: ["entity.name.tag.css", "entity.name.tag.less"],
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: "entity.other.attribute-name",
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: [
- "entity.other.attribute-name.class.css",
- "source.css entity.other.attribute-name.class",
- "entity.other.attribute-name.id.css",
- "entity.other.attribute-name.parent-selector.css",
- "entity.other.attribute-name.parent.less",
- "source.css entity.other.attribute-name.pseudo-class",
- "entity.other.attribute-name.pseudo-element.css",
- "source.css.less entity.other.attribute-name.id",
- "entity.other.attribute-name.scss",
- ],
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: "invalid",
- settings: {
- foreground: "var(--theme-error)",
- },
- },
- {
- scope: "markup.underline",
- settings: {
- fontStyle: "underline",
- },
- },
- {
- scope: "markup.bold",
- settings: {
- fontStyle: "bold",
- foreground: "var(--theme-markdown-strong)",
- },
- },
- {
- scope: "markup.heading",
- settings: {
- fontStyle: "bold",
- foreground: "var(--theme-markdown-heading)",
- },
- },
- {
- scope: "markup.italic",
- settings: {
- fontStyle: "italic",
- },
- },
- {
- scope: "markup.strikethrough",
- settings: {
- fontStyle: "strikethrough",
- },
- },
- {
- scope: "markup.inserted",
- settings: {
- foreground: "var(--theme-diff-added)",
- },
- },
- {
- scope: "markup.deleted",
- settings: {
- foreground: "var(--theme-diff-removed)",
- },
- },
- {
- scope: "markup.changed",
- settings: {
- foreground: "var(--theme-diff-context)",
- },
- },
- {
- scope: "punctuation.definition.quote.begin.markdown",
- settings: {
- foreground: "var(--theme-markdown-block-quote)",
- },
- },
- {
- scope: "punctuation.definition.list.begin.markdown",
- settings: {
- foreground: "var(--theme-markdown-list-enumeration)",
- },
- },
- {
- scope: "markup.inline.raw",
- settings: {
- foreground: "var(--theme-markdown-code)",
- },
- },
- {
- scope: "punctuation.definition.tag",
- settings: {
- foreground: "var(--theme-syntax-punctuation)",
- },
- },
- {
- scope: ["meta.preprocessor", "entity.name.function.preprocessor"],
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "meta.preprocessor.string",
- settings: {
- foreground: "var(--theme-syntax-string)",
- },
- },
- {
- scope: "meta.preprocessor.numeric",
- settings: {
- foreground: "var(--theme-syntax-number)",
- },
- },
- {
- scope: "meta.structure.dictionary.key.python",
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: "meta.diff.header",
- settings: {
- foreground: "var(--theme-diff-hunk-header)",
- },
- },
- {
- scope: "storage",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "storage.type",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: ["storage.modifier", "keyword.operator.noexcept"],
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: ["string", "meta.embedded.assembly"],
- settings: {
- foreground: "var(--theme-syntax-string)",
- },
- },
- {
- scope: "string.tag",
- settings: {
- foreground: "var(--theme-syntax-string)",
- },
- },
- {
- scope: "string.value",
- settings: {
- foreground: "var(--theme-syntax-string)",
- },
- },
- {
- scope: "string.regexp",
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: [
- "punctuation.definition.template-expression.begin",
- "punctuation.definition.template-expression.end",
- "punctuation.section.embedded",
- ],
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: ["meta.template.expression"],
- settings: {
- foreground: "var(--theme-text)",
- },
- },
- {
- scope: [
- "support.type.vendored.property-name",
- "support.type.property-name",
- "source.css variable",
- "source.coffee.embedded",
- ],
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: "keyword",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "keyword.control",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "keyword.operator",
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: [
- "keyword.operator.new",
- "keyword.operator.expression",
- "keyword.operator.cast",
- "keyword.operator.sizeof",
- "keyword.operator.alignof",
- "keyword.operator.typeid",
- "keyword.operator.alignas",
- "keyword.operator.instanceof",
- "keyword.operator.logical.python",
- "keyword.operator.wordlike",
- ],
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "keyword.other.unit",
- settings: {
- foreground: "var(--theme-syntax-number)",
- },
- },
- {
- scope: ["punctuation.section.embedded.begin.php", "punctuation.section.embedded.end.php"],
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "support.function.git-rebase",
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: "constant.sha.git-rebase",
- settings: {
- foreground: "var(--theme-syntax-number)",
- },
- },
- {
- scope: [
- "storage.modifier.import.java",
- "variable.language.wildcard.java",
- "storage.modifier.package.java",
- ],
- settings: {
- foreground: "var(--theme-text)",
- },
- },
- {
- scope: "variable.language",
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: [
- "entity.name.function",
- "support.function",
- "support.constant.handlebars",
- "source.powershell variable.other.member",
- "entity.name.operator.custom-literal",
- ],
- settings: {
- foreground: "var(--theme-syntax-function)",
- },
- },
- {
- scope: [
- "support.class",
- "support.type",
- "entity.name.type",
- "entity.name.namespace",
- "entity.other.attribute",
- "entity.name.scope-resolution",
- "entity.name.class",
- "storage.type.numeric.go",
- "storage.type.byte.go",
- "storage.type.boolean.go",
- "storage.type.string.go",
- "storage.type.uintptr.go",
- "storage.type.error.go",
- "storage.type.rune.go",
- "storage.type.cs",
- "storage.type.generic.cs",
- "storage.type.modifier.cs",
- "storage.type.variable.cs",
- "storage.type.annotation.java",
- "storage.type.generic.java",
- "storage.type.java",
- "storage.type.object.array.java",
- "storage.type.primitive.array.java",
- "storage.type.primitive.java",
- "storage.type.token.java",
- "storage.type.groovy",
- "storage.type.annotation.groovy",
- "storage.type.parameters.groovy",
- "storage.type.generic.groovy",
- "storage.type.object.array.groovy",
- "storage.type.primitive.array.groovy",
- "storage.type.primitive.groovy",
- ],
- settings: {
- foreground: "var(--theme-syntax-type)",
- },
- },
- {
- scope: [
- "meta.type.cast.expr",
- "meta.type.new.expr",
- "support.constant.math",
- "support.constant.dom",
- "support.constant.json",
- "entity.other.inherited-class",
- "punctuation.separator.namespace.ruby",
- ],
- settings: {
- foreground: "var(--theme-syntax-type)",
- },
- },
- {
- scope: [
- "keyword.control",
- "source.cpp keyword.operator.new",
- "keyword.operator.delete",
- "keyword.other.using",
- "keyword.other.directive.using",
- "keyword.other.operator",
- "entity.name.operator",
- ],
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: [
- "variable",
- "meta.definition.variable.name",
- "support.variable",
- "entity.name.variable",
- "constant.other.placeholder",
- ],
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: ["variable.other.constant", "variable.other.enummember"],
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: ["meta.object-literal.key"],
- settings: {
- foreground: "var(--theme-syntax-variable)",
- },
- },
- {
- scope: [
- "support.constant.property-value",
- "support.constant.font-name",
- "support.constant.media-type",
- "support.constant.media",
- "constant.other.color.rgb-value",
- "constant.other.rgb-value",
- "support.constant.color",
- ],
- settings: {
- foreground: "var(--theme-syntax-string)",
- },
- },
- {
- scope: [
- "punctuation.definition.group.regexp",
- "punctuation.definition.group.assertion.regexp",
- "punctuation.definition.character-class.regexp",
- "punctuation.character.set.begin.regexp",
- "punctuation.character.set.end.regexp",
- "keyword.operator.negation.regexp",
- "support.other.parenthesis.regexp",
- ],
- settings: {
- foreground: "var(--theme-syntax-string)",
- },
- },
- {
- scope: [
- "constant.character.character-class.regexp",
- "constant.other.character-class.set.regexp",
- "constant.other.character-class.regexp",
- "constant.character.set.regexp",
- ],
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: ["keyword.operator.or.regexp", "keyword.control.anchor.regexp"],
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: "keyword.operator.quantifier.regexp",
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: ["constant.character", "constant.other.option"],
- settings: {
- foreground: "var(--theme-syntax-keyword)",
- },
- },
- {
- scope: "constant.character.escape",
- settings: {
- foreground: "var(--theme-syntax-operator)",
- },
- },
- {
- scope: "entity.name.label",
- settings: {
- foreground: "var(--theme-text-muted)",
- },
- },
- ],
- type: "dark",
- },
- transformers: [transformerNotationDiff()],
- })
- },
- }),
-)
-
function strip(text: string): string {
const wrappedRe = /^\s*<([A-Za-z]\w*)>\s*([\s\S]*?)\s*<\/\1>\s*$/
const match = text.match(wrappedRe)
@@ -586,10 +8,11 @@ function strip(text: string): string {
}
export default function Markdown(props: { text: string; class?: string }) {
+ const marked = useMarked()
const [html] = createResource(
() => strip(props.text),
async (markdown) => {
- return markedWithShiki.parse(markdown)
+ return marked.parse(markdown)
},
)
return (