Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] demo/wrapper with frameworks #26

Open
4 tasks
matubu opened this issue Mar 29, 2022 · 1 comment
Open
4 tasks

[FEATURE] demo/wrapper with frameworks #26

matubu opened this issue Mar 29, 2022 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@matubu
Copy link
Member

matubu commented Mar 29, 2022

Add demo and documention on how to use speed-highlight JS with frameworks

  • svelte
  • angular
  • react
  • vue
@matubu matubu added the enhancement New feature or request label Mar 29, 2022
@matubu matubu added this to the v1.2.0 milestone Mar 29, 2022
@matubu matubu changed the title [FEATURE] demo with frameworks [FEATURE] demo/wrapper with frameworks Mar 29, 2022
@gummikonsumer
Copy link

gummikonsumer commented Jun 27, 2024

I have been using this for react:

'use client'

import { highlightElement } from '@speed-highlight/core'
import { detectLanguage } from '@speed-highlight/core/detect'
import { useEffect, useRef } from 'react'

export default function Code ({ children, language, theme = 'default', ...props }) {
  const r = useRef()
  useEffect(() => {
    if (r.current) {
      highlightElement(r.current, language || detectLanguage(children))
    }
  }, [r.current])

  return (
    <>
      <link rel='stylesheet' href={`https://cdn.jsdelivr.net/gh/speed-highlight/core/dist/themes/${theme}.css`} />
      <pre ref={r} {...props}>{children}</pre>
    </>
  )
}

// example usage
<Code theme='dark'>{JSON.stringify(experiment, null, 2)}</Code>

the use client part makes it work in next's new app-router. Is there a better way to do theme?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants