Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
YavarR opened this issue Oct 4, 2022 · 2 comments
Open

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

YavarR opened this issue Oct 4, 2022 · 2 comments

Comments

@YavarR
Copy link

YavarR commented Oct 4, 2022

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'

@pep108
Copy link

pep108 commented Oct 13, 2022

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)

@nmangold
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants