Giter Site home page Giter Site logo

arronhunt / highlightjs-copy Goto Github PK

View Code? Open in Web Editor NEW
87.0 4.0 23.0 91 KB

πŸ“‹β‡οΈ A simple, accessible highlightjs plugin to add a copy button to your code blocks.

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

License: The Unlicense

CSS 40.17% JavaScript 59.83%
highlightjs syntax-highlighting

highlightjs-copy's Introduction

Welcome to my GitHub

I hope you enjoy your stay

✨ My interests

highlightjs-copy's People

Contributors

arronhunt avatar hugoderre avatar jdseus avatar mistervector avatar radamuz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

highlightjs-copy's Issues

Nextjs13 - ReferenceError: self is not defined

I'm trying to integrate this into my nextjs13 site in a markdown file that renders blocks of rich text from my headless CMS, i'm using app router. This is probably do to my lack of knowledge with SSR but thought i'd ask here before giving up.

'use client'
import hljs from 'highlight.js';
import CopyButtonPlugin from 'highlightjs-copy';
hljs.addPlugin(new CopyButtonPlugin());

[BLOCKS.EMBEDDED_ENTRY]: (node) => {
                const entryId = node.data.target.sys.id;
                const entry = description.links.entries.block.find(e => e.sys.id === entryId);
                if (!entry) return null;
                const highlightedCode = hljs.highlight(entry.code, { language: entry.language }).value;
                return (
                    <div className='syntax-custom overflow-x-auto my-10'>
                        <p className="text-tiny uppercase font-bold mb-1 text-danger">{entry.language}</p>
                        <pre className='text-sm hljs-copy-wrapper'>
                            <code dangerouslySetInnerHTML={{ __html: highlightedCode }} />
                        </pre>
                    </div>
                );
            }

Error:

ReferenceError: self is not defined
at eval (./lib/markdown.tsx:34:64)
at (ssr)/./lib/markdown.tsx (/folder/.next/server/app/projects/[slug]/page.js:226:1)
at webpack_require (/folder/.next/server/webpack-runtime.js:33:43)
null

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

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'

Uncaught ReferenceError when importing in browser environment

Hello @arronhunt,

I've encountered an issue while using the 'highlightjs-copy' library on my non-Node.js website. I'm loading the library as instructed in the README file:

<script src="https://unpkg.com/highlightjs-copy/dist/highlightjs-copy.min.js"></script>

However, doing so leads to an error in the console:

Uncaught ReferenceError: module is not defined
https://unpkg.com/highlightjs-copy/dist/highlightjs-copy.min.js:1

It seems the library is utilizing the Node.js module.exports syntax, which isn't supported in a browser environment, causing the ReferenceError.

I believe this issue surfaced after the latest 1.0.4 update. Before this update, I didn't encounter such an issue.

Thank you for your time and consideration.

Doesn't work

When click on icon, nothing has changed. Why? No errors in console

Copy icon for lighter themes

Currently this plugin only correctly styles dark-themed code boxes. If I try to use a lighter style, the copy icon does not show up but it still exists in the markup.

Just copy one line

Is it possible to copy only one line, because there are many times when we only need a line in a large block of code?

This library does not work

Uncaught TypeError: highlightjs_copy__WEBPACK_IMPORTED_MODULE_3___default(...) is not a function
followed:

import CopyButtonPlugin from "highlightjs-copy";
hljs.addPlugin( new CopyButtonPlugin());

TypeScript Support

Please add TypeScript types!

This seems awesome, but unusable for me without types.

Thanks for writing this!

J

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.