🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

bs-react-syntax-highlighter

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bs-react-syntax-highlighter

ReasonML bindings for react-syntax-highlighter library

0.2.0
Source
npm
Version published
Weekly downloads
20
66.67%
Maintainers
1
Weekly downloads
 
Created
Source

bs-react-syntax-highlighter

Build Status dependencies Status Greenkeeper badge

ReasonML bindings for react-syntax-highlighter library.

Installation

npm i --save bs-react-syntax-highlighter react-syntax-highlighter

Then add bs-react-syntax-highlighter as a dependency to bsconfig.json.

Usage

Unlike in the JavaScript counterpart, there is no default highlighter - you have to choose Hljs or Prism explicitly.

[@react.component]
let make = () => {
  <ReactSyntaxHighlighter.Prism style={ReactSyntaxHighlighter.Prism.Style.darcula}>
    {"A code to highlight"}
  </ReactSyntaxHighlighter.Prism>;
};
[@react.component]
let make = () => {
  <ReactSyntaxHighlighter.Hljs language={`JavaScript}>
    {"const foo = () => {};"}
  </ReactSyntaxHighlighter.Hljs>;
};

Props spread

In JavaScript, there is a possibility to put any property you like on the root element rendered by the component, by simply putting it on a component. It's called "props spread". react-syntax-highlighter supports that pattern as well. ReasonML simply can't do it.

Quite nice escape hatch is wrapping the component you wish to spread props on in another component (HOC or High-Order Component), which will inject all passed properties to its child in a not type-safe, but quite an efficient way. source. There is a runtime cost for this operation, though, so I've decided to not include such code in this library. Pay the cost only when you need to.

module Spread = {
  [@react.component]
  let make = (~props, ~children) =>
    ReasonReact.cloneElement(children, ~props, [||]);
};

<Spread props={"id": "foobar"}>
  <ReactSyntaxHighlighter.Hljs language={`JavaScript}>
    {"const foo = () => {};"}
  </ReactSyntaxHighlighter.Hljs>;
</Spread>

For convenience I've included just one such a generic property in component bindings: className.

JSX 2

The package provides fallback for projects using older version of JSX syntax.

[@react.component]
let make = () => {
  <ReactSyntaxHighlighter.Hljs.Jsx2 language={`JavaScript}>
    ...{"const foo = () => {};"}
  </ReactSyntaxHighlighter.Hljs.Jsx2>;
};

Notes

An async build and a light build are not currently supported. PRs are welcome!

Keywords

reason

FAQs

Package last updated on 04 Jan 2020

Did you know?

Socket

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.

Install

Related posts