Skip to content

Ideas to syntax highlight on the server #1584

Closed Answered by dominictobias
dominictobias asked this question in Q&A
Discussion options

You must be logged in to vote

Never mind I think it will be simple:

import { cache } from '@solidjs/router'
import { JSX, createResource } from 'solid-js'

const syntaxHighlight = cache(
  async (sourceImport: () => Promise<typeof import('*?raw')>) => {
    'use server'
    const source = await sourceImport().then(m => m.default)
    return `highlighted: ${source}`
  },
  'users',
)

interface ComponentDemoProps {
  component: JSX.Element
  sourceImport: () => Promise<typeof import('*?raw')>
}

export default function ComponentDemo(props: ComponentDemoProps) {
  const [code] = createResource(() => syntaxHighlight(props.sourceImport))
  return (
    <div>
      <div>{code()}</div>
      <div>{props.component}</div>
    </

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dominictobias
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant