Code Block
Display code with a selected theme and regex highlighting using Prism.js.
Install
Install the component from your command line.
Getting Started
Add the component into your email component as follows.
This should render a code-block with the desired theme.
Theming
Themes for this component are basically a set of styles for each kind of token that can result from prismjs’s tokenization. See here for more information on the tokens available.
An example of a theme would be this:
Each token type can have their own defined styles and for each one of there can be any styles that can be applied directly to React
elements.
As you can see from the example dracula
theme though, there is a defined property called base
which is the styling for the pre
element that wraps the HTML being rendered.
For you to not need to defined a theme without any basis, or to not define one that already has been defined, we have many default themes exported from @react-email/code-block
.
These themes were generated by a bit of code that converts a CSS file for a prismjs theme into a object theme of these.
If you want to generate a theme from another existing prismjs theme you can do so by looking into this.
Props
Whether or not to automatically include line numbers on the rendered code block
The font family value to go into the fontFamily: "..."
style for
all used elements of the component
An object representation of a PrismJS CSS theme
The language under the supported languages defined in PrismLanguage
The actual code to render in the code block. Just a plain string, with the proper identation included.
Support
All components were tested using the most popular email clients.
Gmail
Apple Mail
Outlook
Yahoo! Mail
HEY
Superhuman