atom / highlights

Syntax highlighter
https://atom.github.io/highlights
MIT License
530 stars 54 forks source link

added the method requireGrammarsSync() for loading grammars from npm modules #14

Closed bcoe closed 9 years ago

bcoe commented 9 years ago

I've added the method requireGrammarsSync(), for loading a grammar into the registry from an npm module. This is super useful when using highlights as a stand-alone library, and allows grammars to be published to npm for just this purpose.

FYI, we recently switched to highlights as our syntax highlighter for npm. awesome work!

screen shot 2015-01-30 at 12 15 20 am

bcoe commented 9 years ago

@kevinsawicki pull request updated, thanks for the quick code-review I'm giving a demo of highlights to everyone at npm today this will add a lot of razzmatazz.

bcoe commented 9 years ago

@kevinsawicki hold off on merging this, I found something that needs to be patched related to where modules are included from.

bcoe commented 9 years ago

The problem is that require.resolve() always resolves to highlights' node_modules folder, perhaps instead use `path.resolve(__dirname, '../', 'node_modules', moduleName). I'll ask @isaacs if there's a better approach.

bcoe commented 9 years ago

Based on a in-the-air conversation with @isaacs regarding trusting __dirname, i.e., you should not, I think this is a good fix:

highlighter.requireGrammarsSync({
  modulePath: require.resolve('atom-language-dart')
})

I'd say this is ready to go.

bcoe commented 9 years ago

@kevinsawicki okay I think this is actually close to ready to go now, to summarize:

highlighter.requireGrammarsSync({
  modulePath: require.resolve('atom-language-dart/package.json')
})

The nice thing about this is that the existing atom language modules have package.json files, so existing grammars can be published to npm with no modifications.

Thanks for your patience.

kevinsawicki commented 9 years ago

Thanks for this, published in 1.1.0