
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
copy-container-react
Advanced tools
Use this component to display code with syntax highlighting and a clipboard users can click to copy the code to their clipboard. The design is based on OpenAI's component in ChatGPT, and can be styled further.
Use this component to display code with syntax highlighting and a clipboard users can click to copy the code to their clipboard. The design is based on OpenAI's component in ChatGPT, and can be styled further.
The component can also be used to display text without syntax highlighting.
import { CopyContainer } from 'copy-container-react'
function App(){
return(
<CopyContainer lang='python'>
{`import requests
from bs4 import BeautifulSoup
def crawl(url):
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
for title in soup.find_all('h2'): # assuming titles are within h2 tags
print(title.get_text())
crawl('http://www.blogsite.com')
`}
</CopyContainer>
)
}
Your text needs to be within braces (to embed JS in JSX) within grave accent marks (to start a multiline string) and needs to be a child of CopyContainer, as shown above. Spacing (tabs, index, new lines, etc.) in the multi-line string is preserved. It would be nice if the pasted text could start on the line after the grave accent so it would look nice in the code, but an extra new line would appear in your UI. The existing solution is likely the best we can do :)
All props can be omitted. Here's an example which uses all the props:
import { CopyContainer } from 'copy-container-react'
function App(){
return(
<CopyContainer lang='python' highlight={true} copyText='Copy :)' copiedText='Yay :)'>
{`import requests
from bs4 import BeautifulSoup
def crawl(url):
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
for title in soup.find_all('h2'): # assuming titles are within h2 tags
print(title.get_text())
crawl('http://www.blogsite.com')
`}
</CopyContainer>
)
}
Name | Type | Default | Required | Description |
---|---|---|---|---|
lang | String | '' | No | Display the a string in the top left corner and pass the language to highlight.js so it doesn't need to guess. |
highlight | Boolean | true | No | Enable syntax highlighting. |
copyText | String | Copy Code | No | Text beside the clipboard before it is clicked. |
copiedText | String | Copied! | No | Text beside the clipboard after it is clicked. |
To use a different style from the default, import one from this link: https://github.com/highlightjs/highlight.js/tree/main/src/styles like so:
import 'highlight.js/styles/a11y-light.css';
Syntax highlighting styles and overriding CSS will likely interfere with each other so be careful if you choose to do both.
Use the following classes in your own css to style parts of the UI.
.text-lang{}, .text-copy{}, .top-bar{}, .code-body{}, .check{}, .clipboard{}
Let me know if anything should be added. If you want to style an element yourself you could use devtools to figure out a css selector.
Here's an example of the CSS used for the screenshot with the green top bar in the 'How it looks' section:
.clipboard{
stroke: #C71585;
}
.top-bar{
background-color: #3CB371;
}
.text-body{
background-color: whitesmoke;
}
The syntax highlighting library used by this component is highlight.js and the style is stackoverflow-dark.css. Highlight.js tries to automatically detect the programming language of the code, but it hasn't been correct in my experience, though I could be doing something wrong and appreciate their library very much. See their docs for more information (you can examine the highlightjs object to see confidence scores the library gives for its predictions).
Please open an issue on github or email adam.p.zakaria at gmail dot com with any questions or comments :)
FAQs
Use this component to display code with syntax highlighting and a clipboard users can click to copy the code to their clipboard. The design is based on OpenAI's component in ChatGPT, and can be styled further.
The npm package copy-container-react receives a total of 19 weekly downloads. As such, copy-container-react popularity was classified as not popular.
We found that copy-container-react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.