@yozora/react-code-embed
TypeScript icon, indicating that this package has built-in type declarations

3.0.0-alpha.14 • Public • Published

This component is for rendering the Code data produced by @yozora/tokenizer-indented-code and @yozora/tokenizer-fenced-code.
This component has been built into @yozora/react-markdown, you can use it directly.

Install

  • npm

    npm install --save @yozora/react-code-embed
  • yarn

    yarn add @yozora/react-code-embed

Usage

  • Basic:

    import React from 'react'
    import CodeEmbed from '@yozora/react-code-embed'
    import type { ICodeRunnerProps } from '@yozora/react-code-runners'
    
    const JsxRenderer = ({ value }: ICodeRunnerProps): React.ReactElement => {
      // eslint-disable-next-line no-new-func
      const f = new Function(value)
      const v = f()
      return <span data-type="jsx">{ v }</span>
    }
    
    const code = `
      const a = 1 + 2;
      return a * a
    `
    
    const wrapper = (
      <CodeEmbed
        lang="jsx"
        value={ code }
        CodeRenderer={ JsxRenderer }
      />
    )

Props

Name Type Required Default Description
className string false - Root css class
meta Record<string, unknown true - Interpreter for the codes
lang string true - Language of the source codes
runner CodeRunner true - Interpreter for the codes
style React.CSSProperties false - Root css style
value string true - source codes
  • className: The root element of this component will always bind with the CSS class 'yozora-code-embed'.

CSS variables

Name Default value
--yozora-colors-border-error red

Related

Package Sidebar

Install

npm i @yozora/react-code-embed

Weekly Downloads

54

Version

3.0.0-alpha.14

License

MIT

Unpacked Size

29.9 kB

Total Files

7

Last publish

Collaborators

  • lemonclown