How to use the refractor.register function in refractor

To help you get started, we’ve selected a few 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 mozilla / addons-code-manager / src / refractor / index.tsx View on Github external
import refractor from 'refractor';

import text from './text-language';
import './prism.css';
import './prism.overrides.scss';

// This is needed to provide a fallback in `getLanguage()` when the mime type
// has no corresponding syntax highlighting language.
refractor.register(text);

export default refractor;
github benawad / codeponder / packages / web / utils / highlightCode.ts View on Github external
const getHast = (code: string, lang: string): RefractorNode[] | null => {
  if (!lang) return null;
  if (!refractor.registered(lang)) {
    try {
      refractor.register(require(`refractor/lang/${lang}.js`));
    } catch (ex) {}
  }
  if (refractor.registered(lang)) {
    return refractor.highlight(code, lang);
  }
  return null;
};

refractor

Lightweight, robust, elegant virtual syntax highlighting using Prism

MIT
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis