Import Atom syntax highlighting dependency


I would like to use Atom’s syntax-highlighting within a custom Atom package. However, I don’t want to re-require the package as a dependency. I’m looking to recreate the functionality of the markdown-preview package inside of a larger Atom package.

Currently this is accomplished like so:

// goal: require atom's version of 'highlights' here:
import * as Highlights from 'highlights'; 

const highlighter = new Highlights({registry: atom.grammars});

// goal: sub this function for a native atom highlighter
function highlight(code, lang) {
  return highlighter.highlightSync({
    fileContents: code,
    scopeName: 'source.' + (lang || 'js')


Requiring ‘highlights’ as a package means my package also requires ‘node-gyp’, which leads to a headache of node-gyp installation failures for Windows users and frequent apm rebuild issues – all trailing back to node-gyp. If ‘node-gyp’ can be avoided, it should be.

Things that don’t work:

  • ‘atom-package-dependencies’ requires ‘shell-js’ which also requires ‘node-gyp’
  • ‘atom-package-deps’ is for requiring other atom packages, not their dependencies

Things that might work:

  • Is it possible to require the same syntax highlighting, as is handled by core atom packages like the text-editor and ‘markdown-preview’?
  • is it possible to simply apply syntax highlighting through some kind of grammar highlighting function?


What is your ultimate goal here? What kind of package are you trying to build? If you’re trying to recreate the functionality of the markdown-preview package, have you looked at the source for the markdown-preview package?


The package

Markdown preview simply loads ‘highlights’ as a package dependency.

 "dependencies": {
    "highlights": "^1.2"

I’d like to load that existing dependency, or run Atom’s existing highlighter. Atom has a smooth installer, and I’d rather not create a Windows installer due to ‘node-gyp’.