Socket
Socket
Sign inDemoInstall

next-prism

Package Overview
Dependencies
1
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    next-prism

A lightweight, robust, and elegant syntax highlighting component for your next React apps.


Version published
Weekly downloads
10
decreased by-41.18%
Maintainers
1
Created
Weekly downloads
Β 

Changelog

Source

0.5.0 (2022-12-18)

✨ Features

  • Add autolinker plugins

Credits

  • @Bunlong

Readme

Source

next-prism

A lightweight, robust, and elegant syntax highlighting component for your next React apps.

NPM npm bundle size JavaScript Style Guide

🎁 Features

  • Themes
  • Languages
  • Plugins

πŸ”§ Install

next-prism is available on npm. It can be installed with the following command:

npm install next-prism --save

next-prism is available on yarn as well. It can be installed with the following command:

yarn add next-prism

πŸ’‘ Usage

πŸŽ€ Code

import { usePrism } from 'next-prism'

// Import a theme.css
import 'next-prism/themes/tomorrow.css'

export default function App() {
  const { Code } = usePrism()

  return (
    <Code language='javascript'>
      {`<div className="example">
  {Math.random()}
</div>`}
    </Code>
  )
}

πŸŽ€ highlightAll

import { useState, useEffect } from 'react'
import { usePrism } from 'next-prism'

// Import a theme.css
import 'next-prism/themes/tomorrow.css'

function App() {
  const [count, setCount] = useState(0)
  const { Code, highlightAll } = usePrism()

  useEffect(() => {
    highlightAll()
  }, [count])

  return (
    <>
      <button onClick={() => setCount(count + 1)}>Click me</button>
      <p>You clicked {count} times</p>
      <Code language='javascript'>{`<p>You clicked ${count} times<p>`}</Code>
    </>
  )
}

usePrism Return Object

PropTypeDescription
CodeReactNodeCode component.
highlightAllfunctionUse to highlight all code elements.

Code Props

PropTypeDefaultRequireDescription
children || contentReactNode❌The content code
languagestring❌The supported language

Themes

coydark
funkyokaidia
prismsolarizedlight
tomorrowtwilight

Languages

Markup - markup, html, xml, svg, mathml, ssml, atom, rssCSS - css
JavaScript - javascript, jsC-like - clike
ABAP - abapABNF - abnf
ActionScript - actionscriptAda - ada
Agda - agdaAL - al
ANTLR4 - antlr4, g4Apache Configuration - apacheconf
Apex - apexAPL - apl
AppleScript - applescriptAQL - aql
Arduino - arduino, inoARFF - arff
ARM Assembly - armasm, arm-asmArturo - arturo, art
AsciiDoc - asciidoc, adocASP.NET (C#) - aspnet
6502 Assembly - asm6502Atmel AVR Assembly - asmatmel
AutoHotkey - autohotkeyAutoIt - autoit
AviSynth - avisynth, avsAvro IDL - avro-idl, avdl
AWK - awk, gawkBash - bash, sh, shell
BASIC - basicBatch - batch
BBcode - bbcode, shortcodeBBj - bbj
Bicep - bicepBirb - birb
Bison - bisonBNF - bnf, rbnf
BQN - bqnBrainfuck - brainfuck
BrightScript - brightscriptBro - bro
BSL (1C:Enterprise) - bsl, oscriptC - c
C# - csharp, cs, dotnetC++ - cpp
CFScript - cfscript, cfcChaiScript - chaiscript
CIL - cilCilk/C - cilkc, cilk-c
Cilk/C++ - cilkcpp, cilk-cpp, cilkClojure - clojure
CMake - cmakeCOBOL - cobol
CoffeeScript - coffeescript, coffeeConcurnas - concurnas, conc
Content-Security-Policy - cspCooklang - cooklang
Coq - coqCrystal - crystal
CSS Extras - css-extrasCSV - csv
CUE - cueCypher - cypher
D - dDart - dart
DataWeave - dataweaveDAX - dax
Dhall - dhallDiff - diff
Django/Jinja2 - django, jinja2DNS zone file - dns-zone-file, dns-zone
Docker - docker, dockerfileDOT (Graphviz) - dot, gv
EBNF - ebnfEditorConfig - editorconfig
Eiffel - eiffelEJS - ejs, eta
Elixir - elixirElm - elm
Embedded Lua templating - etluaERB - erb
Erlang - erlangExcel Formula - excel-formula, xlsx, xls
F# - fsharpFactor - factor
False - falseFirestore security rules - firestore-security-rules
Flow - flowFortran - fortran
FreeMarker Template Language - ftlGameMaker Language - gml, gamemakerlanguage
GAP (CAS) - gapG-code - gcode
GDScript - gdscriptGEDCOM - gedcom
gettext - gettext, poGherkin - gherkin
Git - gitGLSL - glsl
GN - gn, gniGNU Linker Script - linker-script, ld
Go - goGo module - go-module, go-mod
Gradle - gradleGraphQL - graphql
Groovy - groovyHaml - haml
Handlebars - handlebars, hbs, mustacheHaskell - haskell, hs
Haxe - haxeHCL - hcl
HLSL - hlslHoon - hoon
HTTP - httpHTTP Public-Key-Pins - hpkp
HTTP Strict-Transport-Security - hstsIchigoJam - ichigojam
Icon - iconICU Message Format - icu-message-format
Idris - idris, idr.ignore - ignore, gitignore, hgignore, npmignore
Inform 7 - inform7Ini - ini
Io - ioJ - j
Java - javaJavaDoc - javadoc
JavaDoc-like - javadoclikeJava stack trace - javastacktrace
Jexl - jexlJolie - jolie
JQ - jqJSDoc - jsdoc
JS Extras - js-extrasJSON - json, webmanifest
JSON5 - json5JSONP - jsonp
JS stack trace - jsstacktraceJS Templates - js-templates
Julia - julia
Keepalived Configure - keepalivedKeyman - keyman
Kotlin - kotlin, kt, ktsKuMir (ΠšΡƒΠœΠΈΡ€) - kumir, kum
Kusto - kustoLaTeX - latex, tex, context
Latte - latteLess - less
LilyPond - lilypond, lyLiquid - liquid
Lisp - lisp, emacs, elisp, emacs-lispLiveScript - livescript
LLVM IR - llvmLog file - log
LOLCODE - lolcodeLua - lua
Magma (CAS) - magmaMakefile - makefile
Markdown - markdown, mdMarkup templating - markup-templating
Mata - mataMATLAB - matlab
MAXScript - maxscriptMEL - mel
Mermaid - mermaidMETAFONT - metafont
Mizar - mizarMongoDB - mongodb
Monkey - monkeyMoonScript - moonscript, moon
N1QL - n1qlN4JS - n4js, n4jsd
Nand To Tetris HDL - nand2tetris-hdlNaninovel Script - naniscript, nani
NASM - nasmNEON - neon
Nevod - nevodnginx - nginx
Nim - nimNix - nix
NSIS - nsisObjective-C - objectivec, objc
OCaml - ocamlOdin - odin
OpenCL - openclOpenQasm - openqasm, qasm
Oz - ozPARI/GP - parigp
Parser - parserPascal - pascal, objectpascal
Pascaligo - pascaligoPATROL Scripting Language - psl
PC-Axis - pcaxis, pxPeopleCode - peoplecode, pcode
Perl - perlPHP - php
PHPDoc - phpdocPHP Extras - php-extras
PlantUML - plant-uml, plantumlPL/SQL - plsql
PowerQuery - powerquery, pq, mscriptPowerShell - powershell
Processing - processingProlog - prolog
PromQL - promql.properties - properties
Protocol Buffers - protobufPug - pug
Puppet - puppetPure - pure
PureBasic - purebasic, pbfasmPureScript - purescript, purs
Python - python, pyQ# - qsharp, qs
Q (kdb+ database) - qQML - qml
Qore - qoreR - r
Racket - racket, rktRazor C# - cshtml, razor
React JSX - jsxReact TSX - tsx
Reason - reasonRegex - regex
Rego - regoRen'py - renpy, rpy
ReScript - rescript, resreST (reStructuredText) - rest
Rip - ripRoboconf - roboconf
Robot Framework - robotframework, robotRuby - ruby, rb
Rust - rustSAS - sas
Sass (Sass) - sassSass (SCSS) - scss
Scala - scalaScheme - scheme
Shell session - shell-session, sh-session, shellsessionSmali - smali
Smalltalk - smalltalkSmarty - smarty
SML - sml, smlnjSolidity (Ethereum) - solidity, sol
Solution file - solution-file, slnSoy (Closure Template) - soy
SPARQL - sparql, rqSplunk SPL - splunk-spl
SQF: Status Quo Function (Arma 3) - sqfSQL - sql
Squirrel - squirrelStan - stan
Stata Ado - stataStructured Text (IEC 61131-3) - iecst
Stylus - stylusSuperCollider - supercollider, sclang
Swift - swiftSystemd configuration file - systemd
T4 templating - t4-templatingT4 Text Templates (C#) - t4-cs, t4
T4 Text Templates (VB) - t4-vbTAP - tap
Tcl - tclTemplate Toolkit 2 - tt2
Textile - textileTOML - toml
Tremor - tremor, trickle, troyTurtle - turtle, trig
Twig - twigTwig - twig
TypoScript - typoscript, tsconfigUnrealScript - unrealscript, uscript, uc
UO Razor Script - uorazorURI - uri, url
V - vVala - vala
VB.Net - vbnetVelocity - velocity
Verilog - verilogVHDL - vhdl
vim - vimVisual Basic - visual-basic, vb, vba
WarpScript - warpscriptWebAssembly - wasm
Web IDL - web-idl, webidlWGSL - wgsl
Wiki markup - wikiWolfram language - wolfram, mathematica, nb, wl
Wren - wrenXeora - xeora, xeoracube
XML doc (.net) - xml-docXojo (REALbasic) - xojo
XQuery - xqueryYAML - yaml, yml
YANG - yangZig - zig

Plugins

Line Numbers

Line number at the beginning of code lines.

import { usePrism } from 'next-prism'

// Import a theme.css
import 'next-prism/themes/tomorrow.css'

// Import line-numbers source
import 'next-prism/plugins/line-numbers/line-numbers'
// Import line-numbers.css
import 'next-prism/plugins/line-numbers/line-numbers.css'

export default function App() {
  const { Code } = usePrism()

  return (
    <Code language='javascript' lineNumbers={true}>
      {`<div className="example">
  {Math.random()}
</div>`}
    </Code>
  )
}

Show Invisibles

Show hidden characters such as tabs and line breaks.

import { usePrism } from 'next-prism'

// Import a theme.css
import 'next-prism/themes/tomorrow.css'

// Import show-invisibles source
import 'next-prism/plugins/show-invisibles/show-invisibles'
// Import show-invisibles.css
import 'next-prism/plugins/show-invisibles/show-invisibles.css'

export default function App() {
  const { Code } = usePrism()

  return (
    <Code language='javascript'>
      {`<div className="example">
{Math.random()}
</div>`}
    </Code>
  )
}

Autolinker

Converts URLs and emails in code to clickable links. Parses Markdown links in comments.

import { usePrism } from 'next-prism'

// Import a theme.css
import 'next-prism/themes/tomorrow.css'

// Import autolinker source
import 'next-prism/plugins/autolinker/autolinker'
// Import autolinker.css
import 'next-prism/plugins/autolinker/autolinker.css'

function App() {
  const { Code } = usePrism()

  return (
    <Code language="javascript">
      {`<div className="example">
  <a href="https://github.com/Bunlong/next-prism">next-prism</a>
</div>`}
    </Code>
  );
}

πŸ“œ Changelog

Latest version 0.5.0 (2022-12-18):

  • Add autolinker plugins

Details changes for each release are documented in the CHANGELOG.md.

❗ Issues

If you think any of the next-prism can be improved, please do open a PR with any updates and submit any issues. Also, I will continue to improve this, so you might want to watch/star this repository to revisit.

🌟 Contribution

We'd love to have your helping hand on contributions to next-prism by forking and sending a pull request!

Your contributions are heartily β™‘ welcome, recognized and appreciated. (βœΏβ— β€Ώβ— )

How to contribute:

  • Open pull request with improvements
  • Discuss ideas in issues
  • Spread the word
  • Reach out with any feedback

πŸ† Contributors

Bunlong
Bunlong

πŸ‘¨β€πŸ‘©β€πŸ‘¦ Advertisement

You maybe interested.

  • React Patterns – React patterns & techniques to use in development for React Developer.
  • React Papaparse – The fastest in-browser CSV (or delimited text) parser for React.
  • Next QRCode – React hooks for generating QR code for your next React apps.
  • Next Share – Social media share buttons for your next React apps.
  • Next Time Ago – A lightweight tiny time-ago component for your next React apps.

βš–οΈ License

The MIT License License: MIT

Keywords

FAQs

Last updated on 18 Dec 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc