Gathering detailed insights and metrics for react-code-blocks
Gathering detailed insights and metrics for react-code-blocks
Gathering detailed insights and metrics for react-code-blocks
Gathering detailed insights and metrics for react-code-blocks
@discostudioteam/react-code-blocks
Modified rajinwonderland's modification of Atlaskit's Code Block!
react-code-block
Set of unstyled UI components to build powerful code blocks in React.
@milessystems/react-code-blocks
Modified Atlaskit's Code Block to support more languages (i.e graphql, reasonml, etc) and theme (i.e railscast, dracula, monokai, etc) code snippets!
react-code-blocks-typing
Modified react-code-blocks code to allow for a typing animation, that is the only reason to use this.
npm install react-code-blocks
Typescript
Module System
Min. Node Version
Node Version
NPM Version
87.1
Supply Chain
92.2
Quality
75.1
Maintenance
50
Vulnerability
100
License
Total Downloads
8,254,492
Last Day
4,353
Last Week
89,586
Last Month
393,874
Last Year
3,613,217
Minified
Minified + Gzipped
Latest Version
0.1.6
Package Id
react-code-blocks@0.1.6
Unpacked Size
840.72 kB
Size
156.46 kB
File Count
146
NPM Version
9.8.1
Node Version
18.18.2
Published on
Jan 18, 2024
Cumulative downloads
Total Downloads
Last Day
-7.3%
4,353
Compared to previous day
Last Week
-6.6%
89,586
Compared to previous week
Last Month
-0.9%
393,874
Compared to previous month
Last Year
64.2%
3,613,217
Compared to previous year
1
30
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
1yarn add react-code-blocks
1npm i react-code-blocks
Updated usage instructions can be found here
1import { CopyBlock } from 'react-code-blocks';
1function MyCodeComponent(props) { 2 return ( 3 <CopyBlock 4 text={props.code} 5 language={props.language} 6 showLineNumbers={props.showLineNumbers} 7 wrapLines 8 /> 9 ); 10}
A simple code block component
1import { CodeBlock, dracula } from 'react-code-blocks'; 2 3function MyCoolCodeBlock({ code, language, showLineNumbers }) { 4 return ( 5 <CodeBlock 6 text={code} 7 language={language} 8 showLineNumbers={showLineNumbers} 9 theme={dracula} 10 /> 11 ); 12}
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.
1import { CopyBlock, dracula } from 'react-code-blocks'; 2 3function MyCoolCodeBlock({ code, language, showLineNumbers }) { 4 <CopyBlock 5 text={code} 6 language={language} 7 showLineNumbers={showLineNumbers} 8 theme={dracula} 9 codeBlock 10 />; 11}
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
react-code-blocks is currently maintained by Thomas
Thanks goes to these wonderful people (emoji key):
Taha HICHRI 💻 | florpor 🐛 | Abdollah Keshtkar 💡 📖 💻 | Lukas Bals 💻 | Bobby Wang 💻 | Matthew Peveler 📖 | Dacey Nolan 💡 📖 💻 |
Kevin Eaton 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
No vulnerabilities found.
No security vulnerabilities found.