Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Modular Syntax highlighting for the web.
The original Prism.js is probably one of the best syntax highlighters ever created for javascript. It's extremely performant, and comes packed with tons of languages that people have worked hard to support. However, it wasn't created to play nice with tomorrow's module bundlers like Webpack, Rollup, or Parcel (despite it's claims to do so). RePrism is the answer to that need.
# yarn
$ yarn add reprism
# npm
$ npm install --save reprism
Reprism's core comes packaged with the same 4 default languages that Prism does:
markup
clike
css
javascript
All you need is a Prism theme and you can use reprism
right away!
import { highlight } from "reprism";
import "prismjs/themes/prism-okaidia.css";
const htmlCode = `
<div>
<ul>
<li className='foo' alt='bar' style="background: red;">
Hello!
</li>
</ul>
</div>
`;
const highlightedCode = reprism(htmlCode, "html");
// <pre class='reprism html language-html'><span class=\\"token tag\\"><span class=\\"token tag\\"><span class=\\"token punctuation\\...
Good news! You can use any prism compatible theme that you want, out of the box. Just make sure the styles are loaded, and you're good to go! You can do this any number of ways using various bundlers and plugins or even traditional <link>
tags.
Here are the themes we recommend:
RePrism supports all of the same languages that Prism does, but they have been upgraded to play nicely with bundlers. Click here for the complete directory of updated languages.
To use these languages, simply import them and load them using RePrism's loadLanguages
export. Here's an example of loading the jsx
syntax and using it:
import { highlight, loadLanguages } from "reprism";
import jsx from "reprism/lanugages/jsx";
loadLanguages(jsx);
const jsxCode = `
const element = (
<div>
<ul>
{items.map(item => (
<li key={item.id} className='foo'>
{item.name}
</li>
))}
</ul>
</div>
)
`;
const highlightedCode = reprism(jsxCode, "jsx");
// <pre class='reprism jsx language-jsx'<span class=\\"token keyword\\">const</span> element <span class=\\"token operator\\">=</span> <span class=\\"token punctuation\\">(</span>...
As long as they are used strictly in the browser, most original Prism plugins should work just fine as long as you provide them the global Prism
object:
// Import the Prism Api
import Prism from "reprism";
// When in the browser
if (typeof document !== "undefined") {
// Provide window.Prism for plugins
window.Prism = Prism;
require("prismjs/plugins/copy-to-clipboard");
}
If you have a language that wasn't already ported from the original Prism list, then you can easily upgrade it to work with RePrism like so:
export default {
language: "yourLanguageID",
init: Prism => {
// Insert your original Prism language code
}
};
That's it!
highlight
Use this method to highlight a string of code.
code: String (Required)
- The string of code you want to highlightlanguage: String (Required)
- The language you want to use to parse the code.component: String|Boolean
- Defaults to pre
. The html tag RePrism should use to wrap the source code. If set to false
, the source code will not be wrapped in any element.String
- The resulting HTML markup for your code as a String
, wrapped in a <pre>
tag.import { highlight } from "reprism";
const highlightedCode = highlight("...", "javascript");
loadLanguages
Use this method to load languages into RePrism
...languages
or languages[]
- The languages you want to load. You can pass them as paramaters, or as an array.import { loadLanguages } from "reprism";
import jsx from "reprism/languages/jsx";
import elixir from "reprism/languages/elixir";
import ruby from "reprism/languages/ruby";
loadLanguages(jsx, elixir, ruby);
// or
loadLanguages([jsx, elixir, ruby]);
Prism
The global export used almost exclusively for Plugin backwards compatibility. Expose this as a global variable for plugins to work properly
import Prism from "reprism";
if (typeof document !== "undefined") {
window.Prism = Prism;
require("prismjs/plugins/copy-to-clipboard");
}
FAQs
Modular Syntax highlighting for the web
The npm package reprism receives a total of 29,370 weekly downloads. As such, reprism popularity was classified as popular.
We found that reprism 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.