arronhunt / highlightjs-copy

📋❇️ A simple, accessible highlightjs plugin to add a copy button to your code blocks.

Home Page:https://highlightjs-copy.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to import highlightjs-copy in js file after npm install

YavarR opened this issue · comments

commented

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'

commented

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)

I was having a similar issue, and I created a PR to export a default, #21.

The previous change restricts the export to NodeJS environment, which did not work in my case.