how to import highlightjs-copy in js file after npm install
YavarR opened this issue · comments
Hi Arron
I installed highlightjs-copy, But I can’t import it after npm install.
Could you pleas help me.
I already instals highlight.js and it works perfectly.
That is for highlight.js:
import hljs from 'highlight.js/lib/core'; import 'highlight.js/styles/base16/railscasts.css'; import javascript from 'highlight.js/lib/languages/javascript'
I had the same problem with this. I ended up adding the file to my repo and changing the first line to:
module.exports = class CopyButtonPlugin {
Then I included it with:
const CopyButtonPlugin = require('./vendor/highlightjs-copy.js')
To initialize, I wrapped the code in a timeout because I found that it wouldn't work in Chrome otherwise:
setTimeout(() => { hljs.addPlugin(new CopyButtonPlugin()) hljs.highlightAll() }, 100)