How to use react-refractor - 4 common examples

To help you get started, we’ve selected a few react-refractor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github giladv / orkan / src / components / code-block / index.js View on Github external
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Refractor from 'react-refractor'
import jsx from 'refractor/lang/jsx'
// import 'prismjs/themes/prism-twilight'
import {createStyle} from '../../utils/style-utils';

import style from './style';

Refractor.registerLanguage(jsx);






export default class CodeBlock extends Component{
	static propTypes = {
		value: PropTypes.string
	};

	render(){
		const {className, value, ...otherProps} = this.props;
		const s = createStyle(style, className);
		return (
			<div></div>
github ecomfe / react-suspense-boundary / demo / components / SourceCode / index.js View on Github external
import {useReducer, useMemo} from 'react';
import {FaCode} from 'react-icons/fa';
import Refractor from 'react-refractor';
import jsx from 'refractor/lang/jsx';
import tsx from 'refractor/lang/tsx';
import bash from 'refractor/lang/bash';
import 'prism-themes/themes/prism-vs.css';
import c from './index.less';

Refractor.registerLanguage(jsx);
Refractor.registerLanguage(tsx);
Refractor.registerLanguage(bash);

const SourceCode = ({className, source, toggle, language}) =&gt; {
    const [visible, toggleVisible] = useReducer(v =&gt; !v, !toggle);
    const text = useMemo(
        () =&gt; source
            .replace('../../../src', 'react-suspense-boundary')
            .replace(/import SourceCode from.+\n/, '')
            .replace(/\/\/ eslint-disable-next-line import\/no-webpack-loader-syntax.+\n/g, '')
            .replace(/import source from '..\/SourceCode\/loader.+\n/g, '')
            .replace(/\s+ text.split('\n').map((t, i) =&gt; i + 1),
        [text]
github ecomfe / react-suspense-boundary / demo / components / SourceCode / index.js View on Github external
import {useReducer, useMemo} from 'react';
import {FaCode} from 'react-icons/fa';
import Refractor from 'react-refractor';
import jsx from 'refractor/lang/jsx';
import tsx from 'refractor/lang/tsx';
import bash from 'refractor/lang/bash';
import 'prism-themes/themes/prism-vs.css';
import c from './index.less';

Refractor.registerLanguage(jsx);
Refractor.registerLanguage(tsx);
Refractor.registerLanguage(bash);

const SourceCode = ({className, source, toggle, language}) =&gt; {
    const [visible, toggleVisible] = useReducer(v =&gt; !v, !toggle);
    const text = useMemo(
        () =&gt; source
            .replace('../../../src', 'react-suspense-boundary')
            .replace(/import SourceCode from.+\n/, '')
            .replace(/\/\/ eslint-disable-next-line import\/no-webpack-loader-syntax.+\n/g, '')
            .replace(/import source from '..\/SourceCode\/loader.+\n/g, '')
            .replace(/\s+ text.split('\n').map((t, i) =&gt; i + 1),
github ecomfe / react-suspense-boundary / demo / components / SourceCode / index.js View on Github external
import {useReducer, useMemo} from 'react';
import {FaCode} from 'react-icons/fa';
import Refractor from 'react-refractor';
import jsx from 'refractor/lang/jsx';
import tsx from 'refractor/lang/tsx';
import bash from 'refractor/lang/bash';
import 'prism-themes/themes/prism-vs.css';
import c from './index.less';

Refractor.registerLanguage(jsx);
Refractor.registerLanguage(tsx);
Refractor.registerLanguage(bash);

const SourceCode = ({className, source, toggle, language}) =&gt; {
    const [visible, toggleVisible] = useReducer(v =&gt; !v, !toggle);
    const text = useMemo(
        () =&gt; source
            .replace('../../../src', 'react-suspense-boundary')
            .replace(/import SourceCode from.+\n/, '')
            .replace(/\/\/ eslint-disable-next-line import\/no-webpack-loader-syntax.+\n/g, '')
            .replace(/import source from '..\/SourceCode\/loader.+\n/g, '')
            .replace(/\s+

react-refractor

Super-thin React wrapper for refractor (Syntax highlighting using VDOM)

MIT
Latest version published 9 months ago

Package Health Score

63 / 100
Full package analysis

Popular react-refractor functions