Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
bend-react-code-blocks
Advanced tools
Modified Atlaskit's Code Block to support more languages (i.e graphql, reasonml, etc) and theme (i.e railscast, darcula, monokai, etc) code snippets!
react-code-blocks
👋👋👋React components for rendering code snippets with syntax highlighting
BREAKING CHANGES:
VERSION >= 0.0.8-alpha
now requires a nodejs version >= 12
Initially, this started as a small project looking to modify Atlaskit's Code Block component to support more languages (i.e graphql
, reasonml
, etc). It then rapidly evolved into a never-ending rabbithole which ended up with support for themes (i.e railscast, darcula, monokai, etc), customizable styles, and copy functionality too!
I don't plan on keeping this updated unless people are looking to actually use it. So don't be shy! Feel free to post an issue or a pr.
Install react-code-blocks
via yarn
or npm
yarn add react-code-blocks
npm i react-code-blocks
Updated usage instructions can be found here
import { CopyBlock } from "react-code-blocks";
function MyCodeComponent(props) {
return (
<CopyBlock
text={props.code}
language={props.language}
showLineNumbers={props.showLineNumbers}
wrapLines
/>
);
}
A simple code block component
import { CodeBlock, dracula } from "react-code-blocks";
function MyCoolCodeBlock({ code, language, showLineNumbers }) {
return (
<CodeBlock
text={code}
language={language}
showLineNumbers={showLineNumbers}
theme={dracula}
/>
);
}
Note that
CodeBlock
&CopyBlock
share exactly the same props
name | type | default | description |
---|---|---|---|
text | string | required | The code to be formatted |
language | string | "text" | The language in which the code is written. See here for a list of supported languages |
showLineNumbers | boolean | true | Indicates whether or not to show line numbers |
theme | object | dracula | A theme object for the code block. See here for a list of supported themes |
highlight | string | "" | Lines to highlight! For multiple lines, use a comma i.e highlight="1,6,7" . For a range of lines, use a - i.e highlight="1-5" for highlighting lines 1-5. |
more to come...
A code block component with a little copy button for copying a snippet.
import { CopyBlock, dracula } from "react-code-blocks";
function MyCoolCodeBlock({ code, language, showLineNumbers }) {
<CopyBlock
text={code}
language={language}
showLineNumbers={showLineNumbers}
theme={dracula}
codeBlock
/>;
}
Same as the CodeBlock
's component with the exception of one!
name | type | default | description |
---|---|---|---|
codeBlock | boolean | false | Indicates whether to render the CopyBlock as an inline Code component or a CodeBlock component |
onCopy | function | - | The onCopy function is called if the copy icon is clicked. This enables you to add a custom message that the code block is copied |
For a list of supported themes, check out the list here
For a list of supported languages, check out the list here
If you're looking for some more maintained solutions, I'd suggest the following:
react-syntax-highlighter
: syntax highlighting component for react with prismjs
or highlightjs
ast
using inline styles by @conorhastings.
react-highlight.js
: A lightweight React wrapper around the Highlight.js
syntax highlighting library by @bvaughn.react-live
: A flexible playground for live editing React components by @FormidableLabs.@atlaskit/code
: Renders inline code snippets and code blocks
carbon-components-react
: Check out their <CodeSnippet>
component which supports multi-line, single-line, and inline snippets along with added copying functionality.Feel free to add any other alternative packages here! :smile:
MDX
Code
componentGive a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator
FAQs
Modified Atlaskit's Code Block to support more languages (i.e graphql, reasonml, etc) and theme (i.e railscast, darcula, monokai, etc) code snippets!
The npm package bend-react-code-blocks receives a total of 0 weekly downloads. As such, bend-react-code-blocks popularity was classified as not popular.
We found that bend-react-code-blocks 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.