
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@loopmode/codeblock
Advanced tools
A react component for code highlighting - based on prismjs and prepared for code-splitting.
import() statements (e.g. create-react-app/webpack/parcel)yarn add @loopmode/codeblock
# or
npm install --save @loopmode/codeblock
The default prism theme is okaidia, the default language is javascript.
Use the theme and language props to override.
Currently, you have to decide on a single theme because the global prism stylesheets interfere with each other. See local themed component for how to specify a theme.
You can use the component much like you would use the <pre> tag. Pass the contents as regular react children.
import React from 'react';
import Codeblock from '@loopmode/codeblock'
export default function InlineContent() {
return (
<Codeblock>{`
class Foo {
constructor(value) {
this.value = value;
}
}
const a = new Foo('a');
const b = new Foo('b');
`}</Codeblock>
);
}
If you specify src, the text will be loaded from that URL and then displayed. If the component is unmounted while it's still loading, the request is aborted.
import React from 'react';
import Codeblock from '@loopmode/codeblock'
export default function ExternalContent() {
return (
<Codeblock src="https://raw.githubusercontent.com/loopmode/codeblock/master/packages/codeblock/src/Codeblock.js" />
);
}
If you need to support older browsers, make sure to provide a fetch polyfill, or provide a custom loadExternal function that does not depend on fetch (e.g using axios, superagent etc).
Currently, each prism theme stylesheet is loaded globally. When you load a second theme, the first one is still loaded and the stylesheets interfere. For this reason, you decide for one theme and stick with it.
In that case, you should create a local component that sets the theme prop and use that component across your project.
Example components/Codeblock:
import React from 'react';
import Codeblock from '@loopmode/codeblock'
export default function ThemedCodeblock(props) {
return (
<Codeblock {...props} theme="twilight" />
);
}
All default prismjs themes and languages are supported and loaded with dynamic import() statements that use /* webpackChunkName */ comments.
When you build your app for production, your final bundle will contain an additional codeblock folder with the theme and language files (codeblock/theme.*.js and codeblock/language.*.js).
FAQs
React component to highlight code using prismjs
The npm package @loopmode/codeblock receives a total of 3 weekly downloads. As such, @loopmode/codeblock popularity was classified as not popular.
We found that @loopmode/codeblock 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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.