How to use the refractor.registered 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 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;
};
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