angular-highlightjs icon indicating copy to clipboard operation
angular-highlightjs copied to clipboard

dependency on highlight.js issue

Open a-birla opened this issue 7 years ago • 9 comments

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?

a-birla avatar Sep 28 '17 04:09 a-birla

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

pc035860 avatar Sep 28 '17 05:09 pc035860

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 avatar Sep 28 '17 05:09 a-birla

screen shot 2017-09-27 at 10 12 17 pm this is the folder structure

a-birla avatar Sep 28 '17 05:09 a-birla

@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');

pc035860 avatar Sep 28 '17 06:09 pc035860

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 [email protected] 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.

a-birla avatar Sep 28 '17 07:09 a-birla

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.

pc035860 avatar Sep 28 '17 08:09 pc035860

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

Uncaught ReferenceError: require is not defined

a-birla avatar Sep 28 '17 17:09 a-birla

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.

pc035860 avatar Sep 29 '17 04:09 pc035860

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

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

chathurabuddi avatar Jun 20 '19 08:06 chathurabuddi