Code Monkey home page Code Monkey logo

Comments (4)

tomchentw avatar tomchentw commented on July 24, 2024 1

Wow @wooorm ! That's an impressive work!

One thine that concerns me is the usage on browser: https://github.com/wooorm/refractor#browser

I do not suggest using the pre-built files or requiring refractor in the browser as that would include a 250kb (90kb GZipped) file.

Instead, require refractor/core.js, and include only the used highlighters. For example:

Not sure how I should adapt this along with the current PrismCode API.

from react-prism.

tomchentw avatar tomchentw commented on July 24, 2024

Maybe I should provide them two components, one is the original PrismCode component.

The other one would be PrismRefactor component, and the client would have to use it like this:

var refractor = require('refractor/core.js');
var jsx = require('refractor/lang/jsx.js');

refractor.register(jsx);

render(<PrismRefactor>{'JSX CODE'}</PrismRefactor>);

from react-prism.

tomchentw avatar tomchentw commented on July 24, 2024

Even better:

var { PrismRefactor} = require('react-prism');
require('react-prism/register/refractor/lang/jsx'); // Which will call refractor.register(jsx); in that file

render(<PrismRefactor>{'JSX CODE'}</PrismRefactor>);

from react-prism.

wooorm avatar wooorm commented on July 24, 2024

Thank you!

react-syntax-highlighter comes with a β€œlight” build, similar to what you suggested, and I think that that is the best solution:

Normal build

Including all languages.

import {PrismCode} from "react-prism";
// ...

Light build

Includes only core languages.

import {PrismCode, register} from 'react-prism/light';
import js from 'react-prism/lang/javascript';
register(js);
// ...

You could also do the auto-register thing, but then languages need to require the light build themselves, and they won’t export anything, which I personally think is a bit weird, but πŸ€·β€β™‚οΈ

from react-prism.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.