How to use the react-diff-view/tokenize.tokenize function in react-diff-view

To help you get started, we’ve selected a few react-diff-view 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 otakustay / react-diff-view / site / components / DiffView / Tokenize.worker.js View on Github external
const enhancers = [
            editsType === 'none' ? null : markEdits(hunks, {type: editsType}),
            markWord('\r', 'carriage-return', '␍'),
            markWord('\t', 'tab', '→'),
        ];

        const options = {
            highlight: language !== 'text',
            refractor: refractor,
            language: language,
            oldSource: oldSource,
            enhancers: compact(enhancers),
        };

        try {
            const tokens = tokenize(hunks, options);
            const payload = {
                success: true,
                tokens: tokens,
            };
            self.postMessage({id, payload});
        }
        catch (ex) {
            const payload = {
                success: false,
                reason: ex.message,
            };
            self.postMessage({id, payload});
        }
    }
);