pc035860 / angular-highlightjs

AngularJS directive for syntax highlighting with highlight.js
http://pc035860.github.io/angular-highlightjs/example/
MIT License
294 stars 53 forks source link

dependency on highlight.js issue #88

Open a-birla opened 6 years ago

a-birla commented 6 years ago

as this module has dependency on highlight.js, if I install highlight.js via npm and give the path of the js file created under node_modules and install angular-highlightjs via npm/bower, it does not highlight any content. but if I use the cdn copy of highlight.js or build it locally myself, then it highlights content very well. What is the issue here?

pc035860 commented 6 years ago

@a-birla Can you provide error messages for the node_modules setup? Did it bundle highlight.js package correctly?

a-birla commented 6 years ago

in the highlight.js package, I have one highlight.js file inside lib folder. If I reference that in my script, it does not apply any highlighting. There are errors when I try to use

Uncaught Error: Unknown language: "bash" at Object.highlight (concat_vendor.js?t=1506575342991:494) at Object.j._highlight (concat_vendor.js?t=1506575342991:57380) at h (concat_vendor.js?t=1506575342991:57380)

Also I checked the highlight.js file on https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js is very different from what is downloaded when I do npm install highlight.js

a-birla commented 6 years ago
screen shot 2017-09-27 at 10 12 17 pm

this is the folder structure

pc035860 commented 6 years ago

@a-birla CDN version might already have languages registered. Looks like npm version has the languages registered in libs/index.js.

Usually you'll require highlight.js with

const hljs = require('highlight.js');
// This actually point to require('./path/to/node_modules/highlight.js/lib/index.js')
// which is defined in `package.json` key `main`

rather than require('./path/to/node_modules/highlight.js/lib/highlight.js');

a-birla commented 6 years ago

So in the gulp task where we are concatenating all node modules js files, we give the path only for Index.js and not highlight.js?

On Sep 27, 2017, at 11:10 PM, Chih-Hsuan Fan notifications@github.com wrote:

@a-birla CDN version might already have languages registered. Looks like npm version has the languages registered in libs/index.js.

Usually you'll require highlight.js with

const hljs = require('highlight.js'); // This actually point to require('./path/to/node_modules/highlight.js/lib/index.js') // which is defined in package.json key main rather than require('./path/to/node_modules/highlight.js/lib/highlight.js');

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

pc035860 commented 6 years ago

So you're using gulp to concatenate js files rather than bundlers like webpack, rollup etc? Try node_modules/highlight.js/lib/index.js then.

a-birla commented 6 years ago

no that is not working either. If I only reference index.js, getting this error

Uncaught ReferenceError: require is not defined

pc035860 commented 6 years ago

It seems that the npm version still requires a build procress to work if you're not using a CommonJS compatible bundler.

I'd suggest just use the CDN version or integrate the highlight.js build process into your gulp task.

chathurabuddi commented 5 years ago

if you are using highlight.js npm repository, try changing it to highlightjs repository. Worked for me.

https://www.npmjs.com/package/highlightjs