Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
ink-prism
Advanced tools
Readme
Syntax highlighting component for Ink, powered by Prism.
$ npm i ink-prism
const React = require("react")
const Ink = require("ink")
const { Code } = require("ink-prism")
const code = `
const React = require("react")
const Ink = require("ink")
const { Code } = require("ink-prism")
Ink.render(
<Code language="js">
console.log("Syntax highlighting!")
</Code>
)`
Ink.render(<Code language="js">{code}</Code>)
The only component; its content's syntax will be highlighted.
The language to highlight the code as. It will be automatically hyphen-case
d, so you can use camelCase
if you want to.
string
See loadLanguage()
.
The theme to highlight the code with.
string
"prism"
See loadTheme()
.
The number of spaces to replace all tab (\t
) characters with, if any.
number
4
Whether to "fill" remaning space after every newline, as to make the background color show as a block, instead of as the shape of the text.
boolean
true
This component also has 7 other properties which are not listed individually; paddingTop
, paddingBottom
, paddingLeft
, paddingRight
, paddingX
, paddingY
and padding
. You can either guess what these do, or check out Ink's Box's padding props.
number
0
By default, only a few languages are loaded into memory; markup
, (alias: html
, mathml
, svg
, xml
, ssml
, atom
, rss
), css
, clike
, and javascript
(alias: js
).
Use this method to load one of the built-in languages into memory.
This method is synchronous. Currently, there is no way to load languages asynchronously.
The name of the language to load. It will be automatically hyphen-case
d, so you can use camelCase
if you want to.
string
Load all of the built-in languages into memory. Make sure you actually want to use this method, as there are a lot of languages (more than 200).
This method is synchronous. Currently, there is no way to load languages asynchronously.
Create a language with your own grammar definitions.
The name of the language to add.
string
The grammar object of the language.
Prism.Grammar
The name of an existing language to extend.
string
undefined
By default, only the prism
theme is loaded into memory. Use this method to load one of the built-in themes into memory.
This method is synchronous. Currently, there is no way to load themes asynchronously.
The name of the language to load.
string
Load all of the built-in themes into memory. There aren't that many built-in themes, so this shouldn't pose serious performance issues, though it should still not be necessary in normal circumstances.
This method is synchronous. Currently, there is no way to load themes asynchronously.
Create a theme with your own colors.
The name of the theme to add.
string
The theme data.
Theme
Themes in ink-prism
are defined differently from Prism themes, as you can't really use CSS in Ink.
First of all, all colors must be in hex format (#RGB
, #RGBA
, #RRGGBB
, or #RRGGBBAA
). The theme must have a background
property, defining the background color. Then, a color
property, which will be used for all non-highlighted (default) text.
Finally, a tokens
property, mapping every token name (comment
, punctuation
, function
, ...) to its color. These colors can not only be a plain string, but also an object containing the bold
or italic
boolean properties.
Here's an example. (There are more tokens than that; they were removed for the sake of simplicity):
module.exports = {
background: "#f5f2f0",
color: "#000000",
tokens: {
comment: { italic: true, color: "#708090" },
namespace: "#000000b3", // rgba(0, 0, 0, 0.7)
bold: { bold: true, color: "#000" },
italic: { italic: true, color: "#000" }
}
}
Here's the full version of the default theme, Prism. Check out the other built-in themes for more examples, and feel free to make a Pull Request with any themes you want to add into this module!
FAQs
Syntax highlighting component for [Ink][], powered by [Prism][].
The npm package ink-prism receives a total of 0 weekly downloads. As such, ink-prism popularity was classified as not popular.
We found that ink-prism 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.